IF OBJECT_ID('tempdb..#TABLOBILGILERI') IS NOT NULL DROP TABLE #TABLOBILGILERI; CREATE TABLE #TABLOBILGILERI ( TABLOADI NVARCHAR(128), KODU NVARCHAR(128), SAYISI INT ); DECLARE @sql NVARCHAR(MAX) = ''; SELECT @sql = @sql + ' INSERT INTO #TABLOBILGILERI (TABLOADI, KODU, SAYISI) SELECT ''' + col.TABLE_NAME + ''' AS TABLOADI, KODU, COUNT(KODU) AS SAYISI FROM ' + col.TABLE_SCHEMA + '.' + col.TABLE_NAME + ' GROUP BY KODU HAVING COUNT(KODU) > 1;' FROM INFORMATION_SCHEMA.COLUMNS col WHERE col.COLUMN_NAME = 'KODU' AND col.TABLE_NAME not IN ('STOK_HAR_OZET') AND EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS col2 INNER JOIN INFORMATION_SCHEMA.TABLES tab ON col2.TABLE_NAME = tab.TABLE_NAME AND col2.TABLE_SCHEMA = tab.TABLE_SCHEMA WHERE col2.TABLE_NAME = col.TABLE_NAME AND col2.COLUMN_NAME = 'KODU' AND tab.TABLE_TYPE IN ('BASE TABLE' ) ) AND EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME WHERE tc.TABLE_NAME = col.TABLE_NAME AND tc.TABLE_SCHEMA = col.TABLE_SCHEMA AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' AND ccu.COLUMN_NAME = 'KODU' ); EXEC sp_executesql @sql; SELECT * FROM #TABLOBILGILERI ORDER BY 3 DESC