【发布时间】:2014-11-06 09:14:32
【问题描述】:
我们是否可以从表中提取 SQL 数据库架构?
以下是我的代码,但现在我可以像
一样提取整个架构Create Table Employee(code int, name blah blah...)
Dim sqlQuery As String
Dim textInsertQueryLine As String
Dim tableSchema As DataTable
Dim tableField As DataRow
Dim tableProperty As DataColumn
Dim SourceConn As New SqlConnection(sourceDBPath)
Dim DestinationConn As New SqlConnection(destinationDBPath)
SourceConn.Open()
DestinationConn.Open()
sqlQuery = "SELECT name FROM sys.tables"
Dim cmdX As New SqlCommand(sqlQuery, SourceConn)
Dim readerX As SqlDataReader = cmdX.ExecuteReader
Do While readerX.Read
Dim cmdY As New SqlCommand(sqlQuery, DestinationConn)
Dim readerY As SqlDataReader = cmdY.ExecuteReader
Do While readerY.Read
If readerX.GetString(0) = readerY.GetString(0) Then
txtConsoleView.AppendText(readerX.GetString(0) + "Matched. " + vbCrLf)
Else
tableSchema = readerX.GetSchemaTable()
txtConsoleView.AppendText(tableSchema.ToString + vbCrLf)
End If
Loop
readerY.Close()
Loop
readerX.Close()
SourceConn.Close()
DestinationConn.Close()
【问题讨论】:
-
readerX.GetSchemaTable() 我使用了这一行,但它只返回表名
-
因为你使用了
SELECT name FROM sys.tables,但你必须从sys.tables返回的真实表中SELECT *。
标签: sql sql-server vb.net sql-server-2008 database-schema