MySQL alter command, mysqlalter
Use the alter command in mysql to edit the table structure. The details are as follows:
Modify Field Type
mysql> alter table employee change depno depno int(5) not
Alter Table' User_movement_log 'ADD columnGatewayidint not NULL default 0After ' RegionID ' (which field is added later)Alter TableX_connectionAdd' FEX-N752 'varchar(Ten)default NULL;//PRIMARY KeyAlter TableTabelnameAddnew_field_idint(5) unsigneddefault 0 not NULLAuto_increment,Add Primary Key(new_field_id);//Add a n
do not modify the data type just write the original data type
Tips: We can also use change to achieve the modify effect by simply writing the same field name later
add fields with no integrity constraints
Copy Code code as follows:
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 only by
Alter is a very powerful feature. We can use ALTER to modify the data table name and some other operations, and let's look at an example of adding, deleting, and modifying the table name in the ALTER datasheet in MySQL.
Modify the data content in the MySQL database to del
MySQL alter summary (reprint)1: Delete ColumnsALTER table "table name" DROP "column name"2: Add columnsALTER table "table name" ADD "column name" INT not NULL COMMENT ' comment description '3: Modify the column type informationALT
Alter table only allows adding columns that can contain null values or specified the default definition.
If:
If exists (select 1 from sysobjects where name = n' tab _ test') and not exists (select 1 from sysobjects A, syscolumns B where B. id =. ID and B. name = n' Col _ test' and. name = n' tab _ test ')Alter table tab_testAdd col_test smallint not nullGo
You wi
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 column
Mysql>alter TABLE tablename ADD fieldname FieldType
Such as:
ALTER TABLE T2 AD
A collection of SQL statements for the ALTER TABLE of MySQL, including adding, modifying, deleting fields, renaming tables, adding, deleting primary keys, and so on.
1: Delete Column
ALTER table "table name" DROP "column name"
2: Adding columns
Tags: scan column hang BBB alt class unsigned SQL sigSeptember 15, 2017 10:36:54 Friday Today comes an efficiency issue to note: Scenario: MySQL To change the comment for the table field because of an SQL statement problem that causes the entire table to be updated ... Error: ALTER TABLE COLUMN SMALLINT (4notNULLDEFAUL
Detailed description of unique constraints and NULL in MySQL, and detailed description of null constraints in mysql
Preface
In the previous requirement, the simplified description is to accept MQ messages from other groups and insert a record in the database. To prevent them from sending messages repeatedly and insert
Label:Get ready:CREATE table t (x int,y int); Usage 1:Modifying a column's data classALTER TABLE t modify column y nvarchar (32); Usage 2:Add a column to a tableALTER TABLE t add column z int; Usage 3:To delete a column in a tableALTER TABLE t drop column Z; Usage 4:Chan
The MySQL ALTER TABLE statement can modify the basic structure of the table, such as adding fields, deleting fields, adding primary keys, adding indexes, modifying field data types, renaming tables, and so on, and this article introduces the use of MySQL ALTER TABLE with two simple examples.
Example: Use the
Tags: Suppose data tty span name length col number descriptionALTER TABLE project_list
CHANGE COLUMN descriptionofproj proj_desc VARCHAR(100), CHANGE COLUMN contractoronjob con_name VARCHAR(30); MODIFY: Use it to modify only the type of the column without interfering with its name, assuming you want to change the character length of the Proj_desc
Insert a new column after specifying a column in MySQL, and insert a column in mysql.ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_nameAlter_specification [, alter_specification]...Alter_specification:Table_options| ADD [COLUMN] col_name column_definition[FIRST | AFTER col_nam
NULL, lastname CHAR(50) NOT NULL, age SMALLINT NOT NULL, townid SMALLINT NOT NULL, PRIMARY KEY (peopleid) );
The following figure shows the data we inserted into the people table:
In this data segment, there are four people named "Mikes" (two named Sullivans and two named McConnells), two 17-year-olds, and one na
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.