Wednesday, November 30, 2011

SQL Server tips and tricks

Here are some sql server tips and tricks.
To get all the Tables Information in SQL Server


SELECT * from SYS.Tables
To get all the views information in SQL Server


Select * from sys.views  OR

To get only view names
Select Name from sys.views

To get all stored procedure names
SELECT NAME from SYS.PROCEDURES
To get the Stored procedure script programmatically


EXEC sp_HelpText [Stored Procedure Name]
How to delete all stored procedures?


Here first we will generate the delete script and then we will copy the output and execute it once.
First to get the delete statement for stored procedures:

SELECT 'DROP PROCEDURE ' + NAME FROM sys.procedures
This will give us the drop statements for each stored procedure in our output window like below
DROP PROCEDURE USP_NameOfStoredProcedure
DROP PROCEDURE USP_NameOfStoredProcedure1
DROP PROCEDURE USP_NameOfStoredProcedure2

Then copy all these statements and open a new query window and paste all the copied statements and execute.

I wll keep modifing this whenever I will get something !!! Keep in touch !!!