MySQL Getting Started Guide-quick reference (1) I. SQL quick start
The following is an important quick reference for SQL. for SQL syntax and features added to standard SQL, Please query the MySQL manual.
1. create a table
A table is one of the most basic elements of a database. tables and tables can be independent or associated with each other. The basic syntax for creating a table is as follows:
Create table table_name
(Column_name datatype {identity | null | not null },
...)
The table_name and column_name parameters must meet the requirements of identifier in the user database. the parameter Ype YPE is a standard SQL type or a type provided by the user database. You must use the non-null clause to input data for each field.
Create table also has some other options, such as creating a temporary table and reading some fields from other tables using the select clause to form a new table. In addition, when creating a table, you can use the primary key, KEY, INDEX, and other identifiers to set certain fields as PRIMARY keys or indexes.
Note the following when writing:
List the complete fields in a pair of parentheses.
Field names are separated by commas.
Enter a space after the comma (,) between field names.
The last field name is not followed by a comma.
All SQL statements end with a semicolon.
Example:
Mysql> create table test (blob_col BLOB, index (blob_col (10 )));
2. create an index
Indexes are used to query databases. Generally, a database has a variety of index solutions, each of which is precise to a specific query class. Indexes can accelerate the database query process. The basic syntax for creating an index is as follows:
Create index index_name
On table_name (col_name [(length)],...)
Example:
Mysql> create index part_of_name ON customer (name (10 ));
3. change the table structure
When using a database, you sometimes need to change its table structure, including changing the field name or even changing the relationship between different database fields. The alter command can be implemented. its basic syntax is as follows:
Alter table table_name alter_spec [, alter_spec...]
Example:
Mysql> alter table t1 CHANGE a B INTEGER;
4. delete data objects
Many databases are dynamically used, and sometimes a table or index needs to be deleted. Most database objects can be deleted using the following command:
Drop object_name
Mysql> drop table tb1;