Saturday, April 6, 2013

How to Delete All Stored Procedure From A Database At a Time


declare cur_dropProc cursor
scroll for
select [name] from sysobjects where xtype='p'



open cur_dropProc
go
Declare @procName varchar(500)
fetch first from cur_dropProc into @procName
while @@fetch_status=0
begin
Exec('drop procedure ' + @procName)
fetch next from cur_dropProc into @procName
end
go
close cur_dropProc
go
deallocate  cur_dropProc

How To Delete All Tables In A Database Using sql


To Delete All Tables In A Database At a time Using One Query.

USE [database name]
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

How To Get All Table Names In A Database Using sql.

Here Is The Best Way To Get All Table Names , Procedure Names , Views etc.., Using Following Query.



SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'

And For Other Object Types


C    : Check constraint
D    : Default constraint
F     : Foreign Key constraint
L     : Log
P     : Stored procedure
PK  : Primary Key constraint
RF  : Replication Filter stored procedure
S     :System table
TR   : Trigger
U     : User table
UQ  : Unique constraint
V     : View
X     : Extended stored procedure