Collation of common SQL statements--sql Server 2008 (query one)

Source: Internet
Author: User

Table creation and modification of table structure we're not going to talk about it here, mainly talking about query statements and some common statements.

--Update the statement operation, the main thing to explain is that in front of the Chinese characters better add N to prevent garbled

set username=n' genius summer rain 'where id=5

--Add a new statement and get his primary key ID immediately (this is used a lot, such as restaurant management)

Insert into Values (' xiayu222 ', ' ewdfdf ', ' 172.1.1.0'@ @IDENTITY

--query statement is very powerful, almost can look for anything

--Querying SQL Server version

Select  as version

--Query Date

Select GETDATE () as Date

Now let's focus on the query statement.

--Query for eligible records

Select *fromwhere username=' summer rain '

--Query the operation after the table is sorted (order by)

Select * from Gb_data order by Createdate,username

The--order by statement must be placed behind the where statement (otherwise there will be an error---syntax errors near the keyword ' where '. )

Select *fromwhere username=' summer rain ' ORDER by CreateDate

--fuzzy query with the LIKE keyword, _ represents a character,% represents more than one character

Select *fromwhere'% rain%'
Select *from gb_data where username like ' _ Rain% '

Note: null means "Do not know", NULL participates in an operation structure that is generally null, query data is NULL, cannot be used =,! =, use the IS keyword

--query data in a range can be used in the keyword

Select  from where inch (+)

Collation of common SQL statements--sql Server 2008 (query one)

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.