Data Sheet
- View Data Sheet
- Modify Table Name
- Modify field names
- modifying field data types
- Add Delete-field
- Constraint (primary foreign key default check)
To view the table structure:
- Syntax: Desribe (description) table_name;
DESC table_name;
- Syntax: show CREATE TABLE table_name;
Show CREATE TABLE table_name \g;
Modify Table Name:
- Syntax: ALTER TABLE table_name rename to table_new;
Modify Field Name:
- Syntax: ALTER TABLE table_name change table_filed table_newfiled new_type;
modifying field data types
To modify the field data type:
- Grammar : ALTER TABLE table_name modify Field_table New_type (ten);
Add Delete-field:
- Syntax: ALTER TABLE table_name add new_table_name new_type;
- Syntax: ALTER TABLE TABLE_NAME DROP TABLE_NAME;
Constraints:
PRIMARY KEY constraint |
FOREIGN KEY constraints |
CHECK constraints |
Default Constraints |
PrimaryKey |
Foreigkey |
Check |
Default |
PRIMARY KEY constraint:
- Syntax: ALTER TABLE users ADD constraint pk_users_users_qq PRIMARY KEY (USERS_QQ);
FOREIGN KEY constraints:
- Syntax: ALTER TABLE scoers ADD constraint fk_scoers_users_qq FOREIGN KEY (USERS_QQFK) REFERENCES users (UESRS_QQ);
CHECK constraints:
- Syntax:ALTER table table_name add constraint ck_ (games) Table name _ (scoers) field CHECK (scoers>0);
Default value:
- Syntax: Alter TABLE TABLE_NAME alter user_sex SET DEFAULT ' male ';
2017-07-02
My SQL with 003 data table base operation syntax