The SQL language is divided into three levels.
1, the DDL statement, the data definition statement, defines the database, the table, the index and so on the object definition. Common statements include: Create, DROP, alter. 2, DML statements, data manipulation statements, used to add, delete, update and query database records, and check data integrity, commonly used statements include INSERT, delete, update, select and so on. 3. DCL statements, Data control statements, statements that control access levels for different data objects. Defines the database, table, table, user's access rights, and the full level. Common statements include Grant, REVOKE, and so on.
DDL statements:1, build the library, delete the library:
Build Library: Create database DB name default Charset=utf8;
Delete Library: drop database DB name;
2.
Table Operations
2.1 Build Table 1:
CREATE TABLE table_name (col1 type1 [NOT NULL] [primary key],col2 type2 [NOT NULL])Such as:
CREATE TABLE Person_info (person_id smallint (5) unsigned auto_increment,name varchar () NOT NULL comment ' Person_name ', Country varchar Default ' China ', Salary decimal (10,2) default 0.00 Comment ' salary ', primary key (person_id)) engine=in Nodb default Charset=utf8;
Set engine with default encoding outside parentheses
Note Information: Comment
Defaults assignment: Default keyword
Primary key: Usually put in the last. Primary KEY person_id
Engines: Engine InnoDB
Build Table 2: Create a new table with the same table structure as the original table, but with no data.
CREATE table table_nameliketable_name1;
2.2 Modifying the table structureAlert Table table_name MODIFY col_name column_definition [First | After Col_name
] #修改字段类型Alert Table table_name ADD col_name column_definition [First | After Col_name
] #增加字段Alert Table table_name DROP col_name
#删除字段Alert Table table_name Change old_col_name new_col_name column_definition [first| After Col_name
] #修改字段名For example, modify the Country field to a length of 50 bytes and place it after the salary field. The following two types are possible. ALTER TABLE TABLE_NAME
ChangeCountry
Countryvarchar (50)
default ' China 'After salary; ALTER TABLE TABLE_NAME
ModifyCountry varchar (50)
default ' China 'After salary; When modifying a field, note the original default value, and the default value will still need to be added when modifying the command
2.3 View Table StructureDESC table_name;
2.4 Deleting a tableDROP TABLE table_name;
MySQL DDL statements