- Posts: 725
- Thank you received: 15
Coping Database to another
- hanisultan
-
Topic Author
- Offline
- Platinum Member
-
Less
More
1 month 2 weeks ago #22794
by hanisultan
Coping Database to another was created by hanisultan
Hello,
We have an old database (SQL 2008 R) with millions of records and we decided to split it into multiple databases with the same exact schema. We have over 6k clients so we will be moving few clients at the time to different databses. The problem is we have the data in over 1500 tables in the source database to move to same tables in the target database. Can we do this in the ATEL without creating 1500 transformation (read and write) because that would be too much. I thought I ask you and see if you have a method in AETL where we can use and accomplish this. Please let me know if you have any questions or need additional information. Thank you
We have an old database (SQL 2008 R) with millions of records and we decided to split it into multiple databases with the same exact schema. We have over 6k clients so we will be moving few clients at the time to different databses. The problem is we have the data in over 1500 tables in the source database to move to same tables in the target database. Can we do this in the ATEL without creating 1500 transformation (read and write) because that would be too much. I thought I ask you and see if you have a method in AETL where we can use and accomplish this. Please let me know if you have any questions or need additional information. Thank you
Please Log in or Create an account to join the conversation.
- Peter.Jonson
-
- Offline
- Platinum Member
-
1 month 2 weeks ago #22796
by Peter.Jonson
Peter Jonson
ETL Developer
Replied by Peter.Jonson on topic Coping Database to another
I think using SQL script is a much simplier option in your case
I have created an example for you.
SET NOCOUNT ON
DECLARE @TARGET_DATABASE VARCHAR(50)
DECLARE @TABLE_CATALOG VARCHAR(255)
DECLARE @TABLE_SCHEMA VARCHAR(255)
DECLARE @TABLE_NAME VARCHAR(255)
DECLARE @SQL VARCHAR(1000)
SET @TARGET_DATABASE ='CLONE'
DECLARE t_cursor CURSOR FOR
SELECT TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE'
OPEN t_cursor
FETCH NEXT FROM t_cursor INTO @TABLE_CATALOG,@TABLE_SCHEMA,@TABLE_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL= ' select * into .. from ..'
print @SQL
EXEC(@SQL)
FETCH NEXT FROM t_cursor INTO @TABLE_CATALOG,@TABLE_SCHEMA,@TABLE_NAME
END
CLOSE t_cursor
DEALLOCATE t_cursor
You can tweak it further by adding a where statement and using a custom list of tables
I hope you will find it useful
I have created an example for you.
SET NOCOUNT ON
DECLARE @TARGET_DATABASE VARCHAR(50)
DECLARE @TABLE_CATALOG VARCHAR(255)
DECLARE @TABLE_SCHEMA VARCHAR(255)
DECLARE @TABLE_NAME VARCHAR(255)
DECLARE @SQL VARCHAR(1000)
SET @TARGET_DATABASE ='CLONE'
DECLARE t_cursor CURSOR FOR
SELECT TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE'
OPEN t_cursor
FETCH NEXT FROM t_cursor INTO @TABLE_CATALOG,@TABLE_SCHEMA,@TABLE_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL= ' select * into .. from ..'
print @SQL
EXEC(@SQL)
FETCH NEXT FROM t_cursor INTO @TABLE_CATALOG,@TABLE_SCHEMA,@TABLE_NAME
END
CLOSE t_cursor
DEALLOCATE t_cursor
You can tweak it further by adding a where statement and using a custom list of tables
I hope you will find it useful
Peter Jonson
ETL Developer
The following user(s) said Thank You: hanisultan
Please Log in or Create an account to join the conversation.
- hanisultan
-
Topic Author
- Offline
- Platinum Member
-
Less
More
- Posts: 725
- Thank you received: 15
1 month 2 weeks ago #22797
by hanisultan
Replied by hanisultan on topic Coping Database to another
That is what we are currently doing, store procedures and functions, something exactly like your idea. Thank you
The following user(s) said Thank You: Peter.Jonson
Please Log in or Create an account to join the conversation.