Several mysql operations commonly used in PHP and phpmysql operations

Source: Internet
Author: User

Several mysql operations commonly used in PHP and phpmysql operations

Display database or table:

Copy codeThe Code is as follows:
Show databases; // you can then use database_name;
Show tables;

Change Table Name:

Copy codeThe Code is as follows:
Alter table table_name rename new_t;

Add column:

Copy codeThe Code is as follows:
Alter table table_name add column c_n column attributes;

Delete column:

Copy codeThe Code is as follows:
Alter table table_name drop column c_n;

Create an index:

Copy codeThe Code is as follows:
Alter table c_table add index (c_n1, c_n2 );
Alter table c_table add unique index_name (c_n );
Alter table c_table add primary key (sid );

Delete An index:

Copy codeThe Code is as follows:
Alter table c_table drop index c_n1;

Change column information:

Copy codeThe Code is as follows:
Alter table t_table change c_1 c_1 varchar (200 );
Alter table t_table modify 1 c_1 varchar (200 );

Insert statement:

Copy codeThe Code is as follows:
Insert into table_name (c_1, c_2)
Values ('x1', 1 );

Update statement:

Copy codeThe Code is as follows:
Update table_name set c_1 = 1 where c_2 = 3;

Delete a database or table:

Copy codeThe Code is as follows:
Drop table table_name;
Drop database database_name; // data that can be deleted using mysql_drop_db.

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.