说明:此文件包含了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. Gulp-前端进阶A-2

    1.js压缩 注意在根目录的package.json文件里在成功安装uglify后要有 "gulp-uglify": "^1.5.4" 才行 var gulp ...

  2. EntityFramework学习

    本文档主要介绍.NET开发中两项新技术,.NET平台语言中的语言集成查询技术 - LINQ,与ADO.NET中新增的数据访问层设计技术ADO.NET Entity Framework.ADO.NET的 ...

  3. 推荐几个优秀的java爬虫项目

    java爬虫项目   大型的: Nutch apache/nutch · GitHub 适合做搜索引擎,分布式爬虫是其中一个功能. Heritrix internetarchive/heritrix3 ...

  4. 【读书笔记】iOS网络-HTTP-请求内容

    一,GET方法. 从服务器获取一段内容,用HTTP术语来说就是实体.GET请求通常不包含请求体,不过也是可以包含的.有些网络缓存设施只会缓存GET响应.GET请求通常不会导致服务器端的数据变化. 二, ...

  5. 【读书笔记】iOS-NSString的length

    NSString的length方法能够准确无误地处理国际字符串,如含有俄文,中文或者日本文字符的字符串,以及使用Unicode国际字符标准的字符串.在C语言中处理这些国际字符串是件令人非常头疼的事情 ...

  6. C语言-04-函数

    函数 函数是一组一起执行任务的语句,函数是一个可执行C程序必不可少的条件(至少一个main()函数),函数的定义形式 returnType functionName() { bodyOf of the ...

  7. abs()函数的返回值问题

    转载原文地址:http://www.cnblogs.com/webary/p/4967868.html 在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始 ...

  8. paas架构之docker——安装

    1. 概要 本文描述docker的安装 参考官方文档:https://docs.docker.com/engine/installation/linux/ubuntulinux/ 安装操作系统: Ub ...

  9. 修复 Java 内存模型,第 2 部分——Brian Goetz

    转自Java并发大师Brain Goetz:http://www.ibm.com/developerworks/cn/java/j-jtp03304/ (中文地址) http://www.ibm.co ...

  10. LVS入门

    说到大型网站的架构,就必然要谈到LVS.LVS即:Linux Virtual Server,是由国人章文嵩博士所创立的,已经被加入到了Linux 2.6的内核模块中了.官方网址: http://www ...