SQL Server: Tips and Tricks - 2 (SQL Server Tips and Tricks) by Priyanka Agarwal

SQL Server: Tips and Tricks - 2 (SQL Server Tips and Tricks) by Priyanka Agarwal

Author:Priyanka Agarwal [Agarwal, Priyanka]
Language: eng
Format: epub, azw3, pdf
Tags: SQL Server, meetcoogle, SQL, Tips, Tips and Tricks, Tricks
Publisher: MeetCoogle.com
Published: 2017-05-07T07:00:00+00:00


--DECLARE CURSOR

DECLARE CUR CURSOR

FOR

--Choose the DBs on which you would like to run the script

SELECT NAME

FROM sys.databases

WHERE database_id > 4

--OPEN CURSOR

OPEN CUR

--NEXT NEXT RECORD

FETCH NEXT

FROM CUR

INTO @DatabaseName

WHILE @@FETCH_STATUS = 0

BEGIN

DECLARE @DBName AS NVARCHAR(128);

SET @DBName = QUOTENAME(N'' + @DatabaseName + '');

--USE Dynamic SQL To Change DB name and run DDL statement to create Stored Procedure

EXEC (

N'USE ' + @DBName + N'; EXEC('''+@DDL+''');'

);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.