数据表
-
查看数据表
-
修改表名
-
修改字段名
-
修改字段数据类型
-
添加删除-字段
-
约束(主外键默认检查)
查看表结构:
- 语法:DESRIBE(描述) table_Name;
DESC table_Name;

- 语法:show create table table_Name;
show create table table_Name \G;

修改表名:
- 语法:alter table table_Name rename to table_New;


修改字段名:
- 语法:alter table table_Name change table_Filed table_NewFiled new_Type;
修改字段数据类型

修改字段数据类型:
- 语法:alter table table_Name modify field_Table new_type(10);

添加删除-字段:
- 语法:alter table table_Name add new_table_Name new_type;
- 语法:alter table table_Name Drop table_Name;
约束:
主键约束 |
外键约束 |
检查约束 |
默认约束 |
PrimaryKey |
ForeigKey |
Check |
Default |
主键约束:
- 语法:ALTER TABLE users ADD constraint PK_Users_users_qq PRIMARY KEY(users_qq);

外键约束:
- 语法:ALTER TABLE scoers ADD constraint FK_scoers_users_qq FOREIGN KEY(Users_qqfk) REFERENCES users(uesrs_qq);
检查约束:
- 语法:ALTER TABLE table_Name add constraint CK_(games)表名_(scoers)字段 CHECK(scoers>0);
默认值:
- 语法:ALTER TABLE table_Name ALTER user_sex SET DEFAULT ‘男‘;
2017-07-02
My SQL随记 003 数据表基础操作语法
原文:http://www.cnblogs.com/Hanro-Z/p/7105445.html