sql 新增 修改 刪除 約束

2021-07-09 04:06:44 字數 808 閱讀 2249

1. 向表中新增新的字段

alter  table  table_name  add  column_name  varchar2(20) not null

2. 刪除表中的乙個字段

alter table table_name drop 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語句

新增 在test table 表的 valid status 字段之後,新增乙個字段,設定對應的型別,長度,是否為null,預設值,注釋 alter table test table add column is staff tinyint 2 not null default 0 comment 是...

超簡單!! MySQL中新增 修改 刪除約束

alter table 新增,修改,刪除表的列,約束等表的定義。檢視列 desc 表名 修改表名 alter table t book rename to bbb 新增列 alter table 表名 add column 列名 varchar 30 刪除列 alter table 表名 drop ...

mysql 新增 修改 刪除 字段 sql語句

新增 在test table 表的 valid status 字段之後,新增乙個字段,設定對應的型別,長度,是否為null,預設值,注釋 alter table test table add column is staff tinyint 2 not null default 0 comment 是...