Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic operation of MySQL table

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "the basic operation of MySQL table", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "the basic operation of MySQL table"!

/** ******* USER **********************/

create table USER www.yisu2017.com

(

ID int unsigned,

USERNAME varchar(10) not null,

PASSWORD varchar(32) not null,

GENDER tinyint,

BIRTHDAY date, www.yisu2017.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;

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 innodb, and the USER_ID type must be consistent with the USER (ID) type, otherwise the foreign key cannot be added successfully.

At this point, I believe that everyone has a deeper understanding of the "basic operation of MySQL table", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report