Results 1 to 7 of 7

Thread: Backup and restore database tables data, relations problem !!!

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Backup and restore database tables data, relations problem !!!

    Dear all,
    we have built a small utitlity to save some business data. it uses the msde as its database.

    because the msde doesn't have any enterprize manager, we had to create a backup/restore functions inside the software.

    since its only about 10 tables in the database, we would like to save the data into xml files and resotre them back from xml files.

    our problem is this:

    we didn't implement physical database relations inside the database. although we are using relational database designs. but we prefer to join rows on runtime and not implement relations inside the database.

    this seems to be a very large problem in backup and restoring why?

    because we are have for example two tables : [documents] & [docdetails]

    documents table has an identity integer column which we use as primary key.

    docdetails rows has a foriegn key column called [document] which is related to the [documents.serial]

    when we save the data to xml files its ok, but when we try to retireve the data from xml into the msde database. all [documents] rows are assigned a new autonumber , this way all the related rows in the docdetails table loses their correct integerity with the data .

    i hope i am clear, is there any solution to solve this problem ????

    thank you in advance

    rgds

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Backup and restore database tables data, relations problem !!!

    I think that if you handle the tables’ relations at run time, then you need to handle the tables’ autonumber as well in your app.

  3. #3

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Backup and restore database tables data, relations problem !!!

    is that your way for punishing me for being wrong

  4. #4
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Backup and restore database tables data, relations problem !!!

    I don’t know if you understand me right. What I am trying to say is that you need to generate the autonumber in your app when a record is added. There are three ways to set the autonumber, in database, in dataset and manually through the code. The first to will not work because they are generated independently (perhaps you can try the dataset aoutonumber to see if it works).

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Backup and restore database tables data, relations problem !!!

    I suppose that's happening because of the way you've approached this task. When you take a backup to SQL, you are essentially extracting the information from the database, not backing it up. Now, if you were to maintain your data the way it is, you'd need to first disable the autonumber field on the table, insert the data with primary key values intact, and then restore the autonumbering on the primary key column in the tables.

    This is not a nice approach because you are potentially opening up a hole in data integrity. XML files, being text files, can be edited. Addition of a new row to the xml file could cause duplication.

    MSDE, just like SQL server, allows T-SQL statements. Which means that you can use the BACKUP DATABASE ... TO DISK statement to perform your backups. That is the proper approach.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Backup and restore database tables data, relations problem !!!

    Plus...

    and although I certainly don't agree with saving data to text files...

    It would have been easier to save the DATA from the tables as TAB-DELIMITED .TXT text files.

    Then to get it back into SQL say

    BULK INSERT TABLEXYZ FROM "C:\...\...\TABLEXYZ.TXT" WITH (KEEPIDENTITY)

    KEEPIDENTITY means that the IDENTITY values in the .TXT file are retained during the insert of the data...

    We often "save" text files of tables - so we can archive them (mostly control tables in our DB - not actual production data). We use TDF type .TXT files for that.

    But at any rate - to get around you problem - when you are ready to INSERT the rows from the XML again do this:

    SET IDENTITY_INSERT TABLEXYZ ON

    This will allow you to specify the IDENTITY value in your INSERT statements.

    btw - only one table can have this set to ON at a time - keep that in mind.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Backup and restore database tables data, relations problem !!!

    thx szlamany

    this tip is what i was looking for

    thank you all of your time

    rgds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width