Oracle创建表、约束、视图、索引、序列、同义词、表空间
1、建表
create table userInfo (
id number(6),
name varchar2(20),
sex number(1),
age number(3),
birthday date,
address varchar2(50),
email varchar2(25),
tel number(11)
);
2、创建约束
不带约束名称的:
create table userInfo (
id number(6) primary key,--主键
name varchar2(20) not null,--非空
sex number(1),
age number(3) default 18,
birthday date,
address varchar2(50),
email varchar2(25) unique,--唯一
tel number(11),
deptno number(2) references dept(deptno)—外键
);
带约束名称:
create table userInfo (
id number(6) constraint id_pk primary key,
name varchar2(20) constraint name_nn not null,
sex number(1),
age number(3) default 18,
birthday date,
address varchar2(50),
email varchar2(25) constraint email_uqe unique,
tel number(11),
deptno number(2) constraint dept_deptno_ref references dept(deptno)
);
列模式:
create table userInfo (
id number(6),
name varchar2(20),
sex number(1),
age number(3) default 18,
birthday date,
address varchar2(50),
email varchar2(25),
tel number(11),
deptno number(2),
constraint id_pk primary key (id),--也可以两个以上,联合主键
constraint dept_deptno_ref foreign key (deptno) references dept(deptno),
constraint emial_name_uqe unique (email, name)
);
Alter模式:
alter table userInfo add(msn varchar2(20));
alter table userInfo modify(msn varchar2(25));
alter table userInfo drop(msn);
alter table userInfo