日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

修改表和约束(alter语句)

發布時間:2023/12/9 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 修改表和约束(alter语句) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 測試的表:

?? ?create table t_user(
?? ??? ??? ?id number constraint user_id_pk primary key,
?? ??? ??? ?name varchar2(100),
?? ??? ??? ?salary number
?? ?);


? //? drop table t_user;

?? ?//在表中添加一個新的列? add
?? ?alter table t_user
?? ?add birthday date;

?? ?//刪除表的某列? drop
?? ?alter table t_user
?? ?drop column birthday;


?? ?//給表中的列添加約束? ? add constraint
?? ?//這個約束相當于之前的表級約束
?? ?alter table t_user
?? ?add constraint user_name_un
?? ?unique(name);
?? ?
?? ?//測試剛添加的唯一約束是否生效? ? ?
?? ?insert into t_user(id,name) values(1,'zs');
?? ?insert into t_user(id,name) values(2,'zs');

?? ?
?? ?//刪除表中的約束? ? ? ?drop constraint
?? ?alter table t_user
?? ?drop constraint user_name_un;


?? ?//修改表的名字:? ? ?rename to
?? ?rename t_user to mytest;
?? ?rename mytest to t_user;

?? ?//修改表中某列的類型? ? modify
?? ?alter table t_user
?? ?modify (name varchar2(500));


?? ?//讓約束失效:必須知道約束的名字? ?disable
?? ?alter table t_user
?? ?disable constraint user_id_pk cascade;
?? ?
?? ?//測試是否設置成功? ? ? ??
?? ?insert into t_user(id,name) values(1,'zs1');
?? ?insert into t_user(id,name) values(1,'zs2');


?? ?//讓失效的約束再次生效? ? enable
?? ?alter table t_user
?? ?enable constraint user_id_pk;


?? ?//截斷表中的數據(刪除),不需要提交,默認已經提交,并且不能回滾? ? truncate
?? ?truncate table t_user;
?? ?相當于:
?? ?delete from t_user;
?? ?commit;


?? ?//給表添加注釋? ? comment on?
?? ?comment on table t_user is '很好';
?? ?//給列添加注釋? ??
?? ?comment on column t_user.name is 'good';
?? ?//查看表中注釋
?? ?select * from user_tab_comments where table_name=upper('t_user');
?? ?//查看列中的注釋
?? ?select * from user_col_comments?
?? ?where?
?? ?comments is not null?
?? ?and?
?? ?table_name=upper('t_user');

總結

以上是生活随笔為你收集整理的修改表和约束(alter语句)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。