1. create a new table CREATETABLE table name (domain name data type column option []); mysqlcreatetablecustomer (c_idchar (5) primarykey, c_namevarchar (20), c_birthdate, c_sexchar (1) DEFAULT0 ); CREATE 1. CREATE a new table create table name (domain name data type column option [...]);
Mysql> create table customer (c_id char (5) primary key, c_name varchar (20), c_birth date, c_sex char (1)
DEFAULT '0 ');
Main options available in the create table command
|
Option |
Description |
|
AUTO_INCREMENT |
Custom Auto-incrementing sequence |
|
DEFAULT 'default' |
Define the default value of a column |
|
INDEX |
Define indexes |
|
[NOT] NULL |
Allow/disable NULL values |
|
PRIMARY KEY |
Define column primary keys |
|
UNIQUE |
Define uniqueness |
|
CHECK |
Define the range/option of values that can be entered |
Specify character set when creating a table
Mysql> create table customer (c_id char (5) primary key, c_name varchar (20), c_birth date, c_sex char (1) DEFAULT '0') CHARSET = utf-8;
2. show tables for all tables;
Mysql> show tables;
3. display the DESC table name of the table structure;
Mysql> DESC customer;
4. delete the drop table name;
Mysql> drop table customer;
5. data insertion and display
Insert data into table name (column name 1, column name 2... column name n) values (data 1, data 2... data n) into table );
Displays the data in the table. SELECT column name 1, column name 2... column name n
6. AUTO_INCREMENT auto-incrementing sequence
There are three necessary conditions for customizing the auto-increment sequence in mysql:
1. the data type must be INT, TINYINT, SMALLINT, etc.
2. use [PRIMARY_KEY] and so on to set its uniqueness (the auto-increment sequence number is generally UNIQUE and generally serves as the table's primary key or a UNIQUE column (UNIQUE ))
3. the attachment AUTO_INCREMENT keyword after Column definition
Mysql> create table goods (id INT auto_increment primary key, name varchar (30 ));
// Note: the value of AUTO_INCREMENT can be initialized. alter table name: AUTO_INCREMENT = 0;