How to create a database on hosting. Creating a MySQL Database

Designing a database management system in Delphi.

What you need to master:

1) how to connect the database to Delphi components;

2) the procedure for creating an application to manage a simple local database;

3) how to control the display of database tables;

4) how to organize data sorting and filtering;

5) how to use the SQL query language.

Create a folder in which you will save the applications you develop. For each application in the future, you should create a separate directory in the main folder.

STEP 1. CREATE A SIMPLE DATABASE

Before you begin developing a database management system (DBMS), you should create this database. Let's use the application for this purpose Microsoft Office Access, since Office is installed on almost any computer and Access was most likely installed by default.

IN this manual the possibilities of accessing databases through only one technology will be considered - ADO (Active Data Objects), developed by Microsoft. This modern library, first of all, allows you to work with local MS Access databases and client-server MS SQL Server. Studying this library will allow you in the future to easily move on to databases built on the basis of other technologies.

Let's create for now local database store data computer literature, consisting of one table. Table like two-dimensional array consists of columns and rows. Each table column contains a single field, such as book title or author. Each row of the table contains one record consisting of several fields containing, for example, the title of the book, author, price, year of publication.

Launch Microsoft Office Access. In the menu, click File/New and then in the wizard select New base data. You will be asked to select the database storage location and file name. Specify the path to your first future application (where you will save the Delphi project in the future) and a meaningful name for the computer book store database, for example, mkl.mdb.

A window for organizing work with the database will open (see figure).

Select double click Click on the item “Creating a table in design mode” – the table designer will open, in which you should specify the names of the table fields and the type of data contained in the corresponding fields.

An example of a description of table fields is shown in the figure below. Let there be six fields in the table. In Access, field names can be given names in both English and Russian. The names of fields No. 2-5 are obvious, as is the data type of these fields. Let's look at field #1. Field name: id_kn – book identifier. This field has a special meaning for the database - this is a key field in the table, it carries a unique record identifier. You can set the “Key Field” option via context menu, which appears when you right-click on the corresponding field in the table designer. Save the table by clicking on the save button, you will be asked to choose a name for the table - set the name store.


Using the View menu, set the view to Table Mode:

The table is already ready to be filled in, but we will not do this now, since our main goal is to study Delphi's database management capabilities. Let's create an application in Delphi and there we will start editing the table.

STEP 2. CREATE A SIMPLE APPLICATION FOR DATABASE MANAGEMENT

The simplest application should be able to view the contents of the database (in our case, the contents of one table), in addition, there should be functions for correcting records, deleting them, and adding them. A similar task can, of course, be accomplished without the use of database processing technologies, but the development of such an application will take two to three orders of magnitude longer.

So, start Delphi, create a new application and save the project to the folder where the database file is located. Let the module name be magazin.pas, and the project name ProjectMagazin.dpr.

Now let's determine which components from the palette are needed to work with the database. The database consists of tables, to view which you need the appropriate visual component– DBGrid from the Data Controls tab. In addition, there must be other components that provide communication between the application and the location of the database, recognize its format, and select from specific table databases. For these purposes, we use the following three components: ADOConnection and ADOTable from the ADO tab and DataSource from the Data Access tab.

Let's configure the properties of all components on the form.

1. ADOConnection1. Double-click on the component (or in the object inspector on the ConnectionString property line) - you will be given the opportunity to enter a connection string (Use Connection String), launch the wizard by pressing the Build key and on the “Data Provider” tab select the database connection driver Microsoft data Jet OLE DB Provider. Click “Next” to go to the “Connection” tab and there, in the “Select or enter a database name” line, enter the file name - in our case it is mkl.mdb. You can, of course, press the key next to the line and directly point to the file, but in this case, it is better to immediately remove the path to the file, leaving only the name, so that when moving the application to another location, there will be no problems with accessing the database. Click OK in the wizard and OK on the connection string selection form. Switch the LoginPromt property to False so that every time you connect to the database the user is not prompted for a password.

2. ADOTable1. In the Connection property, in the drop-down list, point to ADOConnection1, in the TableName property, select the table (we have only one store for now). Set the Active property to True (note that in the future, when changing settings, you will often have to return this property to True). And, for convenience, rename the component to TableMagazin.

