Basic SQL statement Operation data additions and deletions check and change

Source: Internet
Author: User
Tags one table

1. Creating database: Create databases < 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;])
Example: Create TABLE Stuinfo (stuid int primary key,stuname varchar () NOT NULL)
5. Delete tables: drop table < table name >
such as: drop table stuinfo;
6, modify the table: ALTER TABLE
Add a new column to a table: ALTER TABLE < table name > Add < column name >< column data type >;
Add multiple columns, separated by commas
Example: 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 >
Example: ALTER TABLE stuinfo change stuname stuaddress varchar (30)
Delete columns: ALTER TABLE < table name > drop < column name >
such as: ALTER TABLE Stuinfo drop Stugender
7. The statement of the created table is reversed: Show create table < table name >
8. Querying all contents of the table: SELECT * FROM < table name >
Partial contents of the query table: Select < column Name list > from < table names >
9. Query table structure: Show columns from < table name >
10. Insert single row of data: INSERT into < table name > (< column list >) VALUES (< value list >)
11. Inserting multiple rows of data: acts as copying data from one table to another
INSERT into < table name > (List of column names) Select <select Statement >
If you copy all 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 Condition >
If you delete data for a person Stuid 4: Delete from Stuinfo where stuid=4

Basic SQL statement Operation data additions and deletions check and change

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.