(Reprint)Simulating the sequence of Oracle in Sql Server by leveraging the identity
2009-07-22 15:41
489 查看
Create proc sp_CreateSequence
(@sequenceName varchar(40),
@startVal int =1,
@increment int =1)
AS
BEGIN
declare @sqlStmt varchar(100)
set nocount on
set @sqlStmt = 'Create Table ' + @sequenceName +
' ( sqVal int IDENTITY (' + convert (varchar(10),@startVal) +
',' + convert (varchar(10),@increment) + '))'
exec (@sqlStmt)
set nocount off
end
go
------------------------------------
Create function dbo.CurrVal (@sequenceName varchar(40))
returns int
as
begin
return (IDENT_CURRENT(@sequenceName))
end
go
-------------------------------------
Create proc NextVal (@sequenceName varchar(40) ,@nextVal int output)
as
begin
declare @sqlStmt varchar(100)
set nocount on
set @sqlStmt = 'insert ' + @sequenceName + ' DEFAULT VALUES '
exec (@sqlStmt)
SET @nextVal=IDENT_CURRENT(@sequenceName)
set nocount off
end
go
(@sequenceName varchar(40),
@startVal int =1,
@increment int =1)
AS
BEGIN
declare @sqlStmt varchar(100)
set nocount on
set @sqlStmt = 'Create Table ' + @sequenceName +
' ( sqVal int IDENTITY (' + convert (varchar(10),@startVal) +
',' + convert (varchar(10),@increment) + '))'
exec (@sqlStmt)
set nocount off
end
go
------------------------------------
Create function dbo.CurrVal (@sequenceName varchar(40))
returns int
as
begin
return (IDENT_CURRENT(@sequenceName))
end
go
-------------------------------------
Create proc NextVal (@sequenceName varchar(40) ,@nextVal int output)
as
begin
declare @sqlStmt varchar(100)
set nocount on
set @sqlStmt = 'insert ' + @sequenceName + ' DEFAULT VALUES '
exec (@sqlStmt)
SET @nextVal=IDENT_CURRENT(@sequenceName)
set nocount off
end
go
相关文章推荐
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- In Oracle 11g, how to change the order of the results of a sql without “order by”?(转)
- Error: The version of SQL Server in use does not support datatype 'datetime2
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- ERROR: The version of SQL Server in use does not support datatype 'datetime2'.
- Description of the SQL Server Agent jobs in BizTalk Server
- Display the size of all tables in Sql Server 2005
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- ADO.NET Entity Framework: The version of SQL Server in use does not support datatype 'datetime2'
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- SQL Interview Preparation (in the context of MS SQL Server)
- 转载:Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005
- Sample script that displays all of the users in a given SQL Server DB
- In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.
- sql express 2008 - Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instan
- Error: The version of SQL Server in use does not support datatype 'datetime2'
- The Maximum Number of Bytes Per Row in SQL Server 2000 -- 8060.
- sql server query to get the list of column name in a table
- 海洋工作室——网站建设专家:The version of SQL Server in use does not support datatype datetime2 and the Entity Framework.