Click here to Skip to main content
15,915,093 members
Home / Discussions / Database
   

Database

 
GeneralDiff b/W ADO & ADO.net Pin
sonia.sardana23-Apr-08 23:46
sonia.sardana23-Apr-08 23:46 
GeneralRe: Diff b/W ADO & ADO.net Pin
Mycroft Holmes24-Apr-08 20:19
professionalMycroft Holmes24-Apr-08 20:19 
GeneralTimeout Exception [modified] Pin
Vimalsoft(Pty) Ltd23-Apr-08 23:25
professionalVimalsoft(Pty) Ltd23-Apr-08 23:25 
GeneralRe: Timeout Exception Pin
Mike Dimmick24-Apr-08 4:15
Mike Dimmick24-Apr-08 4:15 
GeneralRe: Timeout Exception Pin
Vimalsoft(Pty) Ltd24-Apr-08 20:09
professionalVimalsoft(Pty) Ltd24-Apr-08 20:09 
GeneralRe: Timeout Exception Pin
GuyThiebaut24-Apr-08 5:52
professionalGuyThiebaut24-Apr-08 5:52 
GeneralRe: Timeout Exception Pin
Vimalsoft(Pty) Ltd24-Apr-08 20:03
professionalVimalsoft(Pty) Ltd24-Apr-08 20:03 
GeneralDropping all Tables Pin
Broken Bokken23-Apr-08 16:10
Broken Bokken23-Apr-08 16:10 
I am working on a database create script for SQL server 2005. It's getting to be pretty large (20 tables so far) and the gist of the script is to dropall the tables, create the tables, and then add in any default data. I have the last two pieces working correctly, and previously I was dropping each table individually. I found some code to help drop all tables and modified it.

SQL
DECLARE @Count int

--############################################################################################
--		Drop Entities
--############################################################################################


SELECT @Count = COUNT(*) FROM sys.Tables WHERE name NOT LIKE 'sys%'

WHILE @Count > 0
BEGIN
		EXEC sp_MSforeachtable "DROP TABLE ? PRINT '--- Dropped Table ? ---' ";	
		
		SELECT @Count = COUNT(*) FROM sys.Tables WHERE name NOT LIKE 'sys%'
END

IF @Count = 0
BEGIN
	SET @Message = '--- Tables dropped successfully ---' 
END
ELSE
BEGIN
	SET @Message = '--- Error dropping tables ---'
END

PRINT @Message


The problem is that because I have foreign keys, the scrip throws errors. I tried a try-catch but then the query hangs. Ideally, I want the while loop to ignore errors, or at least not display them so that any errors displayed are errors with the create script. I do not want the exec within the while to rollback, which is what I believe the try-catch is doing. Any ideas how to do this?

Broken Bokken

You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod

http://www.brokenbokken.com

GeneralRe: Dropping all Tables Pin
Harini N K23-Apr-08 20:44
Harini N K23-Apr-08 20:44 
GeneralRe: Dropping all Tables Pin
Broken Bokken24-Apr-08 2:25
Broken Bokken24-Apr-08 2:25 
GeneralMissing table in SQL Server Pin
blakey40422-Apr-08 22:59
blakey40422-Apr-08 22:59 
GeneralRe: Missing table in SQL Server Pin
Marek Grzenkowicz22-Apr-08 23:36
Marek Grzenkowicz22-Apr-08 23:36 
GeneralRe: Missing table in SQL Server Pin
blakey40422-Apr-08 23:49
blakey40422-Apr-08 23:49 
GeneralRe: Missing table in SQL Server Pin
Marek Grzenkowicz23-Apr-08 1:27
Marek Grzenkowicz23-Apr-08 1:27 
AnswerRe: Missing table in SQL Server Pin
blakey40423-Apr-08 1:55
blakey40423-Apr-08 1:55 
GeneralConnectivity with SQl database Pin
Sankalp Verma22-Apr-08 22:56
Sankalp Verma22-Apr-08 22:56 
GeneralRe: Connectivity with SQl database Pin
Marek Grzenkowicz22-Apr-08 23:37
Marek Grzenkowicz22-Apr-08 23:37 
GeneralRe: Connectivity with SQl database Pin
Broken Bokken24-Apr-08 3:01
Broken Bokken24-Apr-08 3:01 
Generaltable-value function from ADO Pin
Green Fuze22-Apr-08 22:39
Green Fuze22-Apr-08 22:39 
AnswerRe: table-value function from ADO [modified] Pin
andyharman23-Apr-08 23:19
professionalandyharman23-Apr-08 23:19 
GeneralRe: table-value function from ADO Pin
Mark J. Miller24-Apr-08 10:17
Mark J. Miller24-Apr-08 10:17 
GeneralSlow running Insert/Update query for a specific db Pin
Maira K22-Apr-08 19:32
Maira K22-Apr-08 19:32 
GeneralRe: Slow running Insert/Update query for a specific db Pin
Ashfield22-Apr-08 21:21
Ashfield22-Apr-08 21:21 
GeneralRe: Slow running Insert/Update query for a specific db Pin
Maira K22-Apr-08 22:38
Maira K22-Apr-08 22:38 
GeneralRe: Slow running Insert/Update query for a specific db Pin
Ashfield23-Apr-08 2:21
Ashfield23-Apr-08 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.