3. DataSource1. For this intermediary component, you must set the DataSet property in the drop-down list to the TableMagazin table.

4. DBGrid1. Let's connect the grid from DBGrid1 to the store table from the database using DataSource1, setting the DataSource property in the drop-down list in the object inspector available components DataSource1.

This completes the creation of the simplest database, and we haven’t written a single line of code. If you already had experience working with these components, you would spend less than a minute developing such a DBMS.

Launch the application using the F9 key and work on filling the database (control keys: F2 - edit cell, Ins - add record, Ctrl+Del - delete record). Close the application and then launch it again and you will see that the changes you made are saved.

Example of filling a database:

Not everyone prefers to work with a keyboard if they have a mouse. Therefore, the DBNavigator component from the Data Controls tab can sometimes be useful. Place it for testing (in the future it should be deleted) on the form at your discretion and connect it using the DataSource1 intermediary - point to it in the DataSource property. If necessary, you can disable some keys from the database control panel in the VisibleButtons property. And, although the control buttons are intuitive, it is possible to provide them with tooltips, for which you set the ShowHint property to True, and the text of the tooltips can be set/changed in the Hints property. Possible view applications after connecting the DBNavigator component, see the figure:

What is database creation? There are two types: desktop and client-server. To create desktops, you need a program like Access. You can easily find it in any office suite. Now Access is produced by Infra-Office, Microsoft and many other creators of office suites. As for the client-server model, a simple model can be implemented using a “training” Delphi programs. Serious databases today are written in Oracle and Visual Fox Pro. Data software platforms equipped with graphical tools for creating processed queries to databases of 500,000 and 1,000,000 or tens of millions of rows.

Let's consider the most promising platform for programming past years Delphi 6.0. Let's make a reservation right away that creating in Delphi is not just getting *.db or *bdb files, but installing it on personal computer, configuration and automation. So, in Delphi 6.0, database files are created in a subroutine located in the main menu of the development environment, Date Base Desktop 6.0.

Here you will find everything necessary tools to create database files, assign database type, and prepopulate. Please note that you will only be able to create and manipulate files for which a driver is installed on the platform. For example, to work with a type, Visual Fox Pro 9.0 must be additionally installed in operating system external driver.

As for the work of a program with a database created in Delphi 6.0, without coexistence with the platform itself, then this problem solved by installing and configuring software package Data Base Engine 6.0 (BDE).

So, if you are determined to work with the Paradox file type, then by writing a program in specific folder on the hard drive, you must subsequently register the settings in the Data Base Engine 6.0 package, which include the paths to the files, their properties and the name of the database. This scheme works when you move the programs you create to another computer.

The Engine 6.0 package must be installed on the computer where you are installing machine code created in Delphi 6.0.

Creating a database in Delphi 6.0 is quite automated. A simple program for storing data with one database file is obtained with a few keystrokes. The main difficulty here lies in the implementation of relational forms of the database. So SDNF 3 can be implemented by setting up two DBGRID tables. And receiving various types reports in QReport is a whole story that I don’t even want to touch on. Let's just say that better code Do not throw the created program into the trash, since each custom report for people who do not know SQL will have to be programmed again...


Access creation database in an office suite is not particularly difficult. By logging into the program, you get access to the necessary tools for creating or editing an existing database. Here you don't need to apply special effort to create a report or new form project. Everything is decided almost intuitively. Thus, to establish a connection between tables, graphical tools are used, which can connect the right key two necessary tables.

This article discusses only the creation of a database using educational and desktop packages. As for serious programming, without knowledge of the existence of these platforms you will never solve the problem of operating large databases.

Mysql, it is much more important whether you have basic set knowledge, without which it is impossible to talk about the successful implementation of the plan.

In this material I will tell you what actions any PC owner needs to take if for some purpose he needs to install mysql, create a database, and try his hand at managing a modern database. It will also be of interest to those who want to know how to make it work modern DBMS.

