SQL Server 查找具有特定列的sql表名

pinkon5k  于 2022-12-10  发布在  其他
关注(0)|答案(4)|浏览(148)

Is their any other way or sql query to find the database table names with a particular column than shown below,

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'NameID'
euoag5mw

euoag5mw1#

在SQL Server中,您可以查询sys.columns
类似于:

SELECT
     t.name
 FROM
     sys.columns c
        inner join
     sys.tables t
        on
           c.object_id = t.object_id
 WHERE
     c.name = 'NameID'

如果您在多个架构中有表,则可能需要额外的查找来解析架构名称。

rkkpypqq

rkkpypqq2#

you can run this query

SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%Column%' -- write the column you search here
ORDER BY schema_name, table_name;
jaxagkaj

jaxagkaj3#

For Oracle Database. Use the below query:

select table_name from all_tab_columns where column_name = 'NameID';

If you’ve got DBA privileges, you can try this command instead:

select table_name from dba_tab_columns where column_name = 'NameID';
hmae6n7t

hmae6n7t4#

SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, 
ORDINAL_POSITION as org_pos, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH as CML
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME like '%Here Column Name%'
ORDER BY TABLE_NAME

相关问题