/*************************************************************** */
-- GOOGLE Jr.. --
/*************************************************************** *//*
Description :: Script is mend to search a string literal given and give the
dependencies in the database
Author :: R.V.D.Varma
Scripted Date :: 20 May 2010 Wed
Inputs :: iString_Literal ----------> Literal which is to be searched
iObjects_type ----------> Type of Objects in which String Literal is to be
searched as specified
1..... Stored Procedures / Functions
2..... Views
3..... Tables/Columns
4..... Object Not Known
*/
SET NOCOUNT ON
DECLARE @iString_Literal NVARCHAR(1000)
DECLARE @iObjects_type INT
DECLARE @iSearch_Objects NVARCHAR(1000)
DECLARE @vObject_type NVARCHAR(500)
DECLARE @vObject_Name NVARCHAR(1000)
DECLARE @iResTable TABLE (Attribute_Type NVARCHAR(200),
Attribute_Description NVARCHAR(MAX))
DECLARE @vObjectInfo TABLE([ObjID] INT IDENTITY(1000,1),
Object_Text NVARCHAR(MAX))
SET @iString_Literal = 'TWITTER_COST_DATA'
SET @iObjects_type = 4
IF @iObjects_type = 1
BEGIN
DECLARE tc CURSOR FOR SELECT TYPE_DESC,NAME
FROM sys.OBJECTS
WHERE TYPE_DESC IN ('SQL_STORED_PROCEDURE','SQL_TABLE_VALUED_FUNCTION','SQL_SCALAR_FUNCTION')
OPEN tc
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @vObjectInfo
EXEC sp_helptext @vObject_Name
IF EXISTS(SELECT * FROM @vObjectInfo WHERE CHARINDEX(@iString_Literal,Object_Text,1)>0 )
INSERT INTO @iResTable (Attribute_Type,Attribute_Description)
VALUES (@vObject_type,@vObject_Name)
DELETE FROM @vObjectInfo
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
END
CLOSE tc
DEALLOCATE tc
END
ELSE IF @iObjects_type = 2
BEGIN
DECLARE tc CURSOR FOR SELECT TYPE_DESC,NAME FROM sys.VIEWS
OPEN tc
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @vObjectInfo
EXEC sp_helptext @vObject_Name
IF EXISTS(SELECT * FROM @vObjectInfo WHERE CHARINDEX(@iString_Literal,Object_Text,1)>0 )
INSERT INTO @iResTable (Attribute_Type,Attribute_Description)
VALUES (@vObject_type,@vObject_Name)
DELETE FROM @vObjectInfo
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
END
CLOSE tc
DEALLOCATE tc
END
ELSE IF @iObjects_type = 3
BEGIN
INSERT INTO @iResTable
SELECT DISTINCT 'USER_TABLE',OBJECT_NAME(OBJECT_ID) FROM sys.columns
WHERE NAME LIKE @iString_Literal
END
ELSE IF @iObjects_type = 4
BEGIN
DECLARE tc CURSOR FOR SELECT TYPE_DESC,NAME FROM sys.OBJECTS WHERE TYPE_DESC IN ('SQL_STORED_PROCEDURE','VIEW','SQL_TABLE_VALUED_FUNCTION','SQL_SCALAR_FUNCTION')
OPEN tc
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @vObjectInfo
EXEC sp_helptext @vObject_Name
IF EXISTS(SELECT * FROM @vObjectInfo WHERE CHARINDEX(@iString_Literal,Object_Text,1)>0 )
INSERT INTO @iResTable (Attribute_Type,Attribute_Description)
VALUES (@vObject_type,@vObject_Name)
DELETE FROM @vObjectInfo
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
END
CLOSE tc
DEALLOCATE tc
INSERT INTO @iResTable
SELECT DISTINCT 'USER_TABLE',OBJECT_NAME(OBJECT_ID) FROM sys.columns
WHERE NAME LIKE @iString_Literal
END
SELECT * FROM @iResTable
SET NOCOUNT OFF
-- GOOGLE Jr.. --
/*************************************************************** *//*
Description :: Script is mend to search a string literal given and give the
dependencies in the database
Author :: R.V.D.Varma
Scripted Date :: 20 May 2010 Wed
Inputs :: iString_Literal ----------> Literal which is to be searched
iObjects_type ----------> Type of Objects in which String Literal is to be
searched as specified
1..... Stored Procedures / Functions
2..... Views
3..... Tables/Columns
4..... Object Not Known
*/
SET NOCOUNT ON
DECLARE @iString_Literal NVARCHAR(1000)
DECLARE @iObjects_type INT
DECLARE @iSearch_Objects NVARCHAR(1000)
DECLARE @vObject_type NVARCHAR(500)
DECLARE @vObject_Name NVARCHAR(1000)
DECLARE @iResTable TABLE (Attribute_Type NVARCHAR(200),
Attribute_Description NVARCHAR(MAX))
DECLARE @vObjectInfo TABLE([ObjID] INT IDENTITY(1000,1),
Object_Text NVARCHAR(MAX))
SET @iString_Literal = 'TWITTER_COST_DATA'
SET @iObjects_type = 4
IF @iObjects_type = 1
BEGIN
DECLARE tc CURSOR FOR SELECT TYPE_DESC,NAME
FROM sys.OBJECTS
WHERE TYPE_DESC IN ('SQL_STORED_PROCEDURE','SQL_TABLE_VALUED_FUNCTION','SQL_SCALAR_FUNCTION')
OPEN tc
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @vObjectInfo
EXEC sp_helptext @vObject_Name
IF EXISTS(SELECT * FROM @vObjectInfo WHERE CHARINDEX(@iString_Literal,Object_Text,1)>0 )
INSERT INTO @iResTable (Attribute_Type,Attribute_Description)
VALUES (@vObject_type,@vObject_Name)
DELETE FROM @vObjectInfo
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
END
CLOSE tc
DEALLOCATE tc
END
ELSE IF @iObjects_type = 2
BEGIN
DECLARE tc CURSOR FOR SELECT TYPE_DESC,NAME FROM sys.VIEWS
OPEN tc
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @vObjectInfo
EXEC sp_helptext @vObject_Name
IF EXISTS(SELECT * FROM @vObjectInfo WHERE CHARINDEX(@iString_Literal,Object_Text,1)>0 )
INSERT INTO @iResTable (Attribute_Type,Attribute_Description)
VALUES (@vObject_type,@vObject_Name)
DELETE FROM @vObjectInfo
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
END
CLOSE tc
DEALLOCATE tc
END
ELSE IF @iObjects_type = 3
BEGIN
INSERT INTO @iResTable
SELECT DISTINCT 'USER_TABLE',OBJECT_NAME(OBJECT_ID) FROM sys.columns
WHERE NAME LIKE @iString_Literal
END
ELSE IF @iObjects_type = 4
BEGIN
DECLARE tc CURSOR FOR SELECT TYPE_DESC,NAME FROM sys.OBJECTS WHERE TYPE_DESC IN ('SQL_STORED_PROCEDURE','VIEW','SQL_TABLE_VALUED_FUNCTION','SQL_SCALAR_FUNCTION')
OPEN tc
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @vObjectInfo
EXEC sp_helptext @vObject_Name
IF EXISTS(SELECT * FROM @vObjectInfo WHERE CHARINDEX(@iString_Literal,Object_Text,1)>0 )
INSERT INTO @iResTable (Attribute_Type,Attribute_Description)
VALUES (@vObject_type,@vObject_Name)
DELETE FROM @vObjectInfo
FETCH NEXT FROM tc INTO @vObject_type,@vObject_Name
END
CLOSE tc
DEALLOCATE tc
INSERT INTO @iResTable
SELECT DISTINCT 'USER_TABLE',OBJECT_NAME(OBJECT_ID) FROM sys.columns
WHERE NAME LIKE @iString_Literal
END
SELECT * FROM @iResTable
SET NOCOUNT OFF
No comments:
Post a Comment