我正在使用 SQL Server 2000 和 Java。
我正在创建一个应用程序,除其他外,它从表中读取元数据,在另一台服务器上重新创建它们并携带数据。
其中一个表是这样创建的:
CREATE TABLE some_table (
Date datetime NOT NULL,
Code int NOT NULL,
SameCodeAgainWTF AS Code
)
如何检测“SameCodeAgainWTF”列是计算列,以便我在数据迁移阶段不会尝试在其中插入值?
我已经从连接中获取了 DatabaseMetaData 对象。但我无法找到为我提供该信息的方法。
...
DatabaseMetaData dbMetaData = connection.getMetaData();
...
提前致谢。
编辑1:
我想知道是否有不运行另一个查询的解决方案。是否有办法从 DatabaseMetaData 或 ResultSetMetaData 获取信息。
我知道我可以查询系统列,但我想避免它。
SELECT
sysobjects.name AS TableName,
syscolumns.name AS ColumnName
FROM syscolumns
INNER JOIN sysobjects
ON syscolumns.id = sysobjects.id
AND sysobjects.xtype = 'U' --User Tables
WHERE syscolumns.iscomputed = 1
来自:获取数据库表中计算列的列表(SQL服务器)
I'm working with SQL Server 2000 and Java.
I am creating an application that, among other things, reads the metadata from the tables, recreates them at another server and carry the data.
One of the tables was created this way:
CREATE TABLE some_table (
Date datetime NOT NULL,
Code int NOT NULL,
SameCodeAgainWTF AS Code
)
How do I detect that the "SameCodeAgainWTF" column is a computed column so I don't try to insert values at it during the data migration phase?
I already got the DatabaseMetaData object from the connection. But I was unable to find a method that gives me that information.
...
DatabaseMetaData dbMetaData = connection.getMetaData();
...
Thanks in advance.
EDIT 1:
I want to know if there is a solution without running another query. If there is a way to get the information from the DatabaseMetaData or the ResultSetMetaData.
I know I can query the syscolumns but I want to avoid it.
SELECT
sysobjects.name AS TableName,
syscolumns.name AS ColumnName
FROM syscolumns
INNER JOIN sysobjects
ON syscolumns.id = sysobjects.id
AND sysobjects.xtype = 'U' --User Tables
WHERE syscolumns.iscomputed = 1
From: Get List of Computed Columns in Database Table (SQL Server)
发布评论
评论(1)
查询包含
syscolumns >已计算
列。Query syscolumns which contains an
iscomputed
column.