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

Explain in detail about the addition, deletion, modification and query of MySQL database

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

Share

Shulou(Shulou.com)06/01 Report--

With the development of the Internet, more and more people have entered the IT industry, so how much do you know about the addition, deletion, modification and query of the MySQL database? In order to let you know more about the additions, deletions, modifications and queries of the MySQL database, the editor summarizes the following, let's look down together.

Create a database

CREATE DATABASE database_name

Create a tabl

CREATE TABLE `user` (`id` int (11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8

Delete tabl

DROP TABLE IF EXISTS `user`

Add a field:

"ALTER TABLE `user`ADD `id` int (11) NOT NULL DEFAULT'0' COMMENT 'ID'" ALTER TABLE `user`ADD `name` VARCHAR (20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT' name'

Delete a field

ALTER TABLE `user` DROP column name

Rename

ALTER TABLE table_name CHANGE old_field_name new_field_name field_type

Modify Typ

Alter table T1 change b b bigint not null; alter table infos change list list tinyint not null default'0'

Indexing

Alter table T1 rename T2 * * MySQL > alter table tablename change depno depno int (5) not null; mysql > alter table tablename add index index name (field name 1 [, field name 2 …]) ; mysql > alter table tablename add index emp_name (name); mysql > alter table tablename add primary key (id) with primary keywords; mysql > alter table tablename add unique emp_name2 (cardnumber) with unique restrictions; delete an index mysql > alter table tablename drop index emp_name; to modify the table:

Add fields to Thinkphp3.2, such as:

M ('admin')-> execute ("ALTER TABLE `admin` ADD `id` int (11) NOT NULL DEFAULT' 0' COMMENT 'ID'"); M (' admin')-> execute ("ALTER TABLE `admin` ADD `name` varchar (20) DEFAULT NULL COMMENT 'name'")

The above is a brief introduction to the addition, deletion, modification and search of the MySQL database, of course, the detailed use of the above differences also have to be used by everyone to understand. If you want to know more, welcome to follow the industry information channel!

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