Showing posts with label failing. Show all posts
Showing posts with label failing. Show all posts

Monday, March 12, 2012

Importing data whilst ignoring constraints

Hi all,
I'm trying to import rows in tables from one database into a few tables in
another database
The problem is that the import is failing because constraints are being breached
no matter what order I try and import the table.
I'm sure that there must be a way of switching off constraint checking whilst
importing the data, but at the moment I can't see it. I'm in a catch 22 situation
at the moment, with data in each table depending on data that hasnt been
imported yet.
Any help would be very much appreciated.
Many thanks all
S
> The problem is that the import is failing because constraints are being
> breached no matter what order I try and import the table.
You ought to be able to successfully import data with foreign key
constraints enabled as long as your are doing this in the correct order.
You can enable and disable foreign key constraints with ALTER TABLE like the
example below. See ALTER TABLE in the Books Online for more info.
--disable FK
ALTER TABLE MyTable
NOCHECK CONSTRAINT ALL
--enable FK and validate data
ALTER TABLE MyTable
WITH CHECK
CHECK CONSTRAINT ALL
Hope this helps.
Dan Guzman
SQL Server MVP
"SimonH" <none@.hotmail.com> wrote in message
news:39680632423364747500000@.news.microsoft.com...
> Hi all,
> I'm trying to import rows in tables from one database into a few tables in
> another database
> The problem is that the import is failing because constraints are being
> breached no matter what order I try and import the table.
> I'm sure that there must be a way of switching off constraint checking
> whilst importing the data, but at the moment I can't see it. I'm in a
> catch 22 situation at the moment, with data in each table depending on
> data that hasnt been imported yet.
> Any help would be very much appreciated.
> Many thanks all
> S
>

Importing data whilst ignoring constraints

Hi all,
I'm trying to import rows in tables from one database into a few tables in
another database
The problem is that the import is failing because constraints are being brea
ched
no matter what order I try and import the table.
I'm sure that there must be a way of switching off constraint checking whils
t
importing the data, but at the moment I can't see it. I'm in a catch 22 situ
ation
at the moment, with data in each table depending on data that hasnt been
imported yet.
Any help would be very much appreciated.
Many thanks all
S> The problem is that the import is failing because constraints are being
> breached no matter what order I try and import the table.
You ought to be able to successfully import data with foreign key
constraints enabled as long as your are doing this in the correct order.
You can enable and disable foreign key constraints with ALTER TABLE like the
example below. See ALTER TABLE in the Books Online for more info.
--disable FK
ALTER TABLE MyTable
NOCHECK CONSTRAINT ALL
--enable FK and validate data
ALTER TABLE MyTable
WITH CHECK
CHECK CONSTRAINT ALL
Hope this helps.
Dan Guzman
SQL Server MVP
"SimonH" <none@.hotmail.com> wrote in message
news:39680632423364747500000@.news.microsoft.com...
> Hi all,
> I'm trying to import rows in tables from one database into a few tables in
> another database
> The problem is that the import is failing because constraints are being
> breached no matter what order I try and import the table.
> I'm sure that there must be a way of switching off constraint checking
> whilst importing the data, but at the moment I can't see it. I'm in a
> catch 22 situation at the moment, with data in each table depending on
> data that hasnt been imported yet.
> Any help would be very much appreciated.
> Many thanks all
> S
>

Importing data whilst ignoring constraints

Hi all,
I'm trying to import rows in tables from one database into a few tables in
another database
The problem is that the import is failing because constraints are being breached
no matter what order I try and import the table.
I'm sure that there must be a way of switching off constraint checking whilst
importing the data, but at the moment I can't see it. I'm in a catch 22 situation
at the moment, with data in each table depending on data that hasnt been
imported yet.
Any help would be very much appreciated.
Many thanks all> The problem is that the import is failing because constraints are being
> breached no matter what order I try and import the table.
You ought to be able to successfully import data with foreign key
constraints enabled as long as your are doing this in the correct order.
You can enable and disable foreign key constraints with ALTER TABLE like the
example below. See ALTER TABLE in the Books Online for more info.
--disable FK
ALTER TABLE MyTable
NOCHECK CONSTRAINT ALL
--enable FK and validate data
ALTER TABLE MyTable
WITH CHECK
CHECK CONSTRAINT ALL
--
Hope this helps.
Dan Guzman
SQL Server MVP
"SimonH" <none@.hotmail.com> wrote in message
news:39680632423364747500000@.news.microsoft.com...
> Hi all,
> I'm trying to import rows in tables from one database into a few tables in
> another database
> The problem is that the import is failing because constraints are being
> breached no matter what order I try and import the table.
> I'm sure that there must be a way of switching off constraint checking
> whilst importing the data, but at the moment I can't see it. I'm in a
> catch 22 situation at the moment, with data in each table depending on
> data that hasnt been imported yet.
> Any help would be very much appreciated.
> Many thanks all
> S
>