MySQL adds columns, modifies columns, and deletes column _ MySQL

Source: Internet
Author: User
MySQL adds, modifies, and deletes the column bitsCN.com.

View constraints in MySQL, add constraints, delete constraints, add columns, modify columns, and delete columns

  • View the table field information: desc table name;
  • View all table information: show create table name;
  • Add primary key constraint: alter table name add constraint primary key (for example, PK _ table name) primary key table name (primary key field );
  • Add foreign key constraint: alter table from table add constraint foreign key (for example: FK _ slave table _ master table) foreign key from table (foreign key field) references primary table (primary key field );
  • Delete primary key constraint: alter table name drop primary key;
  • Delete foreign key constraints: alter table name drop foreign key (case sensitive );
  • Alter table t_book rename to bbb;
  • Add column: alter table name add column name varchar (30 );
  • Delete column: alter table name drop column name;
  • Modify the column name MySQL:
    Alter table name change the name of the column to be changed (eg: xxx) to be converted to (eg: yyy) float; // float is the column type, which can be char, int, date and other types
  • Modify the column name SQLServer: exec sp_rename 't_ student. name', 'nn ', 'column ';
  • Modify the column name Oracle: alter table name rename column column1 to column2;
  • Modify column attributes: alter table name modify column1 varchar (32 );

Sp_rename: the built-in stored procedure of SQL Server, which is used to modify the table definition.

BitsCN.com

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.