Sunday, November 10, 2013
Create Dynamic Get storedprocedure for All the tables
--- This can be customized as per the Requirments ------
-- This Script used to create the Get(select all columns) Procedure for all the database tables.
----------------------------------------------------------------------------------------------------
SELECT
' CREATE PROCEDURE [USP_GET_' + TBL.NAME + ']' +
+ ' AS
BEGIN
SELECT ' + LEFT(COLUMNS,LEN(COLUMNS)- 1) + CHAR(10) +
' , GETDATE() AS INSERTED_DATE
FROM ' + TBL.NAME +
'
END
GO
'
FROM SYS.TABLES AS TBL
CROSS APPLY
(
SELECT UPPER('[' + COL.NAME + ']') + ' ,'
FROM SYS.COLUMNS AS COL
WHERE COL.OBJECT_ID = TBL.OBJECT_ID
FOR XML PATH('')) AS TABLE_COLUMN(COLUMNS)
ORDER BY TBL.NAME ASC
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment