日期:2014-05-16  浏览次数:20495 次

论坛数据库设计SQL建表二

数据库设计(1)后,按着步骤往下走。2.1,2.2,2.3是步骤。

?

1. 授予权限
grant connect,resource,dba to ceran
------------------------------------------------------------------------
2. 创建注册用户表
2.1
CREATE TABLE users (
?? user_Id number(10) NOT NULL,
?? user_Name varchar2(20),
?? user_Password varchar2(20),
?? true_Name varchar2(20),
?? user_Email varchar2(100) ,
?? user_Type char(5),
?? register_Time Date,
?? constraint PK_users primary key(user_Id)
)
TABLESPACE bbs_data
PCTUSED??? 40
PCTFREE??? 10
INITRANS?? 1
MAXTRANS?? 255
STORAGE??? (
??????????? INITIAL????????? 64K
??????????? MINEXTENTS?????? 1
??????????? MAXEXTENTS?????? 2147483645
??????????? PCTINCREASE????? 0
??????????? FREELISTS??????? 1
??????????? FREELIST GROUPS? 1
??????????? BUFFER_POOL????? DEFAULT
?????????? )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;

2.2
CREATE SEQUENCE seq_users
START WITH 1
INCREMENT BY 1
CACHE 20
NOCYCLE
NOORDER;
2.3
insert into users(userId)
values(seq_users.nextval);
------------------------------------------------------------------------
3.? 创建主版区
3.1
CREATE TABLE discuss(
?? discuss_Id number(10) not null,
?? discuss_Name varchar2(50),
?? disscuss_Order integer,
?? disscuss_Desc? varchar2(200),
?? constraint PK_discuss primary key(discuss_Id)
)

TABLESPACE bbs_data
PCTUSED??? 40
PCTFREE??? 10
INITRANS?? 1
MAXTRANS?? 255
STORAGE??? (
??????????? INITIAL????????? 64K
??????????? MINEXTENTS?????? 1
??????????? MAXEXTENTS?????? 2147483645
??????????? PCTINCREASE????? 0
??????????? FREELISTS??????? 1
??????????? FREELIST GROUPS? 1
??????????? BUFFER_POOL????? DEFAULT
?????????? )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
3.2
CREATE SEQUENCE seq_discuss
START WITH 1
INCREMENT BY 1????
CACHE 20
NOCYCLE
NOORDER;
3.3
insert into discuss(discussId)
values(seq_discuss.nextval);

------------------------------------------------------------------------
4.? 创建子版块
4.1
CREATE TABLE subBoard(
subBoard_Id number(10) not null,
??? discuss_Id number(10) not null,
?subBoard_Name varchar2(20),
?subBoard_Desc varchar2(20),
?topic_Number number(10),
?reply_Number number(10),
?rowsTopic_Per_Page number(10),
?rowsReply_Per_Page number(10),
?//topic_Point number(10),
?//reply_Point number(10),
?subBoard_Order_Number number(10),
?creat_Time date,
?? constraint PK_subBoard primary key(subBoard_Id)
)
TABLESPACE bbs_data
PCTUSED??? 40
PCTFREE??? 10
INITRANS?? 1
MAXTRANS?? 255
STORAGE??? (
??????????? INITIAL????????? 64K
??????????? MINEXTENTS?????? 1
??????????? MAXEXTENTS?????? 2147483645
??????????? PCTINCREASE????? 0
??????????? FREELISTS??????? 1
??????????? FREELIST GROUPS? 1
??????????? BUFFER_POOL????? DEFAULT
?????????? )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;

4.2
CREATE SEQUENCE seq_subBoard
START WITH 1
INCREMENT BY 1
CACHE 20
NOCYCLE
NOORDER;

------------------------------------------------------------------------
5.? 创建主题贴
5.1
CREATE TABLE topic(
?? topic_Id number(10) NOT NULL,
?? base_Id number(10),
?? discuss_Id number(10),
?? user_Id number(10),
?? topic_Article varchar2(50),
?? topic_Content varchar2(2000),
?? publish_Time? Date,
?? reply_Count Integer,
?? consraint PK_topic primary key(topic_Id),
?? constraint FK_topic_REFE foreign key(discussId) references users(user_Id),
?? constraint FK_topic_REFE foreign key(userId) references topic(topic_Id)
)

TABLESPACE bbs_data
PCTUSED??? 40
PCTFREE??? 10
INITRANS?? 1
MAXTRANS?? 255
STORAGE??? (
??????????? INITIAL????????? 64K
??????????? MINEXTENTS?????? 1
??????????? MAXEXT