- CREATE PROCEDURE [dbo].[uspCreateCopyTables]-- GOALTEST,GOAL
- -- parameters for the stored procedure here
- @toDatabase VARCHAR(100)
- ,@fromDatabase VARCHAR(100)
- AS
- BEGIN
- -- SET NOCOUNT ON added to prevent extra result sets from
- SET NOCOUNT ON;
- DECLARE @fullTableList VARCHAR(8000);
- DECLARE @idx INT;
- DECLARE @tableName VARCHAR(8000);
- DECLARE @SQLQuery NVARCHAR(500);
- DECLARE @ParameterDefinition NVARCHAR(100);
- -- this query gives the list of table name existing in the database.
- SELECT @fullTableList = ISNULL(@fullTableList + ',' + TABLE_NAME, TABLE_NAME)
- FROM INFORMATION_SCHEMA.TABLES
- WHERE TABLE_TYPE = 'BASE TABLE';
- SELECT @idx = 1
- /* this section splits the table name from comma separated string and copies that table name from
- one database to another database*/
- IF LEN(@fullTableList) > 1
- OR @fullTableList IS NOT NULL
- WHILE @idx != 0
- BEGIN
- SET @idx = CHARINDEX(',', @fullTableList)
- IF @idx != 0
- SET @tableName = LEFT(@fullTableList, @idx - 1)
- ELSE
- SET @tableName = @fullTableList
- IF (LEN(@tableName) > 0)
- SET @SQLQuery = 'SELECT * INTO [' + @toDatabase + '].[dbo].[' + @tableName + '] FROM [' + @fromDatabase + '].[dbo].[' + @tableName + ']'
- EXEC (@SQLQuery)
- SET @fullTableList = RIGHT(@fullTableList, LEN(@fullTableList) - @idx)
- IF LEN(@fullTableList) = 0
- BREAK
- END
- END
- GO
Tuesday, 6 December 2016
Copy All tables with Data in Another Database
Subscribe to:
Post Comments (Atom)
Upload valid file in C#
protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile) { try { Dictionary<string, byte[]>...
-
CREATE TAblE #temp ( T_Name VARCHAR(50), T_Times BIGINT ) INSERT INTO #temp(T_Name,T_Times) VALUES ('ASHISH',4) IN...
-
Setting Header Programatically You can also set the cache headers programmatically. This can be useful for generated content and allows m...
-
CREATE TABLE dbo.M_Bank ( ID INT IDENTITY NOT NULL, MB_NAME NVARCHAR (50), MB_SNAME NVARCHAR (20), MB_ADDUSER ...
sir G how many table to be create in database
ReplyDeleteHello Mukesh , Transfer all table (data also) to another database.
DeleteThis comment has been removed by the author.
ReplyDeleteOk Sir G this is great Job
ReplyDelete