views:

102

answers:

2

i need a script to script all the database object (like tables,sp,view).....like

 IF  EXISTS (SELECT * FROM sys.objects 
 WHERE object_id = OBJECT_ID(N'[dbo].[fnSplit]') 
 AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
 DROP FUNCTION [dbo].[fnSplit]
 GO

/****** Object:  UserDefinedFunction [dbo].[fnSplit]    Script Date: 12/14/2009  
15:14:23 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fnSplit].......

it will also drop all constraint .....i need a complete package i am aware of tools like scriptio,SQL Management studio(where only one can be selected either create or drop)

A: 

Have a look at this

How to: Generate a Script (SQL Server Management Studio)

This also includes the option for Script Drop and Include If NOT EXISTS under Choose Script Options (which is set to False by default).

astander
+2  A: 

You can use Sql Management Studio, if you right click the database, select 'Tasks' and then 'Generate scripts'. In that wizard, you can select all objects (including triggers) and also if you want the script to contain drop commands.

Jonas Lincoln
+1 exactly - you can **easily** create the whole database and all its objects in a single operation from SSMS - no need to do it on a object-by-object basis.
marc_s