Since, as I already said, in order for you to succeed, you need basic knowledge, without which you will not be able to create a mysql database, accordingly we will assume that you know what a database, a table, database queries are, and it won’t put you in deadlock abbreviation SQL. We will also assume that you have installed and configured Apache server.

So, if you have everything you need, and the desire to learn how to create a mysql database has not yet disappeared, then let’s start by launching Apache. To run it, go to the path C:\WebServers\etc and run the Run file. If Apache starts correctly, without errors, then a red pen will be added to the existing icons in the lower right corner.

Now you need to make sure that the web server is working, enter the address http://localhost/ in the browser. In response, you should receive the text “Hurray, it’s working!” If this is what you see on the monitor, then Apache is in complete order.

Now go to Utilities and select phpMyAdmin from the list, you have graphical shell, which allows you to manage mySQL DBMS. With its help, you can perform all operations without exception that are provided by the creators of this database, and specifically:

Creating a Database

In order to create a database, you must enter a name in the “Create a new database” field, for example, MyBase. Now click the “Create” button and phpMyAdmin will create a new database.

Creating tables

Creating tables is quite simple, you should select a base (MyBase). In the main window you will be asked to enter a name for the table (try entering the name DataStudent), and you will also need to enter the number of fields (put the number 5). When choosing how many fields you will have, do not forget that one field goes under the key (ID). If you entered everything correctly, then press the “Enter” button.

Now you will see an additional form for creating tables. In it you can set fields, assign for each of them, name the columns, define them maximum dimensions. As a rule, the first field is the key one. We enter the name “ID” into it; now we need to decide on the type of data that will be entered for this column. Since there is no such type as a counter in MySQL, you should select Int and check the unsigned box in the attributes. Then we go to additional settings and set Auto-increment there, so that every time you enter a new value, this field independently increases its value by one.

Thus, you have a typical counter. It's time to move towards next group settings - RadioButton. Here we select the value “primary”; if it is activated, then our field becomes the primary key.

If you did everything correctly, then your main field is configured correctly; when adding rows, the ID value in it automatically increases. And you are one step closer to understanding how to create a database MySQL data.

Moving on, now we need to define the values ​​and give names to the remaining columns of our table. Let it be Last name, first name, patronymic and, say, rating: “Fam”, “Name”, “Otch”, “Evaluation”, it remains to assign a data type - varChar, because these fields will store information in the form of a string. Don't forget to set and maximum length fields, it would be logical to limit it to 30 characters. Check all the entered data and admire the table you created. It should contain a set of fields with the names “ID”, “Fam”, “Name”, “Otch”, “Evaluation”.

I hope that the information in this article was useful to you and that you found the answer to the question of how to create a MySQL database.

Creating a new normalized relational base Access data carried out in accordance with its structure obtained as a result of design. The process of designing a relational database was discussed in the previous chapter. The structure of a relational database is determined by the composition of the tables and their relationships. The relationships between two tables are implemented through the connection key, which is part of the fields of the linked tables. Recall that in a normalized relational database, tables are in a one-to-many or one-to-one relationship. For one-to-multivalued relationships, the connection key is usually used unique key main table, in the subordinate table this can be any of the fields called foreign key.

Creating a relational database begins with the formation of a table structure. This determines the composition of the fields, their names, the data type of each field, the size of the field, keys, table indexes and other properties of the fields. After defining the table structure, a data schema is created in which relationships between tables are established. Access remembers and uses these relationships when populating tables and processing data.

When creating a database, it is important to set parameters that allow Access to automatically maintain data integrity. To do this, when defining the table structure, the key fields of the tables must be specified, restrictions on valid values data, and when creating a data schema based on normalized tables, parameters must be set to maintain the integrity of database relationships.

The creation of the database is completed by the loading procedure, i.e., filling the tables with specific data. Of particular importance is the technology for loading interrelated data. A convenient tool loading data into interrelated tables are input/output forms that provide an interactive interface for working with database data. Forms allow you to create a screen analogue of the source document through which you can enter data into interrelated tables.

ATTENTION!
The user can start working with the database with any number of tables created even before creation full base, displaying all data model objects subject area. The database can be created in stages, and at any time it can be supplemented with new tables and relationships between tables can be entered into the data schema; existing tables can be supplemented with new fields.

