Basic MySQL commands

Source: Internet
Author: User

++ ++ Basic MySQL Operations <br/> // primary key 549830479 <br/> alter table tabelname add new_field_id int (5) unsigned default 0 not null auto_increment, add primary key (new_field_id); <br/> // Add a new column 549830479 <br/> alter table T2 add D timestamp; <br/> alter table Infos add ex tinyint not null default '0'; <br/> // delete column 549830479 <br/> alter table T2 drop column C; <br/> // Rename column 549830479 <br/> alter table T1 change a B integer; <br/> // change column type 549830479 <br/> alter table T1 change B bigint not null; <br/> alter table Infos change list tinyint not null default '0'; <br/> // rename table 549830479 <br/> alter table T1 rename T2; <br/> Add an index 549830479 <br/> mysql> alter table tablename change depno int (5) not null; <br/> mysql> alter table tablename add Index name (field name 1 [, field name 2... ]); <Br/> mysql> alter table tablename add index emp_name (name ); <br/> index 549830479 with primary keywords <br/> mysql> alter table tablename add primary key (ID ); <br/> Add the index with the unique condition 549830479 <br/> mysql> alter table tablename add unique emp_name2 (cardNumber ); <br/> delete an index 549830479 <br/> mysql> alter table tablename drop index emp_name; <br/> Modify Table 549830479 <br/> Add a field: 549830479 <br/> mysql> alter table table_name add field_name field_type; <br/> modify the original field name and type: 549830479 <br/> mysql> alter table table_name change old_field_name new_field_name field_type; <br/> Delete field: 549830479 <br/> mysql> alter table table_name drop field_name; </P> <p> ++ +++ ++ MySQL constraints <br/> -------- Add a primary key constraint (bookid as the primary key) <br/> alter table bookmessage <br/> Add constraint pk_bookid primary key (bookid) <br/> -------- Add a unique constraint <br/> alter table bookmessage <br/> Add constraint uq_bookid unique (bookid) <br/> --------- add default constraint <br/> alter table bookmessage <br/> Add constraint df_address defauit ('address unknown ') for address <br/> -------- add check constraint. The age must be between 15---40. <br/> alter table readermessage <br/> Add constraint ck_age check (age between 15 and 40) <br/> ------- Add a foreign key constraint <br/> alter table bookmessage <br/> Add constraint fk_bookid <br/> foreign key (bookid) <foreign key> references readermessage <Table> (readerid) <primary key in the table> <br/> ------- Delete constraint <br/> alter table table name <br/> drop constraint name <br/> ++ ++ ++ <br/>

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.