mysql建表文档_mysql建表建库

「爱情、让人受尽委屈。」 2022-11-01 00:48 278阅读 0赞

create database if not exists `dbname`;

DROP TABLE IF EXISTS `tbname`;

CREATE TABLE `tbname`(…)

用户登录user

查看贴子

用户发贴

回复贴子

create database if not exists `dbname`;

DROP TABLE IF EXISTS `tbname`;

CREATE TABLE `tbname`(…)

表:

usr:

username

password

create table usr

(username char(15) primary key,

password char(15)

)

topic:

topicID

topicName

TContent

Ttime

TUser

create talbe topic

(topicID int auto_increment primary key,

topicName varchar(50),

TContent text,

Ttime date,

TUser char(15)

)

alter table topic

add constraint FK_TUser foreign key(TUser) references usr(username);

answerTopic

AnUser

AnTime

AnContent

topicID

create table answerTopic

(

AnTopicID int auto_increment primary key,

AnUser char(15),

Antime date ,

AnContent text,

topicID int

)

alter table answerTopic

add constraint FK_anuser foreign key(AnUser) references usr(username);

alter talbe answerTopic

add constraint FK_topicID foreign key(topicID) references topic(topicID);

drop table if exists `usr`;

create table usr

(username char(15) primary key,

password char(15)

);

drop table if exists `topic`;

create table topic

(topicID int auto_increment primary key,

topicName varchar(50),

TContent text(1000),

Ttime date,

TUser char(15)

);

drop table if exists `answerTopic`;

create table answerTopic

(

AnTopicID int auto_increment primary key,

AnUser char(15),

Antime date ,

AnContent text,

topicID int

);

alter table topic

add constraint FK_TUser foreign key(TUser) references usr(username);

alter table answerTopic

add constraint FK_anuser foreign key(AnUser) references usr(username);

alter table answerTopic

add constraint FK_topicID foreign key(topicID) references topic(topicID);

发表评论

表情:
评论列表 (有 0 条评论,278人围观)

还没有评论,来说两句吧...

相关阅读