SQL Server Base language

Source: Internet
Author: User


--Query basic syntax Select Column name from table name where query condition
Select ClassName from Student s,class C where s.classid=c.id and Studentname= ' Zhang San '

--Fuzzy query is the first of 4: _ Represents a character
SELECT * from Student where studentname like ' _ Three '

--There are 4 second types of fuzzy queries:% represents a number of characters
SELECT * from Student where studentname like '% three '

--The second type of fuzzy query is 4: [] represents a character
SELECT * from Student where studentname like '%[2-5] '

--There are 4 second types of fuzzy queries: [^] denotes a character
SELECT * from Student where studentname like '%[^3, three] '

--Sort By default ascending ASC descending to desc ORDER by
SELECT * from Student ORDER by ClassId Asc,studentname desc

--group by group Count (*) The total number of queries is equivalent to where but after group by
-there can be a where when having a having
Select Classid,count (*) as number from Student where studentname!= ' Zhang San ' group by ClassId have ClassId =1

--max Max min Minimum count () Total avg average sum sum
SELECT * FROM Student
Select MAX (Id), studentname from Student Group by Studentname
Select Min (Id) from Student
Select Count (Id) from Student GROUP by Studentname
Select AVG (Id) from Student GROUP by Studentname
Select SUM (Id) from Student GROUP by Studentname

--INSERT statement
--insert into table name (column name) values (value)
INSERT into Student values (2, ' Harry ')

--Modify the statement
--update table Name set column name = ' value ', column name = ' value ' Where condition (if there is no where condition, the value of this column is changed)
Update Student set studentname= ' John Doe ', classid=4 where id=2

--delete delete from table if you want to delete data from the primary table, you need to remove the
--delete table name where condition is deleted according to condition, the self-increment column will not change after deletion
Delete Student where classid=4 and Studentname= ' John Doe '
Delete Student where classid=1
Delete Class where id=1
--Delete the entire table of data
TRUNCATE TABLE Student
TRUNCATE TABLE Class

SQL Server Base language

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.