Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi - I have a table of id numbers that I wish to mask. My thought was to create a new column for this new id number and populate it with a unique sequential value - start at 1 and go as high as needed. My problem is that I cannot recall how to populate that column with a number...Can anyone please help?Thank you,JB
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2013-08-29 : 09:25:49
Use an identity column. See example below. I didn't follow what you meant by "mask" in this context
CREATE TABLE #tmp(x INT, y INT);INSERT INTO #tmp VALUES (1,2);INSERT INTO #tmp VALUES (7,9);INSERT INTO #tmp VALUES (8,9);-- this is the statement you want to useALTER TABLE #tmp ADD newIdcol INT NOT NULL IDENTITY(1,1);SELECT * FROM #tmp;DROP TABLE #tmp;
jcb267
Constraint Violating Yak Guru
291 Posts
Posted - 2013-08-29 : 09:35:20
Thanks, James! I am going to try that now......By mask I just mean to not desplay the real ID number. So if the ID is 100059832 I just want to put a 1 in my column, the next record would have a 2 in this column.....JB
quote:Originally posted by James K Use an identity column. See example below. I didn't follow what you meant by "mask" in this context
CREATE TABLE #tmp(x INT, y INT);INSERT INTO #tmp VALUES (1,2);INSERT INTO #tmp VALUES (7,9);INSERT INTO #tmp VALUES (8,9);-- this is the statement you want to useALTER TABLE #tmp ADD newIdcol INT NOT NULL IDENTITY(1,1);SELECT * FROM #tmp;DROP TABLE #tmp;
jcb267
Constraint Violating Yak Guru
291 Posts
Posted - 2013-08-29 : 09:38:47
That worked perfectly, James. That is exactly what I wanted to do! Thank you......