SQL Server Learning Note 1

Source: Internet
Author: User

1. Query installation collation options drink the current collation server properties

SELECT * from fn_helpcollations ();

2. View the collation of the current server

Select SERVERPROPERTY (' Collation ') as servercollation;

3. Modify the collation of the database DB1 so that he is case-sensitive

Create DATABASE DB1

Go

ALTER DATABASE DB1

Collate sql_latin1_general_cp1_cs_as;

Go

Select Databasepropertyex (' DB1 ', ' Collation ') as Databasecollation

4.SQL server can set collations not only at the server, database, and column levels, but even at a separate query level.

SELECT * from Product ORDER by name Collate Danish_norwegian_ci_ai

5. An interesting phenomenon, look for the 6 lowest prices in the product table below:

Select Top 6 Productnumber,name,listprice  from Product  orderbydesc

Results:

ProductNumber
Name
ListPrice
Num1 Name1 4000
Num2 Name2 4000
Num3 Name3 4000
Num4 Name4 4000
Num5 Name5 4000
Num6 Name6 5000

It seems that the query is concise and the results are good, but it is wrong. If you look at the raw data sorted by price, you will find that the price is 4000 with 5 lines, and the price bit 5000 has 4 lines. If you want to show all 4 rows, you need to use the WITH TIES option, which allows the last position to contain multiple rows, provided that the values of these rows have the same value in the column used by the ORDER BY clause. The query is as follows:

 select  top  6  with   ties Productnumber,name, ListPrice  from  product order  Span style= "color: #0000ff;" >by  ListPrice desc  
ProductNumber
Name
ListPrice
Num1 Name1 4000
Num2 Name2 4000
Num3 Name3 4000
Num4 Name4 4000
Num5 Name5 4000
Num6 Name6 5000
Num7 Name7 5000
Num8 Name8 5000
Num9 Name9 5000

SQL Server Learning Note 1

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.