mysql建表文档_mysql建表建库

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);

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);
经验分享 程序员 微信小程序 职场和发展