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
3
votes
2 answers

newid() with Entity Framework 6 Code First

I want to set the default value of my primary key of a table in SQL database with newid() via Entity Framework 6 Code First. I know how this is done via code and also found some approaches on stackoverflow, like How to set NewId() for GUID in entity…
3
votes
1 answer

How to select halves of multiple groups in a single SQL Server query?

I have a SQL Server 2008 table with records in multiple groups comprised of composite group IDs (i.e. GroupID = Col1 + Col2 + Col3) and need to randomly split each of those groups into control groups, reassigning the value for Col1 only, such that…
David
  • 142
  • 1
  • 8
3
votes
2 answers

NewID() - Is there a high chance of exposing the previous/next GUIDs

I know GUIDs are theoritically unique with a very low chance of collision. However, if I understand properly some of that uniqueness is available because it's seeding from information on the computer used to generate it depending on the algorithm…
jfrobishow
  • 2,897
  • 2
  • 27
  • 42
2
votes
2 answers

CHECKSUM(NewId()) executes multiple times per row

When reviewing code I came across something odd, someone had read that you can use ABS(CHECKSUM(NewId())) % N to get you random numbers from 0 to N-1 (as RAND() doesn't occur per-row), but I suspect they didn't really test their code (simplified…
Seph
  • 8,472
  • 10
  • 63
  • 94
2
votes
1 answer

Optimize Random T-SQL

First: What do you think about the way I random? Is this way too poor?. I have a table TABLE_A: id | name | state ---------------------|---------- 1703248 | blablabla | 1 ... | blablabla | 0 7873415 | blablabla | 1 7926033 …
jlrvpuma
  • 271
  • 2
  • 9
2
votes
2 answers

psycopg2.ProgrammingError: can't adapt type 'NewId' in odoo 14

Getting above error creating new record in one2many field. code is below: def _compute_timesheet_hour(self): for val in self: self._cr.execute('''SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line where…
Pawan Kumar Sharma
  • 1,168
  • 8
  • 30
2
votes
2 answers

Any issues about using NEWID() for API key?

I am working on a small piece that will generate an API Key using SQL Sever's NEWID(). The key will be used to access certain parts of our web app and will be passed in through a URL. The key is generated when a new API consumer is created (in a…
MK_Dev
  • 3,291
  • 5
  • 27
  • 45
2
votes
1 answer

Using NEWID() with CTE to produce random subset of rows produces odd results

I'm writing some SQL in a stored procedure to reduce a dataset to a limited random number of rows that I want to report on. The report starts with a Group of Users and a filter is applied to specify the total number of random rows required…
Tanner
  • 22,205
  • 9
  • 65
  • 83
2
votes
1 answer

TSQL convert newid to decimal(38,0)

I want to cast or convert newid() output to decimal (with minimum space required) So far I did this : SELECT CAST( '0x'+REPLACE(CAST(NEWID() AS VARCHAR(50)), '-', '' ) AS DECIMAL(38,0) ) But I'm getting this error : Error converting data type…
Spongebob Comrade
  • 1,495
  • 2
  • 17
  • 32
1
vote
1 answer

Is possible NEWSEQUENTIALID() repeat with NewId()?

I used to have a table with about 1000W data, the primary key column's datatype is uniqueidentifier, and the default value is Newid(). Now there is a performance problem, and I want to change the default value to NEWSEQUENTIALID(). Is it possible…
L.Tim
  • 61
  • 3
1
vote
1 answer

Randomize part of select from CTE output

In this question @GordonLinoff provided a solution (recursive common table expression) to my initial question. This is a follow-up question. Initial question: How can I loop through registrations until a certain amount (sum) of AmountPersons was…
Dieter
  • 401
  • 1
  • 9
  • 31
1
vote
0 answers

Should I use NEWID() as my primary key in the table? What datatype I should use for that column?

I have read few posts and articles about NEWID() in MS SQL. Before I decide should I use this method or not I would like to get some information. My Single Page App has few tables. One of the tables should store unique key for each customer. I'm…
espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
1
vote
1 answer

ORDER BY NEWID() AND UNION using MS SQL

I'm trying to execute following SQL query over MS. SQL, objective is to select random records from both queries and union them together but its generating the error at ORDER BY NEWID() select 2 random questions when subject_id=1 union select 3…
QSS
  • 41
  • 1
  • 8
1
vote
0 answers

ABS ( CHECKSUM ( NEWID () ) ) % 4 generates unexpected values

the following transact-sql code works properly. it fills up the table with four integers ( 0, 1, 2, 3 ) as expected. CREATE TABLE [TBL_INTEGER] ( [ID] INTEGER IDENTITY ( 1, 1 ) PRIMARY KEY, [NUMBER] INTEGER NOT NULL ) DECLARE @MAX…
1
vote
1 answer

SQL - Returning random rows from a temporary table using NEWID()

I am trying to insert data from a source table in to a temporary table using the NEWID() function so that I get a (fairly) random selection of lines from my source table. Looking at the below code, I insert the data I need into the temp table #x and…
Johnathan
  • 879
  • 3
  • 12
  • 22