Tabellen und Spalten in Datenbank filtern
SELECT T1.object_id, T1.name AS Spaltenname, T2.name AS Tabelle , T3.name AS SchemaName FROM sys.columns T1
LEFT JOIN sys.tables AS T2
ON T1.object_id = t2.object_id
LEFT JOIN sys.schemas AS T3 ON T2.schema_id = T3.schema_id
where T1.name like ‘%Grund%’
AND T3.name = ‘PROVIA’
SELECT T1.object_id, T1.name AS Spaltenname, T2.name AS Tabelle,T2.schema_id,T3.name ,
SUM([Partitions].[rows]) AS T
FROM sys.columns T1
LEFT JOIN sys.tables AS T2
ON T1.object_id = t2.object_id
LEFT JOIN sys.schemas AS T3 ON T2.schema_id = T3.schema_id
LEFT JOIN sys.partitions AS [Partitions]
ON T2.[object_id] = [Partitions].[object_id]
AND [Partitions].index_id IN ( 0, 1 )
where T1.name like ‘LEISTUNGARTID’
and T2.name not like ‘TMP%’
GROUP BY
T1.object_id,
T1.name ,
T2.name,T2.schema_id,T3.name
HAVING SUM([Partitions].[rows])>0
// alle Textspalten in einer Datenbank finden
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
DATA_TYPE =’text’
and TABLE_SCHEMA not in (‘PEP’,’PPS’,’PFDOK’,’BEVIA’,’KORE’,’ANL’,’MTEMP’)
order by TABLE_SCHEMA
Mit den ausgewählten Spalten eine Tabelle abfragen:
declare @sql nvarchar(max)
set @sql = ‘select ‘
select @sql = @sql + ‘[‘ + column_name +’],’
from information_schema.columns
where table_name=’D_Produktvarianten’ and column_name like ‘a%’
set @sql = left(@sql,len(@sql)-1) — remove trailing comma
set @sql = @sql + ‘ from D_Produktvarianten’
exec sp_executesql @sql
Tabellen mit mehreren Spalten suchen:
SELECT * FROm
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME IN (
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
–DATA_TYPE =’text’
TABLE_SCHEMA in (‘Provia’)
and COLUMN_NAME like ‘faktor’
and TABLE_NAME not like’euBP%’
and TABLE_NAME not like’PKH%’)
AND TABLE_NAME IN
(
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
–DATA_TYPE =’text’
TABLE_SCHEMA in (‘Provia’)
and COLUMN_NAME like ‘LOHNARTID’
and TABLE_NAME not like’euBP%’
and TABLE_NAME not like’PKH%’
)
AND TABLE_NAME IN
(
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
–DATA_TYPE =’text’
TABLE_SCHEMA in (‘Provia’)
and COLUMN_NAME like ‘PERSNR’
and TABLE_NAME not like’euBP%’
and TABLE_NAME not like’PKH%’
)