Today somebody asked me if we could add identity column to a table already created.
Well, it works.
To test it just copy and past the code bellow.
CREATE TABLE tablex
(
columny VARCHAR(01)
)
go
INSERT INTO tablex (columny) SELECT "a"
INSERT INTO tablex (columny) SELECT "b"
INSERT INTO tablex (columny) SELECT "c"
INSERT INTO tablex (columny) SELECT "d"
INSERT INTO tablex (columny) SELECT "e"
INSERT INTO tablex (columny) SELECT "f"
INSERT INTO tablex (columny) SELECT "g"
INSERT INTO tablex (columny) SELECT "h"
go
ALTER TABLE tablex ADD columnz NUMERIC (5,0) IDENTITY
go
SELECT * FROM tablex
go
DROP TABLE tablex
go
Result
----------------------------------
columny | columnz |
a | 1 |
b | 2 |
c | 3 |
d | 4 |
e | 5 |
f | 6 |
g | 7 |
h | 8 |
Nenhum comentário:
Postar um comentário