Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL-create Autoincrement manually

$
0
0

Hi All,

I have a requirement where I have a table with Two Column.
And I want to make 'COLA' as Identity\Autoincrement (to start with next value) When Ever new records comes in 'COLB'
BELOW IS SAMPLE TABLE

CREATE TABLE EMP(COLA INT,COLB VARCHAR(10))
INSERT INTO EMP 
SELECT 1,'A' UNION ALL
SELECT 2,'B' UNION ALL
SELECT 3,'C' UNION ALL
SELECT 4,'D' 

/* I LOAD DATA IN ABOVE  TABLE USING  SSIS-2012 */
/* I HAVE ANOTHER TABLE WHICH HOLDS THE TABLE NAME AND MAX VALUE OF PRIMARYKEY COLUMN('COLA IN MY CASE')*/
CREATE TABLE MAX_TABLE (TABLE_NAME VARCHAR(20),MAX_RECORDS INT)
INSERT INTO MAX_TABLE
SELECT 'EMP',4

/*
COLA IN TABLE 'EMP' IS PRIMARYKEY BUT I CANNOT MAKE THAT AS AUTOINCREMENT\IDENTITY IN SQL DIRECTLY. 
REQUIREMENT :: WHEN I LOAD DATA IN EMP TABLE NEXT TIME, NEW VALUE OF COLA SHOULD START FROM 5 AND SSOO ON I.E */

I am working on SQL-2012


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>