1. Enter a database first. 2. Enter the command to build the table:--------------------------------------------the CREATE table table name ( column name 1 column type [constraint], Column Name 2 column type [constraint], .... Column name n column type constraint ); Note: The last line does not have a comma--------------------------------------------if a database keyword is used in a table. For example, create a new order form :(order), but order is a keyword (sort used) in the database. Table name: T_order, if the cost is to use the word order. In this case, use the back quotation mark (') enclosed, ' order '. In general, the table name is: t_ name.
View table structure: DESC table_name; View a detailed definition of the table (shows the table's definition SQL statement): Show CREATE table table_name; Delete table: drop tables table_name;
Constraint on a table (for a column): 1. Non-null constraint: Not nullable, the contents of a column are not allowed to be empty. 2. Set default values for columns: defaults. 3. Unique constraint: Unique, in which the contents of the column must be unique. 4. PRIMARY KEY constraint: PRIMARY key, non-null and unique. 5. Primary key self-growth: auto_increment, starting from 1, step 1. 6. FOREIGN KEY constraint: FOREIGN The foreign key column in the Key,a table. The values of the foreign key columns in table A must be referenced to one of the columns in table B (table B primary key)-explained tomorrow. -------------------------------------------------------------------------------------primary key design, which uniquely identifies a row of data: 1: Single-field primary key, Single column as the primary key, recommended for use. Composite primary key, using multiple columns to act as the primary key, is not recommended. 2: The primary key is divided into two types: 1). Natural PRIMARY Key: Use the business meaning of the column as the primary key (not recommended), such as the identity card number; 2). Proxy primary key: Use a column with no business meaning as the primary key (recommended);
DOME:
Create a student information sheet to record the student's id,name,age. CREATE TABLE ' t_student ' ( ' id ' bigint, ' name ' varchar (), ' age ' int);
CREATE TABLE 't_student' ( 'ID' bigint( -),DEFAULTNOLL,'name'Vachar ( -)DEFAULT NULL, ' Age' int( One)DEFAULT NULL. ) ENGINE=InnoDBDEFAULTCHARSET=UTF8;
CREATE TABLE ' t_student ' ( ' ID'BIGINT, ' name ' VARCHAR(20 ) UNIQUEnotNULL, ' age ' INT DEFAULT);
MySQL table operations