Database backup

  • Hi

    I have a db backup requirement. As shown in the attached image current system is as follows:

    1. There are three source databases such as DB001, DB002 and DB003. Each DB having one table as dbo.EMP and same table schema.

    2. Emp table consists of EmpID (PK) and EmpName.

    3. One backup database i.e, DBbackup

    I need as follows:

    1. Looping through all DB: "SELECT NAME FROM sys.sysdatabases WHERE NAME LIKE ''DB00%''"

    2. Check if table dbo.EMP exist in each DB.

    3. If exist then check table "001" exist in DB "DBbackup". >> "SELECT OBJECT_ID('DBbackup.dbo.001','U') AS Check " . This query will return NULL if table "001" not exist.

    4. If not exist then create a table by taking part of DB name like "001" with same schema in "DBbackup" database.

    5. Select into "001", from dbo.Emp before matching row count to avoid duplicate records.

    Can you give idea how to achieve it.

    Data export of each table is very time consuming. There are more than 150 DBs with huge data. Is there any alternative wizard or inbuilt script is there in SQL server 2005.

    Can it be achieve by stored procedure.

    Can we put a time stamp in SP to check the processing time for each DB.

    Expecting for your solution. Its very urgent.

    Thanks

    Sharma

  • So, before we start doing anything, how about you show us what you have already done to try and achieve your requirements?

  • Here's some hints on your questions, as this looks a lot like homework:

    first, if EMPID is the primary key for EACH of the 150 tables, are they identity() generated or GUIDS? if they are identity, EVERY table would have EMPID=1, so how do you know if the Employee is unique?

    I don't know if you thought that through.

    how are the EMPID's unique over 150 databases? do you really mean the employee name? how do you know that "Bob" in db049 is or is not the same "Bob" in db007, db134 and db147?

    Can you give idea how to achieve it.

    If you are doing this in TSQL, your "loop" is called a cursor, and you'd need that to iterate through the list of databases.

    Data export of each table is very time consuming. There are more than 150 DBs with huge data. Is there any alternative wizard or inbuilt script is there in SQL server 2005.

    Can it be achieve by stored procedure.

    any script that you write in TSQL can then be saved and done in a stored procedure, so yes.

    Can we put a time stamp in SP to check the processing time for each DB.

    lookup getdate() in BOL; it returns the current time down to about 3 milliseconds.

    if you saved the time at the beginning, you could use the DATEDIFF function, or just store the datetimes for reference...but where would you put the results of the times?

    Expecting for your solution. Its very urgent.

    Thanks

    Sharma

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • DTS is supporting multiple databases.

    I am very weak in stored procedure. So added the query snippets in post.

    Can you please write me stored procedure.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply