Coping Database to another

More
2 years 11 months ago #22794 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 

Please Log in or Create an account to join the conversation.

More
2 years 11 months ago #22796 by Peter.Jonson
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
 

Peter Jonson
ETL Developer
The following user(s) said Thank You: hanisultan

Please Log in or Create an account to join the conversation.

More
2 years 11 months ago #22797 by hanisultan
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.

Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Google
Accept
Decline
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Google Analytics
Accept
Decline
Functional
Tools used to give you more features when navigating on the website, this can include social sharing.
Advertisement
If you accept, the ads on the page will be adapted to your preferences.
Google Ad
Accept
Decline
Save