newid

Randomize part of select from CTE output

ぃ、小莉子 提交于 2020-08-09 09:13:07
问题 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 reached and if the next AmountPersons was too high to be invited check the AmountPersons of the next row to see if it would fit? Please check the initial question via the link above to get the full picture. New situation : First we have 20 available

i am migrtaing database from sql server 2008 to teradata

我的未来我决定 提交于 2019-12-25 13:53:11
问题 I am migrating a database from Sql Server 2008 to Teradata and I am facing a problem: In Sql Server in the ddl of a table column is defined as follows: [rowguid] uniqueidentifier ROWGUIDCOL NOT NULL CONSTRAINT [DF_Address_rowguid] DEFAULT (NEWID()) This column uses newid() function to generate and insert random varchar value in the column [rowguid] if the user doesnt provide any input. There is no similar function in Teradata to generate this value. What can be used instead of of NEWID()

SQL Server Copy Random data from one table to another

早过忘川 提交于 2019-12-25 12:54:13
问题 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), data VARCHAR(MAX) ); CREATE TABLE nonsense ( id INT PRIMARY KEY, data VARCHAR(MAX) ); The stuff table is already populated with details , but data is NULL for now. I would like to copy data from one row of nonsense at random into each row of stuff . Since

Changing newid() to newsequentialid() on an existing table

試著忘記壹切 提交于 2019-12-20 10:56:18
问题 At the moment we have a number of tables that are using newid() on the primary key. This is causing large amounts of fragmentation. So I would like to change the column to use newsequentialid() instead. I imagine that the existing data will remain quite fragmented but the new data will be less fragmented. This would imply that I should perhaps wait some time before changing the PK index from non-clustered to clustered. My question is, does anyone have experience doing this? Is there anything

Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

不想你离开。 提交于 2019-12-19 17:35:20
问题 The OUTPUT clause is compatible with SQL Server 2005 but not SQL Server 2000. How do I convert this command to work in SQL Server 2000? CREATE TABLE sample ( ID uniqueidentifier NOT NULL DEFAULT newid(), Title varchar(30) NOT NULL ) INSERT INTO sample (Title) OUTPUT INSERTED.ID VALUES ('Test1') I need the command to retrieve the ID since the INSERT command needs to be called from a stored procedure. Thanks for any help! 回答1: DECLARE @uid uniqueidentifier SET @uid = newid() INSERT INTO sample

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

纵然是瞬间 提交于 2019-12-19 10:25:06
问题 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 ( @SampleLimit ). To achieve the desired result, I start by creating a CTE (temp table) with: The top(@SampleLimit) applied group by UserId (as the UserID appears multiple times) order by NEWID() to put the results in a random order SQL: ; with cte_temp as

Where is the official documentation for T-SQL's “ORDER BY RAND()” and “ORDER BY NEWID()”?

北慕城南 提交于 2019-12-13 11:03:52
问题 I'm looking for the official T-SQL documentation for "ORDER BY RAND()" and "ORDER BY NEWID()". There are numerous articles describing them, so they must be documented somewhere. I'm looking for a link to an official SQL Server documentation page like this: http://technet.microsoft.com/en-us/library/ms188385.aspx CLARIFICATION: What I'm looking for is the documentation for "order_by_expression" that explains the difference in behavior between a nonnegative integer constant, a function that

Inconsistent results with NEWID() and PERSISTED computed column

China☆狼群 提交于 2019-12-12 10:45:12
问题 I am getting odd results when using NEWID() in combination with a persistent computed column. Am I using some function wrong? Not using persisted when creating the column, and therefore calculating values when selecting them, will return correct values. Updating the column (col1) will also return correct values. DECLARE @test TABLE ( Col1 INT, Contains2 AS CASE WHEN 2 IN (Col1) THEN 1 ELSE 0 END PERSISTED) INSERT INTO @test (Col1) VALUES (ABS(CHECKSUM(NEWID()) % 5)), (ABS(CHECKSUM(NEWID()) %

SQL Server : does NEWID() always gives a unique ID?

荒凉一梦 提交于 2019-12-03 19:47:38
问题 Does the NEWID() function never give me the same ID as it already did? Let's say I select a NEWID() and it returns '1' (just as an example). Will it never return '1' again? Is it impossible? 回答1: Both NEWID() and NEWSEQUENTIALID() give globally unique values of type uniqueidentifier. NEWID() involves random activity, thus the next value is unpredictable, and it's slower to execute. NEWSEQUENTIALID() doesn't involve random activity, thus the next generated value can be predicted (not easily!)

Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

白昼怎懂夜的黑 提交于 2019-12-01 17:02:47
The OUTPUT clause is compatible with SQL Server 2005 but not SQL Server 2000. How do I convert this command to work in SQL Server 2000? CREATE TABLE sample ( ID uniqueidentifier NOT NULL DEFAULT newid(), Title varchar(30) NOT NULL ) INSERT INTO sample (Title) OUTPUT INSERTED.ID VALUES ('Test1') I need the command to retrieve the ID since the INSERT command needs to be called from a stored procedure. Thanks for any help! DECLARE @uid uniqueidentifier SET @uid = newid() INSERT INTO sample (ID, Title) VALUES (@uid,'Test1') SELECT @uid AS ID 来源: https://stackoverflow.com/questions/5863168/get-last