Table operation of the data 1. Create a table
Syntax: CREATE TABLE table_name (column_name column_type);
CREATE TABLE student, ID int not NULL auto_increment, name CHAR (+) NOT NULL,--age INT not NU LL, register_data DATE, PRIMARY KEY (ID) );
Auto_increment said: increased by 1. When the write content is empty, the default is to populate the table with a drop-down. Primary key: Represents a constraint (cannot be duplicated and cannot be empty); Accelerate find NOT null: not empty
2. View the table
Show tables; --See what tables are DESC student; --View Student table information show create table student; -View the information created by table student
3. Delete a table
#drop Table name drop table student;
4. Modify the table
Method:
Add Column: ALTER TABLE table name add column name type Delete column: ALTER TABLE table name drop Column name Modify column: ALTER TABLE table name modify column name type; --type ALTER TABLE name change original column name new column name type;--column name, type add primary key: ALTER TABLE table name add primary key (column name); Delete PRIMARY key: alter TABL e table Name drop primary key; ALTER TABLE name modify column name int, drop primary key; Add foreign key: ALTER TABLE from TABLE ADD constraint foreign key name (shape: fk_ from Table _ Main Table) foreign key from table (foreign key field) references Main Table (primary key field); Delete foreign key: ALTER TABLE name drop for Eign key FOREIGN Key name modifies default value: ALTER TABLE TESTALTER_TBL alter I SET default 1000; Delete defaults: ALTER TABLE TESTALTER_TBL alter I DROP D Efault;
1. Add alter TABLE student add sex CHAR (+); #--> add a column 2. Delete alter TABLE student drop sex; #--> Delete a column 3. Modify the table name alter tables student RENAME to students; #--> Rename 4. Modify the column name alter TABLE students change regisiter_date register_date date, #change field name, type can be changed, modify can only change type
MySQL (ii)