Linux MySQL modified data table structure syntax

Source: Internet
Author: User
Tags dname

MySQL Modify table syntax
=========================
Add column [Add column name]
=========================
①alter table name Add column list Type column parameter "Add column to last face of table"
Example: ALTER TABLE test add username char (a) not null default ';
ALTER TABLE test add birth date not null default ' 0000-00-00 ';

②alter table name Add column list type column parameter after a column "Add a new column after a column"
Example: ALTER TABLE test add gender char (1) NOT null default "after username;

③alter table name Add column list type column parameter First "Add new column to the front"
Example: ALTER TABLE TEST add PID int NOT null default 0 first;

=========================
Delete column [drop column name]
=========================
①alter table Name drop column name
Example: ALTER TABLE test drop PID;

=========================
Modify column [modife column name]
=========================
①alter table name Modify column name new type new parameter "Modify column type"
Example: ALTER TABLE test modify gender char (4) NOT null default ';
②alter table name change old column name new column name new type new parameter "Modify column name and column type"
Example: ALTER TABLE test change PID UID int. unsigned NOT NULL default 0;

=========================
Query columns
=========================
①DESC table name "Querying all Columns"
Example: DESC test;
Mysql> DESC Department;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Did | Int (11) | NO | PRI | | |
| Dname | varchar (32) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+

②show columns from table name "Effect as DESC"
Mysql> Show columns from department;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Did | Int (11) | NO | PRI | | |
| Dname | varchar (32) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+

③show CREATE TABLE table name "View Creation code for table"
Mysql> Show CREATE TABLE department;
CREATE TABLE ' Department ' (
' Did ' int (one) is not NULL,
' dname ' varchar (+) DEFAULT NULL,
PRIMARY KEY (' did ')
) Engine=innodb DEFAULT Charset=utf8

Linux MySQL modified data table structure syntax

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.