Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is column Identity or not?
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01549483
Message ID:
01549490
Vues:
23
>>>Hi,
>>>
>>>What would be the TSQL syntax to check if a column is set to be an Indenity column (Is Identity = Yes)? And if No, how to do set the column in Identity Yes in code?
>>>
>>>TIA
>>
>>Sys.columns has IsIdentity bit column, e.g.
>>
>>if exists (SELECT name, is_identity
>>FROM sys.columns
>>WHERE [object_id] = object_id('items')
>>and is_identity = 1)
>>
>>print 'Table Items has identity column'
>>
>>(If you know the column name, just check it using a similar script).
>>
>>If you want to make the column to be identity, you need to re-create the table (e.g. if you don't want to preserve current values, you can do
>>
>>select identity (int,1,1) as NewIdentityColumn, col1, col2, ... 
>>into myNewTable
>>from myTable
>
>I found an article by Pinal Dave where he shows a way to change the column into an Identity. Not very simple; requires creating temp table, etc. So I will do it in SSMS since I don't need to do it often.
>
>http://blog.sqlauthority.com/2009/05/03/sql-server-add-or-remove-identity-property-on-column/

Funny that I didn't check this article, but wrote the same script from the top of my head.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform