1

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)

1
  • 1
    Note: in Sql Management Studio The default option, Generate CREATE statements only, generates a script to create the objects. Generate DROP statements only creates scripts that drop the selected objects. This wizard cannot generate a script that first drops an object and then creates a new version of the object. Commented Dec 14, 2009 at 10:14

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+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.
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.