『ORACLE』 约束实验(11g)

create table student 
(
   sno                  NUMBER(5)            not null,
   sname                VARCHAR2(20),
   idcard               VARCHAR2(18),
   createtime           DATE                 default SYSDATE,
   nno                  NUMBER(2),
   constraint PK_STUDENT primary key (sno)
);

create table course 
(
   cno                  NUMBER(5)            not null,
   cname                VARCHAR2(20),
   constraint PK_COURSE primary key (cno)
);

create table nativeplace 
(
   nno                  NUMBER(2)            not null,
   np_name              VARCHAR2(20),
   constraint PK_NATIVEPLACE primary key (nno)
);

create table sc 
(
   sno                  NUMBER(5)            not null,
   cno                  NUMBER(5)            not null,
   grade                NUMBER(4,1),
   constraint PK_SC primary key (sno, cno)
);

alter table sc add constraint fk_sc_sno foreign key (sno) references student (sno) on delete cascade;
alter table sc add constraint fk_sc_cno foreign key (cno) references course (cno);
alter table student add constraint fk_student foreign key (nno) references nativeplace (nno) on delete set null;

insert into nativeplace values(1,‘heilongjiang‘);
insert into nativeplace values(2,‘jilin‘);
insert into nativeplace values(3,‘liaoning‘);
insert into nativeplace values(4,‘beijing‘);

insert into course VALUES(1,‘Oracle‘);
insert into course VALUES(2,‘Java‘);
insert into course VALUES(3,‘C++‘);

insert into student values(1,‘zhangsan‘,‘123456789123456780‘,default,1);
insert into student values(2,‘lisi‘,‘123456789123456781‘,default,2);
insert into student values(3,‘wangwu‘,‘123456789123456782‘,default,3);
insert into student values(4,‘zhaoliu‘,‘123456789123456783‘,default,4);

insert into sc values(1,1,91);
insert into sc values(1,2,92);
insert into sc values(1,3,93);
insert into sc values(2,1,88);
insert into sc values(2,2,77);
insert into sc values(2,3,99);
insert into sc values(3,1,65);
insert into sc values(3,2,75);
insert into sc values(3,3,85);
insert into sc values(4,1,80);
insert into sc values(4,2,88);
insert into sc values(4,3,89);
commit;

alter table sc drop constraint fk_sc_sno;
alter table sc drop constraint fk_sc_cno;
alter table student drop constraint fk_student;
drop table course cascade constraints;
drop table nativeplace cascade constraints;
drop table sc cascade constraints;
drop table student cascade constraints;

时间: 2024-12-21 17:48:37

『ORACLE』 约束实验(11g)的相关文章

『ORACLE』 DBLINK(11g)

使用tnsnames.ora SQL> grant create database link to scott; Grant succeeded. SQL> conn scott/tigerConnected. SQL> create database link lk connect to hr identified by hr using 'enmo1'; Database link created. SQL> select * from [email protected]; T

『ORACLE』 内置约束(11g)

not null约束只能在列级定义:可以指定not null约束的名称,如不指定则自动生成名称 SQL> create table t1 (x number not null, y number constraint nn_t111_y not null); Table created. SQL> select constraint_name,constraint_type,search_condition from user_constraints where table_name = up

『ORACLE』 数据泵Data Pump中expdp导出(11g)

[[email protected] ~]$ mkdir datadump[[email protected] ~]$ cd datadump/[[email protected] datadump]$ pwd/home/oracle/datadump SQL> create or replace directory dir_dp as '/home/oracle/datadump'; Directory created. SQL> grant read,write on directory

『ORACLE』 清理监听日志(11g)

停止监听服务进程(tnslsnr)记录日志.lsnrctl  set log_status off; 将监听日志文件(listener.log)复制一份,以listener.log.yyyymmdd格式命名cp listener.log listener.log.20170521 将监听日志文件(listener.log)清空. cat /dev/null > listener.log 开启监听服务进程(tnslsnr)记录日志lsnrctl set log_status on; 对于这种lis

『ORACLE』 永久表空间创建设置(11g)

SQL> create tablespace ML01 datafile '/u01/app/oracle/oradata/enmo1/ML.dbf' size 15M autoextend on maxsize 25M; Tablespace created. SQL> alter database datafile '/u01/app/oracle/oradata/enmo1/ML.dbf' autoextend on next 2M;

『ORACLE』 对永久表空间进行DML操作(11g)

SQL> create tablespace ts_users datafile   '/u01/app/oracle/oradata/enmo1/ts01.dbf' size 10m autoextend on maxsize 20m,  '/u01/app/oracle/oradata/enmo1/ts01.bak.dbf' size 10m autoextend on maxsize 20m; Tablespace created. SQL> select tablespace_name

『ORACLE』 SQL语句简单应用(五)(11g)

not null  非空  字段+not null unique  唯一 primary key  主键(确保数据不能重复) foreign key  外键 check  必须 drop purge彻底删除 级联删除:删除一个部门,部门里的员工跟着删除--->on delete cascade 制空:把部门下的员工转到NULL,删除部门--->on delete set null 不能动:先删员工,再删部门 references 参照 constraint 约束 用子查询创建的表除了null,

『ORACLE』Oracle GoldenGate搭建(11g)

Oracle GoldenGate 实现原理是通过抽取源端的redo log 或者 archive log ,然后通过TCP/IP投递到目标端,最后解析还原应用到目标端,使目标端实现 同源端数据同步.

『ORACLE』 创建表(11g)

CREATE TABLE语句 create table [schema.] 表名 (column datatype [DEFAULT expr][, ...]); 在插入的过程中,为列指定一个默认值 ...hire_date DATE DEFAULT SYSDATE,... 默认值必须满足列的数据类型定义 create table hire_dates (id number(8),hire_date date default sysdate); create table dept (deptno