/*
   دوشنبه 07 آبان 1403 - 16:10:00 ب.ظ
   User: 
   Server: TAHERIAN
   Database: ATNDB
   Application: 
*/

Use ATNDBTest
Go
/*=============================================================================================================*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT

BEGIN TRANSACTION
GO

CREATE TABLE dbo.Tmp_License
	(
	Serial bigint NOT NULL IDENTITY (1, 1),
	Id uniqueidentifier NULL,
	LockSerial bigint NULL,
	ClientName varchar(MAX) NULL,
	MemoryId varchar(50) NULL,
	ActivationDate char(10) NULL,
	ActivationDate_Miladi datetime NULL,
	ExpirationDate char(10) NULL,
	ExpirationDate_Miladi datetime NULL,
	LicenseValidityDurationInMonth int NULL,
	LicenseValidityDurationInDays int NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_License SET (LOCK_ESCALATION = TABLE)
GO
SET IDENTITY_INSERT dbo.Tmp_License ON
GO
IF EXISTS(SELECT * FROM dbo.License)
	 EXEC('INSERT INTO dbo.Tmp_License (Serial, LockSerial, ClientName, MemoryId, ActivationDate, ExpirationDate, ExpirationDate_Miladi, LicenseValidityDurationInMonth)
		SELECT Serial, LockSerial, Name, MemoryId, ActivationDate, ExpirationDate, ExpirationDate_Miladi, ValidityDuration FROM dbo.License WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_License OFF
GO
DROP TABLE dbo.License
GO
EXECUTE sp_rename N'dbo.Tmp_License', N'License', 'OBJECT' 
GO
ALTER TABLE dbo.License ADD CONSTRAINT
	PK_License PRIMARY KEY CLUSTERED 
	(
	Serial
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO

-- پر کردن فیلد آی دی با مقدار اولیه
Update License Set Id = NEWID()
Go


COMMIT
