Domanda

This may have an obvious answer but my googling has not provided and answer

why can't I preform a query such as

Select * FROM OBJECT_ID

Where in this case I do not mean use the function Object_ID('TableName') I mean the actual INT ID associated to the table as specified in sys.Tables.

I just came across two tables in the DB I am working on through the sys.Tables and the happened to have the same name (OE_Down), but different schemas (obviously) and that's what go me thinking about this.

So if I preform a query SELECT * FROM OE_DOWN the result is that for the dbo schema which I assume it looks towards as default. I know the proper practice would be to specify the schema along with the table but why not use their object ID's instead since they are unique over anything else.

È stato utile?

Soluzione

Because object_id is not an object in database, it's just a field of sys.Tables...

And you can't make direct dml (data manipulation language) statements on fields values, but just on db (schema) objects.

Asking sys.tables can be used to generate dynamic sql, but not direct dml statements.

Altri suggerimenti

You can execute a script that can be concatenated. Using SQL Command EXEC('')

getting object name:

SELECT @object_name=name FROM sys.tables WHERE object_id=@object_id

finally:

EXEC('SELECT * FROM '+@object_name)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top