新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1
创新互联公司是一家专注于成都网站设计、做网站、成都外贸网站建设公司与策划设计,奉贤网站建设哪家好?创新互联公司做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:奉贤等地区。奉贤做网站价格咨询:028-86922220
一个表只能有一个主键,但是可以用两个字段做联合主键,但针对你发上来的情况,板块表只可以用id字段做主键
create table bk(
id number primary key,
name varchar2(50) not null);
然后创建帖子表
create table tz(
id number primary key,
title varchar2(50),
bkid number,
foreign KEY(bkid) REFERENCES bk(id));
注意 :一定要先创建bk表,再创建tz表
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
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
--使用表级约束
CREATE TABLE table_name
(column_1 datatype ,
column_2 datatype ,
...
CONSTRAINT fk_column
FOREIGN KEY (column_1, column_i, ... column_n)
REFERENCES parent_table (column_1, column_i, ... column_n)
);
--使用列级约束
CREATE TABLE table_name
(column_1 datatype ,
column_2 datatype CONSTRAINT fk_column REFERENCES parent_table (column_name),
...
);
主外键需要依托多表来创建,方法如下:
创建主表:
CREATE TABLE SCOTT.DEPT
(DEPTNO NUMBER(2,0) PARIMARY KEY,
DNAME VARCHAR2(14),
LOC VARCHAR2(13));
创建副表及外键:
CREATE TABLE EMP
(EMPNO NUMBER(4,0) PRIMARY KEY,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4,0),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2,0),
CONSTRAINT FK_DEPTNO FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO));