Some times developers will insert records using sql script.
Oracle database : you can get sequenceid by using NEXTVAL.
SQL Server : There is no function called NEXTVAL. Below are the steps you can follow :
Oracle database : you can get sequenceid by using NEXTVAL.
SQL Server : There is no function called NEXTVAL. Below are the steps you can follow :
SET NOCOUNT ON;
--Declare integer variable
declare @seqid int
--Update MAXSEQUENCE table by increasing MAXRESERVED value+1.
update [maxsequence] set [maxreserved] = [maxreserved]+1 where [tbname] = 'MAXATTRIBUTE' and [name] = 'MAXATTRIBUTEID'
GO
--Get MAXRESERVED from MAXSEQUENCE table and Set to integer variable (in this case @seqid)
SET @seqid = (select maxreserved from maxsequence where [tbname] = 'MAXATTRIBUTE' and [name] = 'MAXATTRIBUTEID')
--When inserting use @seqid at your sequenceid value. Below case, MAXATTRIBUTEID value replaced with @seqid.
INSERT INTO MAXATTRIBUTE
(MAXATTRIBUTEID,OBJECTNAME,ATTRIBUTENAME,.................) VALUES
( @seqid,<OBJECTNAME>,<ATTRIBUTENAME>,.........)
GO
For multiple inserts, add 'update step' and 'set sequenceid in variable step' before every insert :
--Update MAXSEQUENCE table by increasing MAXRESERVED value+1.
update [maxsequence] set [maxreserved] = [maxreserved]+1 where [tbname] = '<OBJECTNAME>' and [name] = '<OBJECTSEQUENCEIDNAME>'
GO
--Get MAXRESERVED from MAXSEQUENCE table and Set to integer variable (in this case @seqid)
SET @seqid = (select maxreserved from maxsequence where [tbname] = '<OBJECTNAME>' and [name] = '<OBJECTSEQUENCEID NAME>')
INSERT INTO <OBJECTNAME>
(OBJECTSEQID,,.................) VALUES
( @seqid,,.........)
GO
Hope it will be useful. :)
2 comments:
Doesnt this require the server to be shutdown while executing the scripts and restart it back once its done?
Recommended way is, any maximo backend changes need server restart or just turn on admin mode and off to get changes affective.
Post a Comment