Friday, October 5, 2012

SQl Server Tricks-Part2

Get list of all procedures created on a particular date in a database

To get the list of all the procedures created on a particular date in a data base, you can use this query.

Use YourDBName
Go
select name from sys.objects
where type = 'P'
and create_date=@yourdate
Go



Get list of all procedures modify on a particular date in a database

To get the list of all the procedures modify on a particular date in a data base, you can use the same but just a bit different query i.e change create_date with modify_date.

Use YourDBName
Go
select name from sys.objects
where type = 'P'
and modify_date=@yourdate
Go

Get list of all user defined functions in a database

To get the list of all the user defined functions in a data base, you can use this query.

USE YourDBName;
GO
SELECT name AS function_name
,SCHEMA_NAME(schema_id) AS schema_name
,type_desc
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%';
GO


Delete duplicate records in table

To delete duplicate records in a table you can use this code. The table must have identity column, which will be used to identify the duplicate records. Table in example is has AutoID as Identity Column and Columns which have duplicate data are DC1 and DC2

DELETE
FROM YourTable

WHERE AutiID NOT IN 
(SELECT MAX(AutiID)
FROM YourTable

GROUP BY DC1,DC2)
 

No comments:

Post a Comment

^ Scroll to Top