开发者

Is it possible to query data from tables by object_id?

开发者 https://www.devze.com 2023-03-16 06:21 出处:网络
I was wondering whether it is possible to query tables by specifying their object_id instead of table names in SELECT statements.

I was wondering whether it is possible to query tables by specifying their object_id instead of table names in SELECT statements.

The reason for this is that some tables are created dynamically, and their structure (and names) are not known before, and yet I would like to be able to write sprocs that are capable of querying these tables and working on their content.

I know I can create 开发者_JAVA百科dynamic statements and execute it, but maybe there are some better ways, and I would be grateful if someone could share how to approach it.

Thanks.


You have to query sys.columns and build a dynamic query based on that.

There are no better ways: SQL isn't designed for adhoc or unknown sturctures.

I've never worked on an application in 20 years where I don't know what my data looks like. Either your data is persisted or it should be in XML or JSON or such if it's transient-

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号