Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Copying 683 Tables Is Harder Than It Looks

Copying 683 Tables Is Harder Than It Looks

Scheduled Pinned Locked Moved The Lounge
databasesql-servercomsysadminhelp
21 Posts 7 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AspDotNetDev
    wrote on last edited by
    #1

    I'm using the SQL Server Import and Export tool to refresh a dev database with production data (over 20GB worth). I've failed at least 10 times now. Each time, I hit a new issue. The last big one was that it doesn't like to force inserts into fields of type timestamp. Found all those and ignored those fields. Now I keep hitting errors when it tries to truncate tables with foreign keys. You would think an import tool could account for this. I expect another 600 or so failures before I get this working. :sigh:

    Thou mewling ill-breeding pignut!

    _ Z B T 4 Replies Last reply
    0
    • A AspDotNetDev

      I'm using the SQL Server Import and Export tool to refresh a dev database with production data (over 20GB worth). I've failed at least 10 times now. Each time, I hit a new issue. The last big one was that it doesn't like to force inserts into fields of type timestamp. Found all those and ignored those fields. Now I keep hitting errors when it tries to truncate tables with foreign keys. You would think an import tool could account for this. I expect another 600 or so failures before I get this working. :sigh:

      Thou mewling ill-breeding pignut!

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      AspDotNetDev wrote:

      Now I keep hitting errors when it tries to truncate tables with foreign keys.

      You need to look at your data structures, and import the tables in the correct order... this will resolve this issue for you. eg: If you have Orders and OrderDetails, don't import OrderDetails before importing Orders.

      Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

      A 1 Reply Last reply
      0
      • _ _Damian S_

        AspDotNetDev wrote:

        Now I keep hitting errors when it tries to truncate tables with foreign keys.

        You need to look at your data structures, and import the tables in the correct order... this will resolve this issue for you. eg: If you have Orders and OrderDetails, don't import OrderDetails before importing Orders.

        Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        I wasn't aware I could change the order in the import tool. In any event, some saintly individual posted this online, which should solve my FK issues:

        EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

        Thank you, random stranger!

        Thou mewling ill-breeding pignut!

        A 1 Reply Last reply
        0
        • A AspDotNetDev

          I wasn't aware I could change the order in the import tool. In any event, some saintly individual posted this online, which should solve my FK issues:

          EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

          Thank you, random stranger!

          Thou mewling ill-breeding pignut!

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          Well, that didn't work, but I have high hopes for this working:

          EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL'

          Fingers crossed.

          Thou mewling ill-breeding pignut!

          A 1 Reply Last reply
          0
          • A AspDotNetDev

            Well, that didn't work, but I have high hopes for this working:

            EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL'

            Fingers crossed.

            Thou mewling ill-breeding pignut!

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            Hopes crushed again, but I have even higher hopes for this:

            while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
            begin
            declare @sql nvarchar(2000)
            SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
            + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
            FROM information_schema.table_constraints
            WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
            SELECT @sql
            exec (@sql)
            end

            Thanks to this. Hey, it's dev, I don't need to stinkin constraints. :~

            Thou mewling ill-breeding pignut!

            B 1 Reply Last reply
            0
            • A AspDotNetDev

              Hopes crushed again, but I have even higher hopes for this:

              while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
              begin
              declare @sql nvarchar(2000)
              SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
              + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
              FROM information_schema.table_constraints
              WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
              SELECT @sql
              exec (@sql)
              end

              Thanks to this. Hey, it's dev, I don't need to stinkin constraints. :~

              Thou mewling ill-breeding pignut!

              B Offline
              B Offline
              Brisingr Aerowing
              wrote on last edited by
              #6

              And?

              Gryphons Are Awesome! ‮Gryphons Are Awesome!‬

              A 3 Replies Last reply
              0
              • B Brisingr Aerowing

                And?

                Gryphons Are Awesome! ‮Gryphons Are Awesome!‬

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                34 million rows copied so far, and about 50 million rows to go. Might actually work this time (probably going to take another half hour to finish). :)

                Thou mewling ill-breeding pignut!

                1 Reply Last reply
                0
                • B Brisingr Aerowing

                  And?

                  Gryphons Are Awesome! ‮Gryphons Are Awesome!‬

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #8

                  Not sure why the network graph is so varied. I was hoping it would just saturate the connection until it finished, but there are a bunch of lulls.

                  Thou mewling ill-breeding pignut!

                  1 Reply Last reply
                  0
                  • B Brisingr Aerowing

                    And?

                    Gryphons Are Awesome! ‮Gryphons Are Awesome!‬

                    A Offline
                    A Offline
                    AspDotNetDev
                    wrote on last edited by
                    #9

                    It worked! I now have a dev database with real data to play with. :-D

                    Thou mewling ill-breeding pignut!

                    _ B 2 Replies Last reply
                    0
                    • A AspDotNetDev

                      I'm using the SQL Server Import and Export tool to refresh a dev database with production data (over 20GB worth). I've failed at least 10 times now. Each time, I hit a new issue. The last big one was that it doesn't like to force inserts into fields of type timestamp. Found all those and ignored those fields. Now I keep hitting errors when it tries to truncate tables with foreign keys. You would think an import tool could account for this. I expect another 600 or so failures before I get this working. :sigh:

                      Thou mewling ill-breeding pignut!

                      Z Offline
                      Z Offline
                      ZurdoDev
                      wrote on last edited by
                      #10

                      The way we do it is to keep a script file. Any database changes get added to a script file so if we need to bring down a db from production we do that and then run the script to update the db to development code. Of course that doesn't help you now. :)

                      There are only 10 types of people in the world, those who understand binary and those who don't.

                      A 1 Reply Last reply
                      0
                      • A AspDotNetDev

                        It worked! I now have a dev database with real data to play with. :-D

                        Thou mewling ill-breeding pignut!

                        _ Offline
                        _ Offline
                        _Damian S_
                        wrote on last edited by
                        #11

                        Woot!! Now recreate all your indices and keys before you get too excited...

                        Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                        A 1 Reply Last reply
                        0
                        • _ _Damian S_

                          Woot!! Now recreate all your indices and keys before you get too excited...

                          Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #12

                          Pretty sure all the indexes are still intact. It's just the constraints that are buggered. I kept the output of all the deleted FK constraints, so I should be able to create a script against the old database to snag them and then recreate them on the new database (I copied the dev database before making changes).

                          Thou mewling ill-breeding pignut!

                          _ 1 Reply Last reply
                          0
                          • Z ZurdoDev

                            The way we do it is to keep a script file. Any database changes get added to a script file so if we need to bring down a db from production we do that and then run the script to update the db to development code. Of course that doesn't help you now. :)

                            There are only 10 types of people in the world, those who understand binary and those who don't.

                            A Offline
                            A Offline
                            AspDotNetDev
                            wrote on last edited by
                            #13

                            We have lots of teams and ex-coworkers who touch/have touched the DB. Trying to enforce any sort of policy would not be feasible for us.

                            Thou mewling ill-breeding pignut!

                            Z 1 Reply Last reply
                            0
                            • A AspDotNetDev

                              Pretty sure all the indexes are still intact. It's just the constraints that are buggered. I kept the output of all the deleted FK constraints, so I should be able to create a script against the old database to snag them and then recreate them on the new database (I copied the dev database before making changes).

                              Thou mewling ill-breeding pignut!

                              _ Offline
                              _ Offline
                              _Damian S_
                              wrote on last edited by
                              #14

                              One thing I didn't ask earlier... why didn't you simply detach the other database, make a copy of the mdf and ldf files, and reattach it in your dev environment?

                              Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                              A N 2 Replies Last reply
                              0
                              • _ _Damian S_

                                One thing I didn't ask earlier... why didn't you simply detach the other database, make a copy of the mdf and ldf files, and reattach it in your dev environment?

                                Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                                A Offline
                                A Offline
                                AspDotNetDev
                                wrote on last edited by
                                #15

                                Some of the dev tables need to remain unchanged. For example, we have different integration with AD between our dev and our production environments. If we overwrote those tables on dev, we would no longer be able to login to our web environments. Also, we are always making changes to dev... don't want to screw up the work of other developers. The big one, though, are the permissions. I don't even want to try dealing with permission issues between environments.

                                Thou mewling ill-breeding pignut!

                                1 Reply Last reply
                                0
                                • A AspDotNetDev

                                  I'm using the SQL Server Import and Export tool to refresh a dev database with production data (over 20GB worth). I've failed at least 10 times now. Each time, I hit a new issue. The last big one was that it doesn't like to force inserts into fields of type timestamp. Found all those and ignored those fields. Now I keep hitting errors when it tries to truncate tables with foreign keys. You would think an import tool could account for this. I expect another 600 or so failures before I get this working. :sigh:

                                  Thou mewling ill-breeding pignut!

                                  B Offline
                                  B Offline
                                  Brady Kelly
                                  wrote on last edited by
                                  #16

                                  The SSMS Export & Import tool is a POS. I use Access to import/export tables. Way better. That is the only reason I use Access.

                                  A 1 Reply Last reply
                                  0
                                  • _ _Damian S_

                                    One thing I didn't ask earlier... why didn't you simply detach the other database, make a copy of the mdf and ldf files, and reattach it in your dev environment?

                                    Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                                    N Offline
                                    N Offline
                                    Nicholas Marty
                                    wrote on last edited by
                                    #17

                                    yeah. or just restoring a backup? ;P

                                    1 Reply Last reply
                                    0
                                    • A AspDotNetDev

                                      We have lots of teams and ex-coworkers who touch/have touched the DB. Trying to enforce any sort of policy would not be feasible for us.

                                      Thou mewling ill-breeding pignut!

                                      Z Offline
                                      Z Offline
                                      ZurdoDev
                                      wrote on last edited by
                                      #18

                                      Quote:

                                      We have lots of teams and ex-coworkers who touch/have touched the DB. Trying to enforce any sort of policy would not be feasible for us.

                                      Sounds like a mess. I feel sorry for you. :)

                                      There are only 10 types of people in the world, those who understand binary and those who don't.

                                      1 Reply Last reply
                                      0
                                      • B Brady Kelly

                                        The SSMS Export & Import tool is a POS. I use Access to import/export tables. Way better. That is the only reason I use Access.

                                        A Offline
                                        A Offline
                                        AspDotNetDev
                                        wrote on last edited by
                                        #19

                                        Please don't tell me you also use an Access database. :((

                                        Thou mewling ill-breeding pignut!

                                        1 Reply Last reply
                                        0
                                        • A AspDotNetDev

                                          It worked! I now have a dev database with real data to play with. :-D

                                          Thou mewling ill-breeding pignut!

                                          B Offline
                                          B Offline
                                          Brisingr Aerowing
                                          wrote on last edited by
                                          #20

                                          Party, lets have a party!

                                          Gryphons Are Awesome! ‮Gryphons Are Awesome!‬

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups