SQL Server Starter Statement summary _mssql

Source: Internet
Author: User

For a database to have more or less to master, the first basic SQL statements to understand. Here's a summary of some entry-level SQL statements.

Create related

Show Database; Show the existing database
use database_x; Now you want to use the database database_x
CREATE TABLE coffee (id int (5) Not null,coffee_name varchar (25)); Create a table that contains IDs and coffee_name two fields
ALTER TABLE coffee add taste varchar (10); Add a new column
insert into coffee (Id,coffee_name,taste,rank) value ("1", "BlueMountain", "OK", "5"); Inserting data
show columns from coffee; View table Structure
Show create TABLE coffee; View table information, including the build table statement
ALTER TABLE student rename SS; Change table name
ALTER TABLE SS drop Mark; Delete Mark column in table SS
SELECT statement

select * from coffee where id= "1"; query out all id=1 information
Select Coffee_name from coffee where id= "2"; query out id=2 coffee name SELECT * FROM club where ID between "1" and "3"; Query for entries from id=1 to 3
select * FROM club where id= "1" or id= "3"; query out id=1 and id=3 two entries
select Club_name from club where Mark> ; 50; Check out the club with Mark greater than 50
select Club_name from the club where Mark not between  and 50; check mark is not in the club between 48 and 50
SELECT * From club where ID in ("1", "3", "4"); Query id=1,3,4 Entries
select * FROM club where ID is not in ("1", "3", "4");
SELECT * from the club where name like "m%r"; Wildcard% represents characters of any length (can be 0, Chinese characters are two characters)
select * FROM club where name like "M_r"; _ Represents a single character
select * FROM club where ID in ("1", " 3 "," 4 ") and mark>50; Multiple Queries
SELECT * FROM club orders by Mark Desc, in descending order of Mark (desc: Descending, USC: Ascending)
Quantity query related

Select COUNT (*) from club; Find out how many records are in the club
Select COUNT (distinct mark) from club; How many records are there in different fractions?
select SUM (Mark) from club; Sum of points
Select AVG (Mark) from club; Average integral
select Max (Mark) from club; Maximum integral
Select min (Mark) from club; Minimum integral
UPDATE statement

Update Club set mark=mark-8 where id= "1"; Id=1 's club is fined 8 points.
Delete statement

Delete from club where id= "001"; Delete Id=001 's Club information
The above statements are SQL statements and additions to check the most basic part of the entry level, must be mastered.

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.