MySQL表基本操作
/********* USER **********************/
create table USER www.2cto.com
(
ID int unsigned,
USERNAME varchar(10) not null,
PASSWORD varchar(32) not null,
GENDER tinyint,
BIRTHDAY date, www.2cto.com
IMAGEURL varchar(30),
CREATED_DATE timestamp,
STATUS tinyint default 1
)engine=innodb, default charset=utf8;
alter table USER add constraint PK_USER primary key (ID);
alter table USER modify column ID int unsigned not null auto_increment;
create unique index IX_USER_USERNAME on USER (USERNAME);
create index IX_USER_PASSWORD on USER (PASSWORD);
create index IX_USER_CREATED_DATE on USER (CREATED_DATE);
/******* MESSAGE **************/
create table MESSAGE
(
ID int unsigned,
USER_ID int unsigned not null ,
CONTENT varchar(400) not null ,
CREATED_DATE timestamp,
STATUS tinyint default 1
)engine=innodb, default charset=utf8;
www.2cto.com
alter table MESSAGE add constraint PK_MESSAGE primary key (ID);
alter table MESSAGE modify column ID int unsigned not null auto_increment;
alter table MESSAGE add constraint FK_MESSAGE_USER foreign key(USER_ID) references USER(ID);
create index IX_MESSAGE_USER_ID on MESSAGE (USER_ID);
create index IX_MESSAGE_CREATED_DATE on MESSAGE (CREATED_DATE);
//注意設置引擎為innodb,而且USER_ID類型要和USER(ID)類型一致,否則外鍵是不能添加成功的。
作者 wangyang2698341