create table table_name (column_name column_type);
創(chuàng)建Author、Article、ArticleDetail三張表
#創(chuàng)建Author表
drop table if exists Author;
create table Author(
au_id int not null PRIMARY key auto_increment comment '主鍵',
name varchar(12) comment '姓名',
sex varchar(12),
address varchar(12),
qq varchar(12),
wechat varchar(25),
create_date datetime
)DEFAULT CHARSET=utf8;
#創(chuàng)建Article表
drop table if exists Article;
create table Article(
ar_id int not null PRIMARY key auto_increment comment '主鍵',
type varchar(12) comment '類(lèi)型',
author varchar(12)comment '作者',
au_id int(11),
articles int(11),
qq_group int(11),
fans int(11),
update_date datetime
)DEFAULT CHARSET=utf8;
#創(chuàng)建ArticleDetail表
drop table if exists ArticleDetail;
create table ArticleDetail(
ad_id int not null PRIMARY key auto_increment comment '主鍵',
ar_id int(11),
title varchar(255) comment '文章標(biāo)題',
url varchar(255)comment '鏈接',
reade_times int(11),
praise_times int(11),
comments_times int(11),
publish_date datetime,
FULLTEXT(url)
)DEFAULT CHARSET=utf8;
MySQL之
操作表
表中增加新列
alter table table_name add column_name column_type;
Author表增加國(guó)籍(hometown)列
#在Author表后增加國(guó)籍列
alter table Author add hometown varchar(12);
刪除表中的列
alter table table_name drop column_name ;
Author表刪除國(guó)籍(hometown)列
#在Author表中刪除國(guó)籍列
alter table Author drop column hometown;
刪除表
drop table table_name ;
刪除Author表
#刪除表沒(méi)有確認(rèn),也不能撤銷(xiāo),執(zhí)行后將直接刪除表
drop table Author;
重命名表
rename table table_nameA to table_nameB;
將Author表重命名為ITester_Authors
rename table Author to ITester_Authors;
rename table ITester_Authors to。