Oracle建表
Oracle建表
参考网址:http://www.oraclejsq.com/article/010100139.html
-- Create table create table STUDENT.stuinfo ( stuid varchar2(10) not null,--学号:'S'+班号(6位数)+学生序号(3位数)(1) stuname varchar2(50) not null,--学生姓名 sex char(1) not null,--性别 age number(2) not null,--年龄 classno varchar2(6) not null,--班号:年级(4位数)+班级序号(2位数) stuaddress varchar2(100) default '地址未录入',--地址 (2) grade char(4) not null,--年级 enroldate date,--入学时间 idnumber varchar2(18) default '身份证未采集' not null--身份证 ) tablespace USERS --(3) storage ( initial 64K minextents 1 maxextents unlimited ); -- Add comments to the table comment on table STUDENT.stuinfo --(4) is '学生信息表'; -- Add comments to the columns comment on column STUDENT.stuinfo.stuid -- (5) is '学号'; comment on column STUDENT.stuinfo.stuname is '学生姓名'; comment on column STUDENT.stuinfo.sex is '学生性别'; comment on column STUDENT.stuinfo.age is '学生年龄'; comment on column STUDENT.stuinfo.classno is '学生班级号'; comment on column STUDENT.stuinfo.stuaddress is '学生住址'; comment on column STUDENT.stuinfo.grade is '年级'; comment on column STUDENT.stuinfo.enroldate is '入学时间'; comment on column STUDENT.stuinfo.idnumber is '身份证号';
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
-- Create/Recreate primary, unique and foreign key constraints alter table STUDENT.STUINFO add constraint pk_stuinfo_stuid primary key (STUID); --把stuid单做主键,主键字段的数据必须是唯一性的(学号是唯一的) -- Create/Recreate check constraints alter table STUDENT.STUINFO add constraint ch_stuinfo_age check (age>0 and age<=50);--给字段年龄age添加约束,学生的年龄只能0-50岁之内的 alter table STUDENT.STUINFO add constraint ch_stuinfo_sex check (sex='1' or sex='2'); alter table STUDENT.STUINFO add constraint ch_stuinfo_GRADE check (grade>='1900' and grade<='2999');

更多精彩