Learning three

We understand that in learning how to create a database II, and he had a series of operations, we have to create a database table to fill in the learning content based on three learning two on in the database

first part

Task 1. We can create a new database classone be done after

Statement: CREATE BATABASE + database name

 

2. Because before we too might define the database and we want to use our new classone database, so we have to tell the system we want to use it.

Statement: USE + database name

the second part

1. For this database we have to start working to fill its contents, table of contents is added to the database

I built a student_tb data table, and give him id, name, age, sex and a series of parameters, so that the data table is much more abundant;

Statement: CREATE TABLE + table name (

          );

 

2. We can show the table names in the database

Statement: SHOW TABLES;

 

3. If we both want to see the table definition statement also want to view the table of character encoding can be used

语句:SHOW CREATE TABLE student_tb;WO

 

4. We can look at the table of field information, including field names, field type and other information available

Statement: DESCRIBE + table name (or DESC + table name)

 

5. If you want to change the name of the table can be

Statement: ALTER TABLE name RENAME TO change the original data data name;

After modifying the good name we can display data about the database

This time we had the table name changing for the better

 

6. We view the data sheet is to rely on the field name, if you want to change the field names can be used

Statement: ALTER TABLE + name + CHANGE + original database field name + name + current field data types now

We can now see if this data table in student_tb_1913 id is changed to student_id;

 

The figure shows, successful change

 

7. When we add a new field name to student_tb_1913, the new field name is automatically added to the end

 

Statement: ALTER TABLE + table name + ADD + the new field name + new field data types;

 Let's look at the display to see if there is added

It seems address this new field has been added to the final of default;

8. But if I want a new field into a field, you would need to make some changes

Statement: ALTER TABLE table name ADD original data field names now now field data types AFTER original field name;

Let's look at the results

Sure enough, the new field name tel is inserted into the end of the existing field names of age;

 

9. Of course, there have to add delete, if I want to delete an existing field name,

Statement: ALTER TABLE table DROP existing data field name;

Let's take a look at the results

Sure enough, in the data table of my sex column names are deleted.

 

10. For a data table we can modify the order of the field name

Statement: ALTER TABLE table name Field 1 MODIFY his data types FIRST / AFTER Field 2;

Field is a field to modify a position, FIRST optional parameter field 1 refers to the modification of the first field in the table, an AFTER 2 field is Field 1 Field 2 inserted later.

Example:

 

FIG first name is placed in the data table the first field, the first field student_id original on to other second layer are sequentially decreased. FIG second address is a tel and exchanged completely immobile. FIG effect as

the third part

1. As before, since I created out of the data table, then I certainly want him to remove the last;

Statement: DROP TABLE table name;

2. Finally, we now have use classone the database in the first part, then I finally can directly make the database to show all his data table to see that he did not in the end have been deleted

Statement: SHOW TABLES;

We can see from the chart, in classone this database has no tables, so deleted successfully

 

This is the data table to create, modify, and delete.

 

Guess you like

Origin www.cnblogs.com/13912475703q/p/11741626.html