 |
| SQL Server 2005 General discussion of SQL Server *2005* version only. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 17th, 2007, 11:27 AM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How can empty Database?
Hello
I want to know that how can empty DB?
first , Drop all constraint (primary Key & foreign key) then DELETE all
Record !
Thanks
|
|

February 17th, 2007, 11:48 AM
|
 |
Wrox Author
|
|
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
This could be fairly time consuming based on the number of tables you have.
First, you need to remove all foreign key constraints. Once your foreign key constraints are removed, you can delete all the rows from the tables. So, it would be something like this:
ALTER TABLE tablename DROP CONSTRAINT constraintname
GO
DELETE FROM tablename
GO
You don't need to drop the Primary key to delete rows from a table.
Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
|
|

February 18th, 2007, 05:52 AM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi scott
I want to perform this action Automatic by "Batch command" .
for example (cursor , Loop , ...)
first , identify all reference Top-Down
then DELETE all of Records Down-Top .
Thank you very much .
|
|

February 18th, 2007, 10:32 AM
|
 |
Wrox Author
|
|
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Ah, ok, no problem. I'll put something together and send it to you shortly..
Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
|
|

February 18th, 2007, 04:45 PM
|
 |
Wrox Author
|
|
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
So, i think your best bet is to use the system tables and cursors.
Within a cursor, you can query the system tables and for each table, query the system tables to identify all the foreign keys and remove them. Then, delete the data.
This is off the top of my head and have not tested this, but i think it would work. Does this make sense?
If you want an example, i can throw a psuedo-code example together...
Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
|
|

February 19th, 2007, 08:36 AM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Scott
I solve this conundrum .
thank to expend your time for help me .
|
|

February 19th, 2007, 09:12 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
|
|
Morik,
How did you solve it, please?
--Jeff Moden
|
|

February 25th, 2007, 05:02 AM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Jeff
sorry for delay .
contact me with ( [email protected]),please .
|
|

March 2nd, 2007, 01:56 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Another possibly easier route is to query the system tables and create a script that will create all tables without any records or constraints. Then drop the database, re-create the database and apply the script that creates all tables.
|
|

March 6th, 2007, 02:07 PM
|
|
Registered User
|
|
Join Date: Feb 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
-- Persian Boy
Hello
do you really think that a DATABASE only made of TABLE?????????????
convenience !
|
|
 |