MYSQL数据库mysql创建数据表实例代码

《MYSQL数据库mysql创建数据表实例代码》要点:
本文介绍了MYSQL数据库mysql创建数据表实例代码,希望对您有用。如果有疑问,可以联系我们。

导读:在mysql数据库中创建表: create table shujubiao( id int primary key auto_increment,指定为i整形 name varchar(32) not nul...

在mysql数据库中创建表:
 MYSQL应用

create table shujubiao(
id int primary key auto_increment,指定为i整形
name varchar(32) not null,指定为不固定长度,最大为32为字符,不能为空
password varchar(64) not null,最大为64为字符,不能为空
email varchar(128) not null,最大为128为字符,不能为空
age tinyint unsigned not null 指定为小整型
)

mysql创建表
说明:此文件包含了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】
 
问题:如何让相册,相片,文章公用一个评论表?
 MYSQL应用

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;MYSQL应用

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,
  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;
(脚本学堂 www.jbxue.com)
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;MYSQL应用

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应用

以上分享了mysql数据库创建表的多个实例,希望对大家有所赞助.MYSQL应用

《MYSQL数据库mysql创建数据表实例代码》是否对您有启发,欢迎查看更多与《MYSQL数据库mysql创建数据表实例代码》相关教程,学精学透。编程之家PHP学院为您提供精彩教程。

相关文章

在正式开始之前,我们先来看下 MySQL 服务器的配置和版本号信...
> [合辑地址:MySQL全面瓦解](https://www.cnblogs.c...
物理服务机的CPU、内存、存储设备、连接数等资源有限,某个时...
1 回顾 上一节我们详细讲解了如何对数据库进行分区操作,包括...
navicat查看某个表的所有字段的详细信息 navicat设计表只能一...
文章浏览阅读4.3k次。转载请把头部出处链接和尾部二维码一起...