MSSQL system function newid () My understanding and knowledge

Source: Internet
Author: User

Maybe you should be familiar with the ms SQL built-in function newid. Yesterday, my colleague asked me how to check the mobile phone number in LINQ. I did not think twice, do you want to use it. net's random () function to generate a selection condition for the application, and then conduct the query. Later, she told me that she has search on the website, I just don't know how to use it. Later, let's take a look at the attention of the generation on the website. I still understand it, however, I have posted my own experiences and experiences. You are a hacker, expert, or ninja, and don't miss me. I am a self-School, hehe, however, I also hope that you will point out my shortcomings here. At least you can learn many things in the Forum, the new technologies and ideas have also been improved in the discussion of each other. You may post comments, comments, and comments.

-- Off-topic: I always think that traditional Chinese characters are rich and profound, but I still want to use simplified Chinese characters to make myself more comfortable with others.

Is generated based on SQL Server 2005

1. First talk about newid ():

Newid () is a function added by ms SQL Server. It is used to return the randomly generated uniqueidentity value. As shown in position 1 in the figure, there is a return parameter. As you can see, please note that @ none is an input parameter. In fact, it is equivalent to a placeholder here. It does not work, but indicates that newid () does not use input parameters, none.

If you do not believe it, you can perform verification:

Code sample:

Select Top 2 * from MERs orderNewid (4)

Red part: with a parameter

MSSQL prompts an error:

Information: The newid function requires 0 argument (s ).

The newid function requires 0 parameters. The implication is that there is no parameter.

2. Let's talk about how to use the newid () function.

In the MSSQL query analyzer or SQL script editing area, enter the following SQL statement

In fact, in 1, we have vaguely figured out how to use newid function,

CodeCopy it once:

Select Top 2 * from MERs order by newid () -- you can see the column 2 in the figure.

3. Execute multiple excute SQL commands,

You will find that the two data records after each execution are random and basically different results.

Let's talk about how to use newid () in ms SQL.

In the next article, I will discuss how to use newid () in LINQ ()

 

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.