Monthly Archives: March 2012

Get all Table name and Primary Key constraint in a database

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 AS IndexName,
COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic
AND i.index_id = ic.index_id
WHERE i.is_primary_key = 1

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

Delete all Store Procedure from a database in SQL Server

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

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

%d bloggers like this: