create table tab_class( class_id number primary key, class_name varchar2(10) not null unique );
create table tab_stu( stu_id number, --学生姓名,不能为空,不能重复 stu_name varchar2(20) not null unique, --学生姓名只能是male或female stu_gender varchar2(6) not null check(stu_gender='male' or stu_gender='female'), --学生年龄只能在18到60之间 stu_age number check(stu_age >18 and stu_age <60), --邮箱可以不填写,填写的话不能相同 stu_email varchar2(30) unique, stu_address varchar2(30), --外键约束 class_id number not null references tab_class(class_id) );
--维护约束 --创建约束 create table tab_check( che_id number, che_name varchar2(20) ); --为表增加主键约束 alter table tab_check add constraints tab_check primary key(che_id);
--添加唯一约束,tab_check_unique表示约束的名称 alter table tab_check add constraints tab_check_unique unique(che_name);
--添加一个字段 alter table tab_check add che_age number; --添加检查约束 alter table tab_check add constraints tab_check_age check(che_age>18 and che_age<60);
--删除主键约束 alter table tab_check drop constraints tab_check;
--禁用约束 alter table tab_check disable constraints tab_check;
--启用约束 alter table tab_check enable constraints tab_check;
--联合主键 create table tab_person( tab_firstname varchar2(10), tab_lastname varchar2(10), tab_gender varchar2(5), primary key(tab_firstname,tab_lastname) );
alter table tab_stu add constraints tab_stu foreign key(class_id) references tab_class(class_id);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有