Add, query, modify, and delete operations on data in basic SQL statements

Source: Internet
Author: User

Add, query, modify, and delete operations on data in basic SQL statements
1. create a database: create database <database Name>;
For example, create database student;
2. connect to an existing database: use <Database Name>;
For example, use student;
3. delete a database: drop database <database Name>;
For example, drop database student;
4. create a table: create table <table Name> (<column Name> <column data type> [<column constraints>])
For example, create table stuInfo (stuId int primary key, stuName varchar (20) not null)
5. delete a table: drop table <table Name>
For example, drop table stuInfo;
6. modify a table: alter table
Add a new column to the table: alter table <table Name> add <column Name> <column data type>;
Add multiple columns separated by commas
For 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>
For example, alter table stuInfo modify stuGender int
Alter column name: alter table <table Name> change <old column Name> <new column Name> <data type>
For example, alter table stuInfo change stuName stuAddress varchar (30)
Delete column: alter table <table Name> drop <column Name>
For example, alter table stuInfo drop stuGender
7. Export the Statement of the created table in reverse direction: show create table <table Name>
8. query all table content: select * from <Table Name>
Query part of the table: select <column Name List> from <Table Name>
9. query the table structure: show columns from <Table Name>
10. insert a single row of data: insert into <Table Name> (<column Name List>) values (<Value List>)
11. Insert multiple rows of data: It is equivalent to copying data from one table to another.
Insert into <Table Name> (column Name List) select <select statement>
For example, copy the names of all students in 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>
For example, delete the data of a person whose stuID is 4: delete from stuInfo where stuId = 4

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.