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)
Query syscolumns which contains an iscomputed
column.
SELECT o.name as TableName, c.name as ComputedColumnName
FROM sysobjects o
INNER JOIN syscolumns c
ON o.id = c.id
AND c.iscomputed = 1
WHERE o.xtype = 'u'
精彩评论