获取表信息
我试图获取表信息并给出表名称,因此我编写了如下查询:
SELECT so.name, sc.name, st.name, sc.length, CASE WHEN sc.status = 0x80 THEN 'Y' ELSE 'N' END AS IsIdent, ColOrder
FROM Asdim.dbo.sysobjects so
INNER JOIN Asdim.dbo.syscolumns sc
ON so.id= sc.id
INNER JOIN Asdim.dbo.systypes st
ON sc.xtype = st.xusertype
WHERE so.Name = 'Admin'
问题是我有两个名为“Admin”的表,但它们具有不同的架构。因此,当我运行此查询时:
SELECT * FROM Asdim.dbo.sysobjects WHERE name LIKE 'Admin'
我得到两条记录,因为表名相同。有没有一种方法可以根据架构名称进行过滤?
I am trying to get the table information give a table name so I wrote a query like this:
SELECT so.name, sc.name, st.name, sc.length, CASE WHEN sc.status = 0x80 THEN 'Y' ELSE 'N' END AS IsIdent, ColOrder
FROM Asdim.dbo.sysobjects so
INNER JOIN Asdim.dbo.syscolumns sc
ON so.id= sc.id
INNER JOIN Asdim.dbo.systypes st
ON sc.xtype = st.xusertype
WHERE so.Name = 'Admin'
The problem is that I have two tables with name 'Admin' but they have different schemas. So when I run this query:
SELECT * FROM Asdim.dbo.sysobjects WHERE name LIKE 'Admin'
I get two records since the table names are same. Is there a way that I caould filter out based on the schema name too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用的视图均已弃用,只是为了向后兼容而提供。使用新的视图给出。
INFORMATION_SCHEMA.COLUMNS
几乎包含您需要的所有信息,但缺少有关标识列的信息。The views you are using are all deprecated and just supplied for backward compatibility. Using the new views gives.
INFORMATION_SCHEMA.COLUMNS
has nearly all the information you need but is missing info about identity columns.