说明:此文件包含了blog数据库中建立所有的表的Mysql语句.

 在sql语句中注意“约束的概念":
1.实体完整性约束(主键--唯一且非空) primary key()
违约处理:No action(拒绝执行) 2.参照完整性约束(外键约束)foregin key() references tableName(filedName) [on delete|update casecade | no action]
违约处理:级联更新或拒绝执行 3.用户自定义完整性约束(not null,unique,check短语)
违约处理:拒绝执行 //添加列语法
//【alter table blog_article add columName type constraint】
//添加约束例子
//【alter table blog_article add CONSTRAINT foreign key(category_Name) references blog_category(category_Name) on delete cascade on update cascade】 问题:如何让相册,相片,文章公用一个评论表? create database blog; create table blog_user
(
user_Name char(15) not null check(user_Name !=''),
user_Password char(15) not null,
user_emial varchar(20) not null unique,
primary key(user_Name) )engine=innodb default charset=utf8 auto_increment=1; create table blog_category
(
category_Name char(18) not null check(category_Name!=''),
category_Date datetime not null,
primary key(category_Name)
)engine=innod default charset=utf8 auto_increment=1; create table blog_article
(
article_Id int unsigned not null auto_increment,
article_title varchar(20) not null unique,
article_content longtext not null,
article_date datetime not null,
article_readTime int unsigned not null default 0,
user_Name char(15) not null,
category_Name char(18) not null,
primary key(article_Id),
foreign key(user_Name) references blog_user(user_Name) on delete cascade on update cascade,
foreign key(category_Name) references blog_category(category_Name) on delete cascade on update cascade
)engine=innodb default charset=utf8 auto_increment=1; CREATE TABLE blog_comment (
comment_Id int(10) unsigned NOT NULL AUTO_INCREMENT,
comment_Content varchar(90) NOT NULL,
comment_Date datetime NOT NULL,
article_Id int(10) unsigned NOT NULL,
user_Name char(15) NOT NULL,
PRIMARY KEY (comment_Id),
foreign key(article_Id) references blog_article(article_Id) on delete cascade on update cascade,
foreign key(user_Name) references blog_user(user_Name) on delete cascade on update cascade
)engine=innodb default charset=utf8 auto_increment=1; create table blog_photoAlbum
(
photoAlbum_Name char(20) not null check(photoAlbum_Name!=''),
photoAlbum_Date datetime not null,
primary key(photoAlbum_Name)
)engine=innodb default charset=utf8; create table blog_photograph
(
photograph_Name varchar(20) not null check(photograph_Name!=''),
photograph_Date datetime not null,
photoAlbum_Name char(20) not null,
photoURL varchar(90) not null,
foreign key(photoAlbum_Name) references blog_photoAlbum(photoAlbum_Name) on delete cascade on update cascade
)engine=innodb default charset=utf8;

mysql创建表的更多相关文章

  1. oracle与mysql创建表时的区别

    oracle创建表时,不支持在建表时同时增加字段注释.故采用以下方式: #创建表CREATE TABLE predict_data as ( id integer ), mid ), time dat ...

  2. 【转载】Mysql创建表时报错error150

    从mysql数据库中导出正常数据库的脚本语句,而后使用脚本语句创建数据库的过程中,执行语句提示Can't Create Table 'XXX' erro150的错误,语句执行中断,创建table失败, ...

  3. mysql 创建表时注意事项

    mysql  创建表时注意事项 mysql 想必大家都不会陌生吧  是我学习中第一个接触的的数据库 已学习就很快上手的   这是一个关系型数据库  不懂什么是关系型数据库 啊哈哈哈  现在知道啦  因 ...

  4. MySQL 创建表时,设置时间字段自己主动插入当前时间

    MySQL 创建表时,设置时间字段自己主动插入当前时间 DROP TABLE IF EXISTS `CONTENT`; CREATE TABLE `CONTENT` ( `ID` char(20) N ...

  5. Python MySQL 创建表

    章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...

  6. mysql创建表分区

    MySQL创建表分区 create table erp_bill_index( id int primary key auto_increment, addtime datetime ); inser ...

  7. MySQL 创建表

     MySQL中create table语句的基本语法是: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,. ...

  8. MySQL创建表的语句

    show variables like 'character_set_client';#查询字符集 show databases;#列出所有的服务器上的数据库alter create database ...

  9. mysql创建表和数据库

    创建数据库,创建数据库表,例子.MySQL语句   1.创建数据库:    创建的代码:create  数据库的代码:database   数据库表名:随便起,只要自己记住就行.test create ...

  10. mysql创建表时,设置timestamp DEFAULT NULL报错1067 - Invalid default value for 'updated_at'

    问题背景: 线上的linux服务器上的mysql服务器中导出数据库的结构.想要在本地创建一个测试版本 导出后再本地mysql上运行却报错   1067 - Invalid default value ...

随机推荐

  1. 六个创建模式之单例模式(Singleton Pattern)

    定义: 确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.三个特点:一个类只有一个实例:必需自己创建这个实例:必需自行向整个系统提供这个实例. 结构图: Singleton:单例类,提 ...

  2. 将HTML5封装成android应用APK文件的几种方法(转)

    作为下一代的网页语言,HTML5拥有很多让人期待已久的新特性.HTML5的优势之一在于能够实现跨平台游戏编码移植,现在已经有很多公司在移动 设备上使用HTML5技术.随着HTML5跨平台支持的不断增强 ...

  3. html,xhtml和xml

    html,xhtml和xml的定义: 1.html即是超文本标记语言(Hyper Text Markup Language),是最早写网页的语言,但是由于时间早,规范不是很好,大小写混写且编码不规范: ...

  4. 可怜的js居然没有块级作用域

    js中在一个函数中定义一个for循环:for(var i=0;i<5;i++) 其中的i并不会随着for循环的结束就销毁,i会一直存在该函数中,这就是js和其他语言的区别,也就是js没有块级作用 ...

  5. ASP.NET中UEditor使用

    ASP.NET中UEditor使用 0.ueditor简介 UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协议,所有源代 ...

  6. SharePoint Tricks - Survey

    1. SharePoint 2010中,在Survey的问题框中输入HTML代码可以用于插入图片或者链接,具体方法为: 1.1 在问题框中输入html, 1.2 在New Form和Edit Form ...

  7. 【读书笔记】iOS-写代码注意事项

    一,我是尽早和经常编译的强烈支持者.通常,在写完每个方法或有点难度的代码后,都要尝试进行构建.这是一个好习惯,因为如果在上次成功编译以来添加的代码量很小,那么可以非常容易地缩小编译错误范围.这个方法还 ...

  8. img 在层内 居中显示

    div{width:250px;height:150px;background:#000;position:relative;} img{;;;;margin: auto;} <div>& ...

  9. iOS网络-05-AFNetwoking原理及常用操作

    AFN的六大模块 NSURLConnection,主要对NSURLConnection进行了进一步的封装,包含以下核心的类: AFURLConnectionOperation AFHTTPReques ...

  10. 关于ajax请求数据后,数据本身的js失效的一些想法

    今天遇到一个头疼的问题.我做一个左右翻页效果(客户要求能够无限翻页),所以只能动态请求数据,进行局部刷新操作. 这时候问题就出来了,当我请求翻页的时候,数据通过js填充到div里面,但这些数据,自身带 ...