Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating new Database - Forcing Order of Scripts

Status
Not open for further replies.

DonS100

Programmer
Dec 4, 2001
104
0
0
US
Hello, I have a products database that I need to recreate somewhere else but with no data in the tables. Is the best way to do this, simply using the 'Generate SQL Script' option though Enterprise Manager against the existing database. Are there any objects that will not get created?

One thing I have come across with scripting so far is that I have views based on views. So I'm having to manually change the order of views in my script to have the ones not based on views at the top. Is there a easier way to do this?

Thanks

Don
 
Easiest is backup DB restore on the server you want it then run this
Code:
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO

EXEC sp_MSForEachTable '
 IF OBJECTPROPERTY(object_id(''?''), ''TableHasForeignRef'') = 1
  DELETE FROM ?
 else 
  TRUNCATE TABLE ?
'
GO


EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top