1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
说明:此文件包括了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 创建表 create table详解的更多相关文章

  1. 用复制方式创建表 Create Table tbname as select * from user.tab where ...

    用复制方式创建表 Create Table tbname as select * from user.tab where ...

  2. Oracle create tablespace 创建表空间语法详解

    CREATE [UNDO]  TABLESPACE tablespace_name          [DATAFILE datefile_spec1 [,datefile_spec2] ...... ...

  3. MySQL数据库表分区功能详解

    1.什么是表分区? mysql数据库中的数据是以文件的形势存在磁盘上的,默认放在/mysql/data下面(可以通过my.cnf中的datadir来查看),一张表主要对应着三个文件,一个是frm存放表 ...

  4. Oracle 创建表 Create Table...

    一.创建表 主键约束primary key 约束条件,唯一且非空,一个表中只能有一个主键:有多个字段联合作为主键时,合在一起唯一标识记录,叫做联合主键. 外键约束 foreign key 受另外一张表 ...

  5. mysql 数据表读锁机制详解

    为了给高并发情况下的mysql进行更好的优化,有必要了解一下mysql查询更新时的锁表机制.一.概述MySQL有三种锁的级别:页级.表级.行级.MyISAM和MEMORY存储引擎采用的是表级锁(tab ...

  6. mysql user表 权限字段详解

    Select_priv.确定用户是否可以通过SELECT命令选择数据. Insert_priv.确定用户是否可以通过INSERT命令插入数据. Update_priv.确定用户是否可以通过UPDATE ...

  7. mysql 聚集函数 count 使用详解

    mysql 聚集函数 count 使用详解 本文将探讨以下问题 1.count(*) . count(n).count(null)与count(fieldName) 2.distinct 与 coun ...

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

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

  9. mysql 聚集函数 count 使用详解(转载)

    本文将探讨以下问题 1.count(*) . count(n).count(null)与count(fieldName)2.distinct 与 count 连用3.group by (多个字段) 与 ...

随机推荐

  1. Swift和OC 混编

    1.首先创建一个Swift工程 2.导入或者创建一个OC文件(.h和.m) 3.再创建一个桥连接文件 4.然后文件样子为 5.在桥接链接里面导入头文件 6.通过targets->->bui ...

  2. Java thread中对异常的处理策略

    转载:http://shmilyaw-hotmail-com.iteye.com/blog/1881302 前言 想讨论这个话题有一段时间了.记得几年前的时候去面试,有人就问过我一个类似的问题.就是j ...

  3. Longest Substring Without Repeating Characters - 哈希与双指针

    题意很简单,就是寻找一个字符串中连续的最长包含不同字母的子串. 其实用最朴素的方法,从当前字符开始寻找,找到以当前字符开头的最长子串.这个方法猛一看是个n方的算法,但是要注意到由于字符数目的限制,其实 ...

  4. LNMP一键安装包sh脚本

    Xshell 5 (Build 0719) Copyright (c) 2002-2015 NetSarang Computer, Inc. All rights reserved. Type `he ...

  5. vs2010中iostream.h出错

    使用 #include <iostream> using namespace std; 替代 VS2010删除了所有非标准库,保留了C++标准库,iostream.h是以前旧版的库,VS2 ...

  6. C++ ABI之名字改变,编译器生成符号研究(以Qt为例)

    在C++中,由于重载等技术的存在,编译器要将函数.结构体.类等等的信息传递给链接器,就不能像C语言那样简单地通过函数名来完成,它需要提供额外的参数信息,而还要和C语言共用链接器,这就需要用到名字改编( ...

  7. Solr4.7从文件创建索引

    索引数据源并不会一定来自于数据库.XML.JSON.CSV这类结构化数据,很多时候也来自于PDF.word.html.word.MP3等这类非结构化数据,从这类非结构化数据创建索引,solr也给我们提 ...

  8. Boost.Asio基础(三)

    Socket控制 以下的函数进行处理一些高级的socket选项: get_io_service():返回io_service实例 get_option(option):返回socket option对 ...

  9. Android开发之TextView排版问题

    下面直接是关于解决该问题的代码(根据别人的代码进行了修正以及测试,保证可以修改字体尺寸.颜色.根据padding调整,如果需要支持其他的格式可以将对应的属性添加至Paint类型的对象中):   1 p ...

  10. ASP.NET身份验证的几种方式

    1.windows身份验证 2.  Forms验证 3.Passport验证 4.none http://www.jb51.net/article/30510.htm