码迷,mamicode.com
首页 > 数据库 > 详细

SQL增加、删除、更改表中的字段名

时间:2017-10-20 10:23:10      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:default   table   增加   har   char   foreign   int   varchar   reference   

1. 向表中添加新的字段

   alter  table  table_name  add  column_name  varchar2(20) not null

2. 删除表中的一个字段

    delete table table_name column column_name

3. 修改表中的一个字段名

   alter table table_name rename column oldname to newname

4. 添加主键约束
   alter table 表名
   add constraint 约束名 primary key (列名)

5. 添加唯一约束
   alter table 表名
   add constraint 约束名 unique (列名)

6. 添加默认约束
   alter table 表名
    add constraint 约束名 default(内容) for 列名

7. 添加check约束
   alter table 表名
   add constraint 约束名 check(内容)

8. 添加外键约束
   alter table 表名
   add constraint 约束名 foreign key(列名) references 另一表名(列名)

9. 删除约束
   alter table 表名
   drop constraint 约束名

SQL增加、删除、更改表中的字段名

标签:default   table   增加   har   char   foreign   int   varchar   reference   

原文地址:http://www.cnblogs.com/xin688/p/7697765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!