DBCC CHECKIDENT can reset the identity value of the table. For example, YourTable has 10 rows with 10 as the last identity. If we want the next record to have the identity of 25, we need to run the following TSQL script in Query Analyzer.
DBCC CHECKIDENT (yourtable, reseed, 24)
If yourtable has to start with an identity of 1, the table should be reseeded with an identity of 0. If the identity seed is set below the values that are currently in the table, it will violate the uniqueness constraint and will generate error.
Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts
Tuesday, 20 September 2011
How to search Stored Procedures in SQL Server
The following stored procedure will list all stored procedure names whose text contains the parameter search string:
CREATE PROCEDURE Find_Text_In_SP
@StringToSearch varchar(100)
AS
SET @StringToSearch = '%' +@StringToSearch + '%'
SELECT Distinct SO.Name
FROM sysobjects SO (NOLOCK)
INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
AND SO.Type = 'P'
AND SC.Text LIKE @stringtosearch
ORDER BY SO.Name
GO
The following stored procedure list all stored procedure names whose text contains the parameter search string:
CREATE PROCEDURE Find_SPName_With_Text
@StringToSearch varchar(100)
AS
SET @StringToSearch = '%' + @StringToSearch + '%'
SELECT DISTINCT SO.NAME
FROM SYSOBJECTS SO (NOLOCK)
WHERE SO.TYPE = 'P'
AND SO.NAME LIKE @StringToSearch
ORDER BY SO.Name
GO
CREATE PROCEDURE Find_Text_In_SP
@StringToSearch varchar(100)
AS
SET @StringToSearch = '%' +@StringToSearch + '%'
SELECT Distinct SO.Name
FROM sysobjects SO (NOLOCK)
INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
AND SO.Type = 'P'
AND SC.Text LIKE @stringtosearch
ORDER BY SO.Name
GO
The following stored procedure list all stored procedure names whose text contains the parameter search string:
CREATE PROCEDURE Find_SPName_With_Text
@StringToSearch varchar(100)
AS
SET @StringToSearch = '%' + @StringToSearch + '%'
SELECT DISTINCT SO.NAME
FROM SYSOBJECTS SO (NOLOCK)
WHERE SO.TYPE = 'P'
AND SO.NAME LIKE @StringToSearch
ORDER BY SO.Name
GO
Subscribe to:
Posts (Atom)