Oracle資料表建立 查詢 約束等操作

2022-09-01 02:06:12 字數 862 閱讀 9939

create  table stuinfo    ——建立學員資訊表

stuno char(6) not null

stuname varchar(2) not nul,

stuage number(3,0) not null

新建一張表複製學員資訊表則是:create table stuinfo2 as select * from stuinfo;

刪除表:1、drop table 表    2、truncate  表;

2、對錶結構的查詢:desc 表名;

3、改表名:alter table old表名 rename to new表名;

增加列:alter table 表 add(列名 型別,列名 型別);

修改列:alter table 表 modify (列名 型別,列名 型別);

刪除一列:alter table 表 drop column 列名; 刪除多列:alter table 表 drop(列1,列2);

4、向表中新增約束,emp表的deptno作為外來鍵引用dept表的deptno

alter table emp add constraint pk_test foreign key(deptno) references dept(deptno);

5、向表中新增主鍵約束

alter table emp add constraint pk_emp_deptno primary key(deptno);

6、刪除約束:

alter table emp drop constraint pk_emp_deptno;

7、禁用和啟用約束:

alter table 表 dsable||enable constraint 約束名;

Oracle 資料表約束

2.2 唯一性約束 2.3 主鍵約束 2.4 外來鍵約束 3.禁用和啟用約束 資料庫不僅僅是用來儲存資料,它還必須保證所儲存資料的正確性。如果資料不準確或不一致,那麼該資料表的完整性就可能受到了破壞,從而給資料庫本身的可靠性帶來問題。為了維護資料庫中資料的完整性,在建立表時常常需要定義一些約束。約束...

oracle資料庫 資料表的建立及相關約束名稱

基本語法create table 表名稱 欄位名1 字段型別,欄位名2 字段型別,欄位名3 字段型別,欄位名4 字段型別,字段 字段型別 例如 建立一張儲存老師資訊的表,使用非空約束 唯一約束 主鍵約束和檢查約束 方式一 在建立欄位時新增約束宣告 第一步 drop table teacher pur...

Oracle 約束條件與資料表

1.建立班級資訊表,classes cid int 主鍵,cname varchar2 100 非空 唯一,intro varchar2 1000 使用insert語句插入5條資料 create table classes cid int constraint pk cid primary key,...