mysqlテーブルの作成

2832 ワード

  :      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;