Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8806081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:01:45+00:00 2026-06-14T02:01:45+00:00

In order to use newid() in a UDF, I’ve created a view that can

  • 0

In order to use newid() in a UDF, I’ve created a view that can help me:

create view RandomUUID as select newid() as UUID

In this way, UDFs can now get access to newid(). Cool.

My question, however, is what is the best way to select this? Does it make sense to add a TOP 1 or (nolock) to the query in my UDF? As in:

select UUID from RandomUUID

vs.

select top 1 UUID from RandomUUID (nolock) -- Or any other combo of query modifiers

UPDATE:

This SqlFiddle demonstrates how this is being used.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:01:53+00:00Added an answer on June 14, 2026 at 2:01 am

    There is no reason to add (nolock) because there is no record involved to lock! For the record, (NOLOCK) should be written as WITH (nolock) from SQL Server 2008 onwards (or was it 2005).

    TOP (1) will add a SORT operator here that will be extraneous, since there is only ever one row created.


    You can create it like this:

    create view RandomUUID as select newid() as UUID;
    GO
    
    create function give_me_a_new_id ()
    returns uniqueidentifier as
    begin
    return (select UUID from RandomUUID);
    end;
    GO
    

    Note: (nolock) will be optimized away, but TOP(1) adds a SORT operation as seen here (expand the Execution plans).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can we use order by clause in view in sql server 2005? CREATE VIEW
I don't think that I can use ORDER BY clause inside the GROUP_CONCAT function.
My query is this: SELECT TOP 5 * FROM [TableName] ORDER By NEWID() But
I understood that in order to use cookies inside of phonegap native app there
I've found that in order to use PRISM's classes in XAML you need to
Currently, I have URLs that look like this: http://www.example.com/user/create http://www.example.com/user/edit/1 But now, I have
Please advice on where can I find the lib in order to use the
This is the IMDB code http://pastie.org/private/s8m72fndjvqzdtcjjel5w and in order to use it I must
In order to use the instrumentation features introduced in JDK 5, you can use
In order to use normal mapping in GLSL shaders, you need to know the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.