Tuesday, 27 July 2021

SQL script to delete duplicates and get table, sp or view names

 Hi All,

Script to delete duplicates in a table - Sh 

 

WITH cte 

     AS (SELECT TN,IV,ROW_NUMBER() OVER (PARTITION BY TN

                                       ORDER BY ( SELECT 0)) RN 

         FROM   [pos].[Header_Hist]) 

delete FROM cte 

WHERE  RN > 1; 

Script To get table, stored procedure and View names In a database - Sh 

 

For Tables: 

SELECT TABLE_NAME  FROM INFORMATION_SCHEMA.TABLES 

For Stored Procedure: 

Select [NAME] from sysobjects where type = 'P' and category = 0 

For Views: 

Select [NAME] from sysobjects where type = 'V' and category = 0 

 

No comments:

Post a Comment