Questions tagged [newid]

NEWID() is a SQL Server function which creates a unique value of type uniqueidentifier.

NEWID() is a SQL Server function which creates a unique value of type uniqueidentifier.

Reference

MSDN article

73 questions
0
votes
2 answers

Populating GUID column with NEWID() in an INSERT INTO SELECT FROM statement is throwing an error (NULL) value

I am trying to populate Table1 with values from Table2 if they do not already exist in Table1. Table1 has a UNIQUEIDENTIFIER constraint and has a default value of NEWID() specified. I was using a SELECT DISTINCT statement to get the results from…
Boozy
  • 3
  • 4
0
votes
1 answer

getting one random row from a table inside a function- sql server

i have this procedure in sql. the requirment is: if condition (for example i put 1=1 ..) then [run another procedure or function that will random from table with values one value and return it.] else 1 for example: case when 1=1 then (dbo.myFunc…
malka
  • 19
  • 1
  • 8
0
votes
3 answers

using NEWID() inside a function - as variable - but getting the same value every time

I'm using NEWID() inside a function. this is my function: CREATE FUNCTION dbo.myFunc (@newid NVARCHAR(50)) RETURNS int AS BEGIN declare @rndValue int set @rndValue = (SELECT top 1 * FROM #temp ORDER BY lower(@newid)) RETURN @rndValue…
malka
  • 19
  • 1
  • 8
0
votes
1 answer

Sybase ASE new id function behavior

We use the Sybase function Newid() to generate UUID, that works fine and the generate UUID are unique, however, we noticed after hundred executions that the last 12 chars of the generated UUID are the same. is it a normal behavior of this function…
0
votes
1 answer

SQL SP not consistantly generating unique newid()

I am having problems with a stored procedure that i have created. I just started programming with sql about 6 months ago, so my SP might appear to be sloppy, so sorry in advance. Heres the issue i am having: I am selecting the top item in a table,…
Devon Sams
  • 1,324
  • 2
  • 12
  • 19
0
votes
1 answer

Allocate Unique Random case number SQL 2008

I have a list of teams in one table and list of cases in another table. I have to allocate a unique random case number to each one of the members in the team. What is the best way to generate unique random case number for each team member. I have…
sparc
  • 345
  • 1
  • 2
  • 13
0
votes
0 answers

SQL Server syntax for NEWID()

I need some help with some SQL Server 2014 syntax. I want to use the NEWID() function to create the UUID value in column CareplannersUUID. Each time a record is inserted, I want a new UUID value to appear in column CareplannersUUID. But I am not…
Eric B
  • 29
  • 5
0
votes
1 answer

SQL Server Copy Random data from one table to another

I have 2 tables stuff and nonsense. nonsense is not the same size as stuff; in this case it is has fewer rows, but it may have more. The structures are something like this: CREATE TABLE stuff ( id INT PRIMARY KEY, details VARCHAR(MAX), …
Manngo
  • 14,066
  • 10
  • 88
  • 110
0
votes
1 answer

SQL update column with random numbers from set list of values

I have a table that gets rewritten each night. I have two columns that need to be populated with a random number from a set list of values. Angle column needs to be populated with 15,30,45,60,90 and Distance needs to populated with 9,15,21. The…
Slink182
  • 13
  • 5
0
votes
1 answer

Select random rows from table

I want to select 24 Random rows from whole table of Admin_Pic_Lib, but this Query give syntax error, SELECT top 24 CAST( [Pictures] AS varbinary(Max)) FROM Admin_Pic_Lib ORDER BY NEWID() UNION ALL SELECT CAST([Pictures] AS varbinary(Max)) …
Avais
  • 5
  • 4
0
votes
0 answers

select top rows from huge table efficiently with where clause

In a huge sql server table which is having 2,00,000 records, does the query like below should be fine considering performance perspective. Please provide your suggestions to improvise this query. INSERT INTO @Results (Name, URL, MSA) select top…
0
votes
3 answers

SQL select random record

I have a table like below and wish to select distinct people e.g row 2, 9, 11, 20. I don't want to select MAX() as that's not random. And I don't want to select Jack twice. It needs to be one person from each set of records ID Name Category…
Abbaskhan
  • 87
  • 2
  • 10
0
votes
1 answer

Avoid certain characters in NEWID() in SQL

I have a table with columns id and name. In the id column, a key generated using NEWID() is inserted. SET @myid = NEWID() SELECT @id = SUBSTRING(CONVERT(varchar(255), @myid), LEN(@myid)-5, LEN(@myid)) This could be some randomly generated…
Divya Rose
  • 227
  • 4
  • 22
0
votes
1 answer

How to select distinct sets of 6 randomised rows partitioned on one column in SQL

I have a simple results set that gives me a User ID and an Operator from a table that contains other columns, one of which is a GUID based on an activity that has taken place for that user. I've added a row number and partitioned by the Operator to…
Phteven
  • 139
  • 1
  • 13
0
votes
1 answer

Changing to newsequentialid() on an existing table with 4 million records

My Question is almost the same like Changing newid() to newsequentialid() on an existing table if I change to newsequentialid() than the index should be more compact, correct? And what happens if the sequence is hitting exists ID's while inserting…
Roland
  • 398
  • 2
  • 10