Nous suivrons les étapes ci-dessous.
- Ajouter une nouvelle colonne avec TestID au tableau existant
- Mettez à jour les enregistrements de l'ID (colonne d'activation de l'identité) à la colonne TestID (nouvellement ajouté).
- Supprimer l'identifiant (colonne d'activation de l'identité) du tableau
- Renommer la colonne nouvellement ajoutée ( TestID) en Id.
--Create Table with Identity Property CREATE TABLE dbo.Employee ( Id INT IDENTITY(1,1), Name VARCHAR(10)) GO
--Insert the record after creating Table with Identity Property on Id Column INSERT INTO dbo.Employee VALUES('Shahzad') GO
--Run to See the Data SELECT * FROM dbo.Employee
--Find out all the columns for all the tables on which Identity Property is enabled SELECT OBJECT_NAME(OBJECT_ID) AS TableName,name AS ColumnName FROM sys.columns
WHERE is_identity=1
/** Drop Identity ********/
--Add a new column with any name ALTER TABLE dbo.Employee
ADD TestId INT
--Update the Records in newly Added column , in our case TestID UPDATE dbo.Employee
SET TestId=Id
--Drop Identity Column ALTER TABLE dbo.Employee
DROP COLUMN Id
--Rename the newly Added Column to Identity Column you had at first. EXEC sp_rename 'dbo.Employee.TestId','Id','COLUMN' Démonstration vidéo :comment supprimer la propriété d'identité d'une colonne dans la table SQL Server