I am looking for an easier way to clear all the data from a database.
I tried "TRUNCATE TABLE", but this didn't work because of the foreign key
constraints.
Thanks,
CraigGraig
Yes , you need to drop constraints first.
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:32C43C9A-4CF6-4023-8C82-A53DA1075267@.microsoft.com...
>I am looking for an easier way to clear all the data from a database.
> I tried "TRUNCATE TABLE", but this didn't work because of the foreign key
> constraints.
> Thanks,
> Craig|||Have you thought about scripting the objects and creating a new (empty)
database?
ML
http://milambda.blogspot.com/|||Thanks -- I think I'll do that.
Is there a way to automate scripting a database without going through the
Enterprise Manager wizard and having to remember all the options you selecte
d
the last time you scripted the database. I'm going to be doing this a lot, s
o
I want to try and automate the procress as much as possible.|||I'm not sure about the automating the script creation, but one thing you
could do is issue the truncate table statements to erase the foreign key
tables first, then the primary key table.
i.e. if you have a Customer table with a CustomerID, and an Orders table
that has a foreign key reference to CustomerID, you could TRUNCATE TABLE
Orders first, then TRUNCATE TABLE Customers.
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:241DB382-86D6-4DF4-B4DE-110F4EE08E29@.microsoft.com...
> Thanks -- I think I'll do that.
> Is there a way to automate scripting a database without going through the
> Enterprise Manager wizard and having to remember all the options you
selected
> the last time you scripted the database. I'm going to be doing this a lot,
so
> I want to try and automate the procress as much as possible.|||That doesn't work.
I tried creating a database with an orders table and a customers table and
after I truncated the orders table, I still could not truncate the Customers
table (due to the foreign key constraint).
"Patrick Kremer" wrote:
> I'm not sure about the automating the script creation, but one thing you
> could do is issue the truncate table statements to erase the foreign key
> tables first, then the primary key table.
> i.e. if you have a Customer table with a CustomerID, and an Orders table
> that has a foreign key reference to CustomerID, you could TRUNCATE TABLE
> Orders first, then TRUNCATE TABLE Customers.
> "Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
> news:241DB382-86D6-4DF4-B4DE-110F4EE08E29@.microsoft.com...
> selected
> so
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment