Get the App
SLTechnology News&Howtos  ›  Database  › 

Basic operation of MySQL table

Shulou Source: shulou.com Published: 2022-05-31 18:37:15 11月12日 Update

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!

Tags: Basic operation content type learning practical deeper consistent success interest practicality practical engine simple operation method more friends website channel query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS Huawei MariaDB Xiaomi