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

How to modify the table structure and the function of adding, deleting and modifying fields in MySQL

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

Share

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

This article is about how MySQL modifies the table structure and adds, deletes and modifies fields. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

MySQL modify table structure add delete modify fields

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'"); Thank you for reading! On "MySQL how to modify the table structure and add delete modify field function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

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: 281

*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