Common SQL statements

Source: Internet
Author: User

Create a student table

 Create TableStudent (SnoChar(6)Primary Key,/*column-Level integrity constraints, SNO is the primary key*/SnameChar(Ten)Unique,/*column-level integrity constraints, sname unique*/SsexChar(2)Check(Ssexinch('male','female')), Sagesmallint, Sdate date not NULL);

Changes to the data table

eg. Add a column to the student table

Alter Table Add Char(+);

eg. Will age data type this text long integer type

Alter Table Alter column int;

Deletion of data tables

(After the basic table is deleted, the data in the table and the indexes created on this table, views, triggers, etc. are automatically deleted, so be careful to delete them)

Drop Table Student;

Indexing (speeding up queries, increasing efficiency) and deleting

Set the number of the student table to be indexed in ascending order the number of the student table is in ascending order, and the result is a unique index based on descending.

Create Unique Index  on /* if not stated, the default is ascending */ Create Unique Index  on ASC desc);

Deletion of indexes

To delete the index of a student table

Drop Index Stusno;

Inquire:

Query student All the information

Check name, and age

Select *  from Student; Select  from Student;

Set up a SC table with the number SNO Course Number Cno score Grade

In this SC table, check the number of students who have selected the course and eliminate the repetition number.

Select distinct  from SC;

Check the student number and name of all the students in the computer department

Select  from where = ' CS ';

Check the names of students aged between 20-30 years

Select  from where between  -  and ;

String match

Find out the name and gender of the student whose name is named Zhang Wei

Select  from where  like ' Zhang _  _ wei%';

Exists

Select  from where exists (Select*fromwhere Sno=student.sno);

Common SQL statements

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.