Questions tagged [tsql-sequence]
8 questions
                    
                    7
                    
            votes
                
                3 answers
            
        SQL Server get multiple next values for sequence
In SQL Server you can select the next value from a sequence like this:
select next value for MY_SEQ
If you don't suppress the table from which to select, for every row the next value will be outputted:
select next value for MY_SEQ 
from…
         
    
    
        MetaColon
        
- 2,895
- 3
- 16
- 38
                    6
                    
            votes
                
                1 answer
            
        Is it possible to concatenate a string to a sequence value and use as a column default value?
I'd like to set a default value for a column from a sequence like what is done here, but also prepend a value in front of the sequence so the value saved in the table looks like P123. Is that possible?
         
    
    
        adam0101
        
- 29,096
- 21
- 96
- 174
                    3
                    
            votes
                
                2 answers
            
        Insert using a Sequence as generator for a Primary Key value in Entity Framework
I have a sequence that looks like this:
CREATE SEQUENCE dbo.NextWidgetId
 AS [bigint]
 START WITH 100
 INCREMENT BY 2
 NO CACHE 
GO
And a table that looks like this:
CREATE TABLE [dbo].[Widget_Sequenced]
(
    [WidgetId] [int] NOT NULL DEFAULT(NEXT…
         
    
    
        Vaccano
        
- 78,325
- 149
- 468
- 850
                    1
                    
            vote
                
                1 answer
            
        Getting the sequenced id of a row to be the foreign key of a row in another table in one query
The database is SQL Server 2012.
I'm supposed to add a bunch of rows on two tables from an Excel file.
I have the table Customers:
id | firstname | lastname
1  | John      | Doe
etc.
The Customers table has a sequence customers_seq to use for ids…
         
    
    
        Steve Waters
        
- 3,348
- 9
- 54
- 94
                    0
                    
            votes
                
                1 answer
            
        Concatinated default value from sequence on a non primary key column
I'm trying to create a table with some kind of generated default business-key. The value may be overridden, but may not be null.
For the column I want to generate a string like "_": for example user_1, user_2,... the sequence…  
         
    
    
        Matthias Burger
        
- 5,549
- 7
- 49
- 94
                    0
                    
            votes
                
                1 answer
            
        Set a new, specific value for SQL sequence
I have created a sequence to my database as follows:
DECLARE @max int;
SELECT @max = MAX(customernumber)+1
FROM organisation
exec('CREATE SEQUENCE organisation_customernumber_sequence
    START WITH ' + @max +
'   INCREMENT BY 1;')
It works and…
         
    
    
        Steve Waters
        
- 3,348
- 9
- 54
- 94
                    -2
                    
            votes
                
                1 answer
            
        Is there any way to restrict the data inserted into table if it is already present?
I have an sp which when triggered, data will be inserted into the data table. If the data being inserted is already present in the table, I don't want the data to be inserted into the table. is there anyway i could use a logic to restrict the data…
         
    
    
        sam
        
- 81
- 6
                    -2
                    
            votes
                
                1 answer
            
        How to view the definition of a sequence?
I want to retrieve the definition of a sequence through a query. I have already done this with triggers:
USE dbName 
SELECT c.text FROM sys.syscomments c 
INNER JOIN (
    SELECT object_id FROM SYS.triggers WHERE name = 'triggerName'
) t ON c.id =…
        
    