BELOW SP WILL HELP YOU TO AUTO INCREMENT PRIMERY KEY IN RUN TIME
ALTER PROCEDURE AUTO_INCREMENT
@NAME VARCHAR(12) = NULL
AS
BEGIN
DECLARE @ID INT
SELECT @ID = MAX(ID) FROM TEST --(TABLENAME)
IF @ID IS NULL
INSERT INTO TEST VALUES(1,@NAME)
ELSE
INSERT INTO TEST VALUES(@ID +1 ,@NAME)
END
ALTER PROCEDURE AUTO_INCREMENT
@NAME VARCHAR(12) = NULL
AS
BEGIN
DECLARE @ID INT
SELECT @ID = MAX(ID) FROM TEST --(TABLENAME)
IF @ID IS NULL
INSERT INTO TEST VALUES(1,@NAME)
ELSE
INSERT INTO TEST VALUES(@ID +1 ,@NAME)
END
No comments:
Post a Comment