Is there a way to specify a column in which table it is used with SQL Query?

Is there any way for a column in which table is it using SQL Query?

+3
source share
5 answers

yes, Assuming this is a db SQL server, you can check the query below -

select [name], object_name(id) from sys.columns where [name] like '%columnname%'

object_name (id) will give you the table name for the specified column name.

+1
source

You can try something like this using Sql Server 2005+

SELECT OBJECT_NAME(c.OBJECT_ID) TableName, c.name ColumnName
FROM sys.columns c
WHERE c.name = '<column name>'
+1
source

Try

SELECT OBJECT_NAME(id) FROM syscolumns WHERE [name] = 'mycolumn'

0

syscolumns ( , ), , . .

0

If you are trying to figure out from which table a particular column arose in a query, the best option is to alias all the columns at the time of writing the queries. I would not accept any code in a code review that does not do this, because it is a pain to understand later.

0
source

Source: https://habr.com/ru/post/1769319/


All Articles