add index (ID)
3. Modify the ID field in the table employee as the primary key.
Alter table employee add primary key (ID)
4. Modify the ID field in the table employee as the UNIQUE index UNIQUE.
Alter table employee add unique (ID)
5. Rename the id field in the employee table to salary and set its data type to int.
Alter table employee change id salary INT
6. De
ADD a field in the classic usage of the alter statement in mysql: alter table table_name ADD field_name field_type; www.2cto.com modify the original field name and type: alter table table_name CHANGE old_field_name new_field_name field_type; Delete the field: alter table tab
use change to achieve the modify effect. we only need to write the same field name after it.
Add fields without integrity constraints
Mysql> alter table person add sex boolean;
Query OK, 0 rows affected (0.21 sec)
Records: 0 Duplicates: 0 Warnings: 0
The sex here is followed by only the data type, without the integrity constraints.
Add fields with integrity constraints
, modify table Employee ID field as the primary key primary keys
ALTER TABLE employee ADD PRIMARY KEY (ID)
4, modify table Employee ID field is unique index unique
ALTER TABLE employee ADD UNIQUE (ID)
5. Rename the ID field in the Employee table to salary and set its data type to int
ALTER TABLE Employee Change ID salary INT
6, delete the customer_id field
Tags: mysql alter commandLin Bingwen Evankaka Original works. Reprint please specify the source Http://blog.csdn.net/evankakaThis article explains in detail the use of the ALTER command in MySQL syntax, which is a much more useful syntax, and the functionality is very powerful.Use the learning;
Create TABLE student (ID
COLUMN account_number INT ALTER TABLE employee ADD INDEX (ID) ALTER TABLE employee ADD PRIMARY KEY (ID) ALTER TABLE employee ADD UNIQUE (ID) ALTER TABLE Employee Change ID salary INT ALTER TABLE Employee DROP customer_id
Employee table to salary and set its data type to int
ALTER TABLE Employee Change ID salary INT
6, delete the customer_id field in the Employee table
ALTER TABLE Employee DROP customer_id
7. Delete all primary keys in employee table
ALTER TABLE employee DROP PRIMARY KEY
8. Delete the index of the field customer_id in the employee table, just cancel the cus
This article explains in detail the use of the ALTER command in MySQL syntax, which is a much more useful syntax, and the functionality is very powerful. Use Learning (to be built in advance) CREATE TABLE INT not NULL , CHAR (tennotnull, INTis notnull, INT ); Take a look at the new table.One, delete, add or modify table field
Delete a table fi
The following article is mainly about the application of the MySQL alter syntax, we all know that the MySQL alter syntax in the actual application of the proportion is still very large, so understand the actual use of the MySQL alter
> ALTER TABLE myTable -> ADD COLUMN Quantity SMALLINT UNSIGNED NOT NULL, -> MODIFY ID SMALLINT UNSIGNED NOT NULL, -> ADD PRIMARY KEY (ID);
Run the desc command again to view the table structure. The preceding modification command takes effect:
Desc myTable;+ ---------- + ---------------------- + ------ + ----- +
The following articles mainly introduce the practical use of MySQL ALTER syntax. We all know that the proportion of MySQL ALTER syntax in actual application is still very large, so you can have a good idea about the practical use of MySQL
// Primary key
Alter table tablename add new_field_id int (5) unsigned default 0 not null anto_increment, add primary key (new_field_id );
// Add a new columnMysql> alter table tablename ADD fieldname fieldtypeFor example:Alter table t2 ADD d TIMESTAMP;Alter table infos ADD ex tinyint not
statement:
mysql> ALTER TABLE myTable
-> ADD COLUMN Quantity SMALLINT UNSIGNED not NULL,
-> MODIFY ID SMALL INT UNSIGNED not NULL,
-> ADD PRIMARY KEY (ID);
Again using the DESC command to view the table structure, we found that the above modification
// Primary keyAlter table tablename add new_field_id int (5) unsigned default 0 not null anto_increment, add primary key (new_field_id );// Add a new columnMysql> alter table tablename ADD fieldname fieldtypeFor example:Alter table t2 ADD d TIMESTAMP;Alter table infos ADD ex tinyint not null default '0 ';// Delete a co
I field of the table created above:
mysql> ALTER TABLE testalter_tbl DROP i;
You cannot use drop to delete a field if only one field is left in the datasheet.
In MySQL, use the ADD clause to add columns to the datasheet, the following instance adds the I field in the table Testalter_tbl, and defines the data type:
Mysql adds a column, deletes a column, modifies a column name, and mysql columns at a certain position in the table.
To add a column to a created table, run the following code: alter t
test where ID mysql> TRUNCATE TABLE test; #删除allMysql> select * from test;Empty Set (0.00 sec)
On top, modify the table name in the database, add and remove fields from the table.
mysql> Use GBK #进入gbk数据库mysql> desc test;+-------+----------+------+-----+---------+----------------+| Field | Type | Null | Key | Defaul
Tags: color add char log alt usage RIP name testOne: Modify table information 1. Modify the table name Alter Table to Sys_app; 2. Modify Table Annotations Alter Table ' System Information Table '; Second: Modify field information 1. modifying field types and annotations Alter table sys_application columnvarchar( name of ' app ') ; 2. Modify the field type
We know that,MySQLDatabases are often combined with PHP to develop powerful applications. So for those who are new to PHP programming, it is necessary to understand some simple MySQL database operations. In this article, we useAlter tableStatement to modify the table structure. Next let's take a look at this part.
1. Add Columns
Alter table tbl_name add col_name type
For example, add a weight
original varchar (25) to varchar (20)
Modify Field name
The Code is as follows:
Mysql> alter table person change stu_name name varchar (25 );
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
Stu_name is the original name and name is the new name.
It should be noted that no matter whether the data type is changed, the subsequent data types must be written
If you do not modify th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.