Basic MySQL table operations

Source: Internet
Author: User


Basic MySQL table operations/*********************************/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 = innod B, 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 ); // note that the engine is set to innodb And the USER_ID type must be the same as the USER (ID) type. Otherwise, the foreign key cannot be added successfully. Author: wangyang2698341

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.