Archive

Archive for March, 2012

Get all Table name and Primary Key constraint in a database

March 16, 2012 Leave a comment

Today i got modified database from customer, they asked to validate the database and include in our project. While am validating i came to know that some of the table name where changed. so i tried to find out the changed table name, at that time Primary key constrain give hand to find out those table.

while am surffing in google i got the Query as below

SELECT i.name AS IndexName,
OBJECT_NAME(ic.OBJECT_ID) AS TableName,
COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic
ON i.OBJECT_ID = ic.OBJECT_ID
AND i.index_id = ic.index_id
WHERE i.is_primary_key = 1

Above Query gives me Constraint name and Table name. Thanks to sqlauthority.com

Advertisements
Categories: SQL

Delete all Store Procedure from a database in SQL Server

March 16, 2012 Leave a comment

Here is a way to delete all stored procedures from an SQL Server database.

DECLARE @procedureName varchar(500)
DECLARE cur CURSOR
      FOR SELECT [name] FROM sys.objects WHERE type = ‘p’
      OPEN cur      FETCH NEXT FROM cur INTO @procedureName
      WHILE @@fetch_status = 0
      BEGIN
            EXEC(‘DROP PROCEDURE ‘ + @procedureName)
            FETCH NEXT FROM cur INTO @procedureName
      END
      CLOSE cur
      DEALLOCATE cur

Categories: SQL
%d bloggers like this: