加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2020-12-12 03:06:07 所属栏目:MySql教程 来源:网络整理
导读:《MYSQL数据库mysql创建数据表实例代码》要点: 本文介绍了MYSQL数据库mysql创建数据表实例代码,希望对您有用。如果有疑问,可以联系我们。 导读:在mysql数据库中创建表:create table shujubiao( id int primary key auto_increment,指定为i整形 name var

《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学院为您提供精彩教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读