oracle經典建表語句–scott建表
複製**
create table emp
(empno number(4) primary key,
ename varchar2(10),
job varchar2(9),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
depno number(4)
);create table dept(
deptno number(4),
dname varchar2(14),
loc varchar2(13)
);create table salgrade
(grade number,
losal number,
hisal number
);create table bonus
(ename varchar(10),
job varchar2(9),
sal number,
comm number
);insert into dept values (10,『accounting』,『new york』);
insert into dept values (20,『research』,『dallas』);
insert into dept values (30,『sales』,『chicago』);
insert into dept values (40,『operations』,『boston』);
select * from dept;
insert into emp values
(7369,『smith』,『clerk』,7902,to_date(『17-12-1980』,『dd-mm-yyyy』),800,null,20);
insert into emp values
(7499,『allen』,『salesman』,7698,to_date(『20-2-1981』,『dd-mm-yyyy』),1600,300,30);
insert into emp values
(7521,『ward』,『salesman』,7698,to_date(『22-2-1981』,『dd-mm-yyyy』),1250,500,30);
insert into emp values
(7566,『jones』,『manager』,7839,to_date(『2-4-1981』,『dd-mm-yyyy』),2975,null,20);
insert into emp values
(7654,『martin』,『salesman』,7698,to_date(『28-9-1981』,『dd-mm-yyyy』),1250,1400,30);
insert into emp values
(7698,『blake』,『manager』,7839,to_date(『1-5-1981』,『dd-mm-yyyy』),2850,null,30);
insert into emp values
(7782,『clark』,『manager』,7839,to_date(『9-6-1981』,『dd-mm-yyyy』),2450,null,10);
insert into emp values
(7839,『king』,『president』,null,to_date(『17-11-1981』,『dd-mm-yyyy』),5000,null,10);
insert into emp values
(7844,『turner』,『salesman』,7698,to_date(『8-9-1981』,『dd-mm-yyyy』),1500,0,30);
insert into emp values
(7900,『james』,『clerk』,7698,to_date(『3-12-1981』,『dd-mm-yyyy』),950,null,30);
insert into emp values
(7902,『ford』,『analyst』,7566,to_date(『3-12-1981』,『dd-mm-yyyy』),3000,null,20);
insert into emp values
(7934,『miller』,『clerk』,7782,to_date(『23-1-1982』,『dd-mm-yyyy』),1300,null,10);
select * from emp;
insert into salgrade values (1,700,1200);
insert into salgrade values (2,1201,1400);
insert into salgrade values (3,1401,2000);
insert into salgrade values (4,2001,3000);
insert into salgrade values (5,3001,9999);
select * from salgrade;
commit;
–外來鍵約束
create table qq(
garde number(3) primary key,
gname varchar2(20)
);create table firend(
fid number(3),
name varchar2(20),
grade number(3),
foreign key(grade) references qq(garde) on delete cascade
);創表時建立外來鍵:
foreign key(列名) references 引用外來鍵表名(列名) on delete cascade
創表後新增外來鍵:
alter table 表名 add constraint 外來鍵約束名 foreign key(列名) references 引用外來鍵表(列名)
on update restrict //同步更新
on delete restrict // 同步刪除;
…oracle實現主鍵id自增
– 建立表
create table t_module (
module_id int not null ,
module_code varchar(32) not null,
module_name varchar(32) not null,
isnew int default 0 ,
primary key (module_id)
)– 為 表 建立 序列
– 從1 開始, 每次 加1
create sequence seq_module start with 1 increment by 1;
–查詢 下乙個 id
select seq_module.nextval from dual
Oracle 建表語句
create table table name id numner 12 text verchar2 255char not null char型別,乙個漢字佔乙個長度 pid varchar2 32 byte notnull byte型別,utf8乙個漢字佔大約兩個長度 status number...
Oracle標準建表語句
create table 建表 create table outln.customer id varchar2 32 default sys guid not null,cust id varchar2 64 cust name varchar2 255 id no varchar2 64 mobi...
Oracle基礎 建表語句(DDL)
1.建立表 語法 create table table name filed name datatype not null,filed name datatype not null,filed name datatype,filed name datatype not null,constraint...