SQL Statement Encyclopedia

Source: Internet
Author: User

1. Creating database: Create DB < database name >;

Such as: Create database student;

2. Connect to an existing database: Use < database name >;

such as: Use student;

3. Delete databases: Drop database < database name >;

such as: drop database student;

4. Creating table: Create table < table name > (< column name >< column data type >[< column constraint;])

such as: Create TABLE stuinfo (stuid int primary key,stuname varchar () NOT NULL)

5. Delete Table: Drop table < table name >

such as: drop table stuinfo;

6, modify the table: ALTER TABLE

To add a new column to a table: ALTER TABLE < table name > Add < column name >< column data type >;

Add multiple columns, separated by commas in the middle

such as: ALTER TABLE stuinfo add Stugender varchar (10)

Modify the data type of a column: ALTER TABLE < table name > Modify < column name >< new data type >

such as: ALTER TABLE stuinfo modify Stugender int

Modify column name: ALTER TABLE < table name > change < old column name >< new column name >< data type >

such as: ALTER TABLE stuinfo change stuname stuaddress varchar (30)

Delete column: ALTER TABLE < table name > drop < column name >

such as: ALTER TABLE Stuinfo drop Stugender

7. Reverse-Wizard The statement of the table you created: Show create table < table name >

8, all the contents of the query table: SELECT * FROM < table name >

Part of the query table: Select < column list > from < table name >

9. Query table structure: Show columns from < table name >

10. Insert single line data: INSERT into < table name > (< column list >) VALUES (< value list >)

11, inserting multiple rows of data: The role is equivalent to copy data from one table to another table

INSERT into < table name > (column list) select

If you copy all the student names from the Stuinfo table to the Stuname column in the students table: INSERT into students (stuname) select Stuname from Stuinfo

12, delete data: Delete from < table name > where< filter Conditions >

If you delete the data for the person who stuid 4: Delete from Stuinfo where stuid=4

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.