Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-06-01 00:03:24 09月17日 Update

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!

Tags: Field index structure function content name more article good practical key keyword data database article condition see knowledge type Gasso Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Apple MySQL Shulou Tech Info