以oracle自帶的用戶scott為例。
十年品牌的成都網(wǎng)站建設(shè)公司,1000多家企業(yè)網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn).價(jià)格合理,可準(zhǔn)確把握網(wǎng)頁設(shè)計(jì)訴求.提供定制網(wǎng)站建設(shè)、商城建設(shè)、微信小程序、成都響應(yīng)式網(wǎng)站建設(shè)公司等服務(wù),我們設(shè)計(jì)的作品屢獲殊榮,是您值得信賴的專業(yè)的建站公司。
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表的外鍵
);
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)
多了個(gè)to
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多了個(gè)to
-- 創(chuàng)建測試主表. ID 是主鍵.
CREATE TABLE test_main (
id INT,
value VARCHAR(10),
PRIMARY KEY(id)
);
-- 創(chuàng)建測試子表.
CREATE TABLE test_sub (
id INT,
main_id INT,
value VARCHAR(10),
PRIMARY KEY(id)
);
-- 創(chuàng)建外鍵
ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main;