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

What are the SQL statements commonly used in MySQL such as table building?

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article will explain in detail what MySQL commonly used SQL sentences such as table building are, and the editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Build a table:

DROP TABLE IF EXISTS bulletin CREATE TABLE bulletin (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, # primary key uid INT (11) NOT NULL DEFAULT 0, # creator id context VARCHAR (600) NOT NULL DEFAULT'', # announcement details (300 words) begintime DEC (20) NOT NULL DEFAULT 0, # announcement start time endtime DEC (20) NOT NULL DEFAULT 0, # announcement end time createtime DEC (20) NOT NULL DEFAULT 0 # creation time modifytime DEC (20) NOT NULL DEFAULT 0 # modification time PRIMARY KEY (`Id`),) DEFAULT CHARSET=UTF8 TYPE=INNODB

Modify the original field name and type:

ALTER TABLE bulletin CHANGE uid username VARCHAR (50) NOT NULL DEFAULT''

Add a new field:

Alter table bulletin add citycode varchar (6) not null default 0; # City Code

1. Set the encoding when you create the database

Create database test character set utf8

two。 Set encoding when creating a table

Create table test (id int primary key) DEFAULT charset=utf8

3. Modify database coding

Alter database test character set utf8

4. Modify table default coding

Alter table test character set utf8

5. Modify field coding

Alter table test modify col_name varchar (50) CHARACTER SET utf8

Add index method

1. Add PRIMARY KEY (primary key index)

Mysql > ALTER TABLE `table_ name` ADD PRIMARY KEY (`column`)

two。 Add UNIQUE (unique index)

Mysql > ALTER TABLE `table_ name` ADD UNIQUE (`column`)

3. Add INDEX (normal index)

Mysql > ALTER TABLE `table_ name` ADD INDEX index_name (`column`)

4. Add FULLTEXT (full-text index)

Mysql > ALTER TABLE `table_ name` ADD FULLTEXT (`column`)

5. Add multi-column index

Mysql > ALTER TABLE `table_ name` ADD INDEX index_name (`column1`, `column2`, `column3`) this is the end of the article on "what are the common SQL statements such as table building in MySQL". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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