oracle怎么定义外键,oracle 设置外键
oracle中 怎么设主外键?
以oracle自带的用户scott为例。
十年品牌的成都网站建设公司,1000多家企业网站设计经验.价格合理,可准确把握网页设计诉求.提供定制网站建设、商城建设、微信小程序、成都响应式网站建设公司等服务,我们设计的作品屡获殊荣,是您值得信赖的专业的建站公司。
create table dept(
deptno number(2) primary key, --deptno 为 dept表的主键
dname varchar2(10),
loc varchar2(9)
);
create table emp(
empno number(4) primary key, --empno 为 emp表的主键
ename varchar2(10),
job varchar2(9),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2) references dept(deptno) --dept表中deptno字段 为 emp表的外键
);
oracle创建外键
create TABLE zhao(
id number primary key,
mingcheng nvarchar2(50),
neirong nvarchar2(50),
jiezhiriqi date,
zhuangtai nvarchar2(50)
);
create TABLE tou(
id number primary key,
zhao_id number,
toubiaoqiye nvarchar2(50),
biaoshuneirong nvarchar2(50),
toubiaoriqi date,
baojia number,
zhuangtai nvarchar2(50),
foreign KEY(zhao_id) REFERENCES zhao(id)
);
foreign key (zhao_id) references to zhao(id)
多了个to
oracle怎么创建外键?
create TABLE zhao(\x0d\x0a id number primary key,\x0d\x0a mingcheng nvarchar2(50),\x0d\x0a neirong nvarchar2(50),\x0d\x0a jiezhiriqi date,\x0d\x0a zhuangtai nvarchar2(50)\x0d\x0a);\x0d\x0acreate TABLE tou(\x0d\x0a id number primary key,\x0d\x0a zhao_id number,\x0d\x0a toubiaoqiye nvarchar2(50),\x0d\x0a biaoshuneirong nvarchar2(50),\x0d\x0a toubiaoriqi date,\x0d\x0a baojia number,\x0d\x0a zhuangtai nvarchar2(50),\x0d\x0a foreign KEY(zhao_id) REFERENCES zhao(id)\x0d\x0a);\x0d\x0aforeign key (zhao_id) references to zhao(id)\x0d\x0a多了个to
oracle 定义表外键
-- 创建测试主表. ID 是主键.
CREATE TABLE test_main (
id INT,
value VARCHAR(10),
PRIMARY KEY(id)
);
-- 创建测试子表.
CREATE TABLE test_sub (
id INT,
main_id INT,
value VARCHAR(10),
PRIMARY KEY(id)
);
-- 创建外键
ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main;
分享题目:oracle怎么定义外键,oracle 设置外键
标题来源:http://pwwzsj.com/article/phhjso.html