Creating a database in MS Access 2010

The page that opens after launching Access displays the Microsoft Office Backstage view - a set of commands on a tab File(File) - which is designed to execute commands that apply to the entire database. At the same time, on the tab File(File) command selected Create(New). The area of ​​this command contains Available templates(Available Templates), which allow you to create a database using numerous templates located on your computer or accessible via the Internet.

A template is a ready-to-use database that contains all the tables, queries, forms, and reports needed to perform a specific task. These ready-made databases data allow you to quickly create applications that support a wide range of tasks. New application templates are constantly being released and can be downloaded from the Microsoft Office Online website. These standard applications You can use them without any modification or customization, or, using them as a basis, adapt the template to your needs and create new fields and tables, forms, reports and other database objects.
The Open command is intended to open any previously created database. A list of the 4 most recently opened databases is also available here. The Recent command opens a longer list of recently opened databases. By clicking on the button icon you can add a database to the list of recent ones, and by clicking on the icon you can remove it from the list.

Team Open(Open) is designed to open any previously created database. A list of the 4 most recently opened databases is also available here. Team Latest(Recent) opens a longer list of recently opened databases.

And we have a video on this topic:

Read about creating an Access database file in the next section.

Create a database. IN command line MySQL enter CREATE DATABASE command ; . Replace the name of your database. It cannot contain spaces.

  • For example, to create a database of all American states, you could enter CREATE DATABASE us_states;
  • Note: Commands do not need to be entered in uppercase.
  • Note: All MySQL commands must end with ";". If you forgot to put a semicolon, just enter ";" on next line to start processing the previous command.

Display a list of available databases. Enter the SHOW DATABASES command; to display a list of stored databases. In addition to the newly created database, you will also see the mysql and test databases. You can ignore them for now.

Select a database. Once the database has been created, you need to select it to begin editing. Enter the command USE us_states; . You will see a Database changed message, which notifies you that us_states is now the active database.

Create a table. A table is where information is stored in a database. To create a table, you need to enter its entire structure with one command. To create a table, enter the following command: CREATE TABLE states (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, state CHAR(25), population INT(9)); . This command will create a table called "states" with three fields: id , state , and population .

  • The INT command specifies that the id field will only contain numbers (integers).
  • The NOT NULL command indicates that the id field should not be empty (required for entry).
  • PRIMARY KEY indicates that the id field is a key field in the table. A key field is a field that cannot contain identical values.
  • The AUTO_INCREMENT command will automatically assign increasing values ​​to the id field, essentially automatically numbering each record.
  • The CHAR (characters) and INT (integer) commands indicate the data type allowed in the corresponding fields. The number following the command indicates how many characters or numbers the field can contain.
  • Create a record in the table. Now that the table has been created, it is time to enter information. Use the following command to enter the first entry: INSERT INTO states (id, state, population) VALUES (NULL, 'Alabama', '4822023');

    • This command essentially tells the database to store information in a table in three appropriate fields.
    • Since the id field contains a NOT NULL identifier, entering NULL as a value will cause it to increase by one, thanks to the AUTO_INCREMENT identifier.
  • Create more entries. You can save many entries with one command. To save three more states, enter the following command: INSERT INTO states (id, state, population) VALUES (NULL, 'Alaska', '731449'), (NULL, 'Arizona', '6553255'), (NULL, 'Arkansas ', '2949131'); .

  • Run a database query. Now that simple base data is created, you can run queries to retrieve necessary information. To get started, enter the following command: SELECT * FROM us_states; . This query will return the entire database, as shown by the "*" command, which means "all".

    • For a more complex query, enter the following command: SELECT state, population FROM us_states ORDER BY population; This query will return a table with states sorted by population instead of sorted by name in alphabetical order. The id field will not be rendered since you only asked for the state and population fields.
    • To display states by population in reverse order, use the following command: SELECT state, population FROM us_states ORDER BY population DESC; . The DESC command will display states in descending order of population (largest to smallest, not smallest to largest).


  •