mysql创建表

 1 说明:此文件包含了blog数据库中建立所有的表的Mysql语句.
 2  
 3 在sql语句中注意“约束的概念":
 4 1.实体完整性约束(主键--唯一且非空) primary key()
 5     违约处理:No action(拒绝执行)
 6  
 7 2.参照完整性约束(外键约束)foregin key() references tableName(filedName) [on delete|update casecade | no action]
 8   违约处理:级联更新或拒绝执行
 9  
10 3.用户自定义完整性约束(not null,unique,check短语)
11       违约处理:拒绝执行
12  
13 //添加列语法
14 【alter table blog_article add columName type constraint】
15 添加约束例子
16 【alter table blog_article add CONSTRAINT foreign key(category_Name) references blog_category(category_Name) on delete cascade on update cascade】
17  
18  
19 问题:如何让相册,相片,文章公用一个评论表?
20  
21 create database blog;
22  
23 create table blog_user
24 (
25   user_Name char(15) not null check(user_Name !=''),26   user_Password 27   user_emial varchar(20) not  unique,1)">28   primary key(user_Name)         
29  
30 )engine=innodb default charset=utf8 auto_increment=1;
31  
32  
33  
34  
35 create table blog_category
36 37  category_Name char(18) not null check(category_Name!=''38  category_Date datetime not 39  primary key(category_Name)
40 )engine=innod 41  
42  
43  
44  
45 create table blog_article
46 47   article_Id int unsigned not   auto_increment,1)">48   article_title varchar(20) not 49   article_content longtext not 50   article_date datetime not 51   article_readTime null default 052   user_Name 53   category_Name 54   primary key(article_Id),1)">55   foreign key(user_Name) references blog_user(user_Name) on delete cascade on update cascade,1)">56   foreign key(category_Name) references blog_category(category_Name) on delete cascade on update cascade
57 )engine=innodb 58  
59  
60  
61  
62  
63  
64 CREATE TABLE blog_comment (
65   comment_Id int(10) unsigned NOT NULL AUTO_INCREMENT,1)">66   comment_Content varchar(90) NOT NULL,1)">67   comment_Date datetime NOT NULL,1)">68   article_Id ) unsigned NOT NULL,1)">69   user_Name char(1570   PRIMARY KEY (comment_Id),1)">71   foreign key(article_Id) references blog_article(article_Id) on delete cascade on update cascade,1)">72   foreign key(user_Name) references blog_user(user_Name) on delete cascade on update cascade
73 )engine=innodb 74  
75  
76  
77 create table blog_photoAlbum
78 79   photoAlbum_Name char(20) not null check(photoAlbum_Name!=''80   photoAlbum_Date datetime not 81   primary key(photoAlbum_Name)
82 )engine=innodb default charset=utf8;
83  
84  
85  
86  
87 create table blog_photograph
88 89   photograph_Name varchar(20) not null check(photograph_Name!=''90   photograph_Date datetime not 91   photoAlbum_Name char(20)  not 92   photoURL varchar(90) not 93   foreign key(photoAlbum_Name) references blog_photoAlbum(photoAlbum_Name) on delete cascade on update cascade
94 )engine=innodb default charset=utf8;

 

相关文章

摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
今天犯了个错:“接口变动,伤筋动骨,除非你确定只有你一个...
Writer :BYSocket(泥沙砖瓦浆木匠)微 博:BYSocket豆 瓣:...
本文目录 线程与多线程 线程的运行与创建 线程的状态 1 线程...