数据库的MYSQL代码脚本
DROP DATABASE IF EXISTS BCCNBBS;
CREATE DATABASE BCCNBBS;
USE BCCNBBS;
CREATE TABLE USER (
ID INT NOT NULL auto_increment,
USERNAME CHAR(20) NOT NULL UNIQUE,
PASSWORD CHAR(20) NOT NULL,
NAME CHAR(20) NOT NULL,
SEX CHAR(2) NOT NULL,
EMAIL CHAR(50) NULL,
SCORE INT NOT NULL,
ENROLL_DATE DATE,
LOGIN_TIMES INT,
LAST_LOGIN DATE,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE PAGE (
ID INT NOT NULL auto_increment,
NAME CHAR(20) NOT NULL UNIQUE,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE THEME (
ID INT NOT NULL auto_increment,
PAGE_ID INT NOT NULL,
AUTHOR INT NOT NULL,
PUBLIC_DATE DATE NOT NULL,
PUBLIC_TIME TIME NOT NULL,
CONTENT TEXT NOT NULL,
VIEW_STATUS CHAR(10) NOT NULL,
LOCK_STATUS CHAR(10) NOT NULL,
SCORE INT NOT NULL,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE REPLY (
ID INT NOT NULL auto_increment,
THEME_ID INT NOT NULL,
AUTHOR INT NOT NULL,
PUBLIC_DATE DATE NOT NULL,
PUBLIC_TIME TIME NOT NULL,
CONTENT TEXT NOT NULL,
VIEW_STATUS CHAR(10) NOT NULL,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE MANAGER (
USER_ID INT NOT NULL,
POWER CHAR(10) NOT NULL,
PAGE_ID INT NOT NULL,
PRIMARY KEY (USER_ID,POWER,PAGE_ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE SCORE_OPERATE (
ID INT NOT NULL auto_increment,
SENDUSER_ID INT NOT NULL,
RECEIVEUSER_ID INT NOT NULL,
SCORE_VALUE INT NOT NULL,
OPERATE_DATE DATE NOT NULL,
OPERATE_TIME TIME NOT NULL,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE THEME ADD CONSTRAINT FK_THEME_PAGE
FOREIGN KEY(PAGE_ID) REFERENCES PAGE(ID) ON DELETE CASCADE;
ALTER TABLE THEME ADD CONSTRAINT FK_THEMEL_USER
FOREIGN KEY(AUTHOR) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE REPLY ADD CONSTRAINT FK_REPLY_THEME
FOREIGN KEY(THEME_ID) REFERENCES THEME(ID) ON DELETE CASCADE;
ALTER TABLE REPLY ADD CONSTRAINT FK_REPLY_USER
FOREIGN KEY(AUTHOR) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE MANAGER ADD CONSTRAINT FK_MANAGER_USER
FOREIGN KEY(USER_ID) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE MANAGER ADD CONSTRAINT FK_MANAGER_PAGE
FOREIGN KEY(PAGE_ID) REFERENCES PAGE(ID) ON DELETE CASCADE;
ALTER TABLE SCORE_OPERATE ADD CONSTRAINT FK_SCORE_OPERATE_USER_SENDUSER
FOREIGN KEY(SENDUSER_ID) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE SCORE_OPERATE ADD CONSTRAINT FK_SCORE_OPERATE_USER_RECEIVEUSER
FOREIGN KEY(RECEIVEUSER_ID) REFERENCES USER(ID) ON DELETE CASCADE;
恩,一旦写完脚本,就意味着应该转到技术论坛了
DROP DATABASE IF EXISTS BCCNBBS;
CREATE DATABASE BCCNBBS;
USE BCCNBBS;
CREATE TABLE USER (
ID INT NOT NULL auto_increment,
USERNAME CHAR(20) NOT NULL UNIQUE,
PASSWORD CHAR(20) NOT NULL,
NAME CHAR(20) NOT NULL,
SEX CHAR(2) NOT NULL,
EMAIL CHAR(50) NULL,
SCORE INT NOT NULL,
ENROLL_DATE DATE,
LOGIN_TIMES INT,
LAST_LOGIN DATE,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE PAGE (
ID INT NOT NULL auto_increment,
NAME CHAR(20) NOT NULL UNIQUE,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE THEME (
ID INT NOT NULL auto_increment,
PAGE_ID INT NOT NULL,
AUTHOR INT NOT NULL,
PUBLIC_DATE DATE NOT NULL,
PUBLIC_TIME TIME NOT NULL,
CONTENT TEXT NOT NULL,
VIEW_STATUS CHAR(10) NOT NULL,
LOCK_STATUS CHAR(10) NOT NULL,
SCORE INT NOT NULL,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE REPLY (
ID INT NOT NULL auto_increment,
THEME_ID INT NOT NULL,
AUTHOR INT NOT NULL,
PUBLIC_DATE DATE NOT NULL,
PUBLIC_TIME TIME NOT NULL,
CONTENT TEXT NOT NULL,
VIEW_STATUS CHAR(10) NOT NULL,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE MANAGER (
USER_ID INT NOT NULL,
POWER CHAR(10) NOT NULL,
PAGE_ID INT NOT NULL,
PRIMARY KEY (USER_ID,POWER,PAGE_ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE SCORE_OPERATE (
ID INT NOT NULL auto_increment,
SENDUSER_ID INT NOT NULL,
RECEIVEUSER_ID INT NOT NULL,
SCORE_VALUE INT NOT NULL,
OPERATE_DATE DATE NOT NULL,
OPERATE_TIME TIME NOT NULL,
PRIMARY KEY (ID)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE THEME ADD CONSTRAINT FK_THEME_PAGE
FOREIGN KEY(PAGE_ID) REFERENCES PAGE(ID) ON DELETE CASCADE;
ALTER TABLE THEME ADD CONSTRAINT FK_THEMEL_USER
FOREIGN KEY(AUTHOR) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE REPLY ADD CONSTRAINT FK_REPLY_THEME
FOREIGN KEY(THEME_ID) REFERENCES THEME(ID) ON DELETE CASCADE;
ALTER TABLE REPLY ADD CONSTRAINT FK_REPLY_USER
FOREIGN KEY(AUTHOR) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE MANAGER ADD CONSTRAINT FK_MANAGER_USER
FOREIGN KEY(USER_ID) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE MANAGER ADD CONSTRAINT FK_MANAGER_PAGE
FOREIGN KEY(PAGE_ID) REFERENCES PAGE(ID) ON DELETE CASCADE;
ALTER TABLE SCORE_OPERATE ADD CONSTRAINT FK_SCORE_OPERATE_USER_SENDUSER
FOREIGN KEY(SENDUSER_ID) REFERENCES USER(ID) ON DELETE CASCADE;
ALTER TABLE SCORE_OPERATE ADD CONSTRAINT FK_SCORE_OPERATE_USER_RECEIVEUSER
FOREIGN KEY(RECEIVEUSER_ID) REFERENCES USER(ID) ON DELETE CASCADE;
恩,一旦写完脚本,就意味着应该转到技术论坛了
淘宝杜琨