常用Oracle語句

2021-07-27 15:25:38 字數 1609 閱讀 4199

--表結構操作

--建表語句

create table test(id varchar(14),name varchar2(64));

create table test***(*** varchar(2),name varchar2(2));

--修改表名;將表名test重新命名為test1

alter table test rename to test1;

--新增主鍵約束

alter table test add constraint pk_id primary key(id);

--新增外來鍵約束

alter table test add constraint fk_*** foreign key(***) references test***(***);

--新增欄位email、***

alter table test add (email varchar2(32));

alter table test add *** varchar2(1);

--給***新增cheak約束

alter table test add constraint cons_cheack1 check(*** in('1','3'))

--測試check約束(***的值必須是1和3)

insert into test values('1','tom','[email protected]','5');

--刪除check約束

alter table test drop constraint cons_cheack1;

--修改***欄位為非空

alter table test modify *** is null;

--修改***字段長度

alter table test modify *** varchar2(2);

--刪除欄位email

alter table test drop column email;

--為test表新增說明

comment on table test is '這是乙個測試表';

--為表字段id新增說明

comment on column test.id is '這是test表的主鍵';

--建立表空間

create tablespace test

datafile 'e:\test.ora'--資料檔案路徑

size 100m; --檔案大小

--使用者許可權操作(必須為dba許可權)

--建立使用者,建立使用者test,密碼:test

create user test identified by test;

--建立使用者test1,指名其所屬命名空間為test

create user test1 identified by test1 default tablespace test;

--刪除使用者test

drop user test;

--給test使用者新增登陸許可權

grant session on test;

--給test使用者新增dba許可權

grant dba on test;

常用Oracle語句

1,建立表空間 2,建立使用者名稱並確定表空間 create user watf identified by watf profile default default tablespace watf temporary tablespace temp account unlock 3,給使用者賦予許...

oracle常用sql語句

1.解鎖oracle使用者下某個使用者 以內建的scott使用者為例 sql conn as sysdba sql alter user scott account unlock identified by tiger 解釋 首先要切換到sysdba使用者下,否則會提示 許可權不足 error at...

oracle常用SQL語句

最近專案中用到,現記錄一下 新增主鍵 alter table shop spec detail add constraint spec detail id primary key id 新增索引 create index spec detail id on shop spec detail id 給...