GENERATE UNIQUE IDENTIFIRE BASE ON GUID
علی ذوالفقار
1400/09/28 20:16:28 (589)
sp :
ALTER PROCEDURE [dbo].[SP_UNO]
@GUID AS NVARCHAR(255)
AS
BEGIN
-- routine body goes here, e.g.
-- SELECT 'Navicat for SQL Server'
DECLARE @UNO AS NVARCHAR(255)
SELECT @UNO = LEFT(NEWID() , 8)
IF NOT EXISTS (SELECT UNO FROM TBL_CERT WHERE UNO = @UNO)
BEGIN
UPDATE TBL_CERT SET UNO = @UNO WHERE GUID = @GUID
END
ELSE
BEGIN
EXEC DBO.SP_UNO @GUID
END
END
TRIGGER AFTER INSERT :
BEGIN
-- Type the SQL Here.
DECLARE @GUID NVARCHAR(255)
SELECT @GUID = GUID FROM INSERTED
EXEC DBO.SP_UNO @GUID
END