set arg=
If = 0 Then
show_help()
End If
Server = arg(0)
User = arg(1)
pass = arg(2)
database_name = arg(3)
table_name = arg(4)
set Conn = CreateObject("")
"Driver={SQL Server};Server=" & Server & ";UID=" & User & ";PWD=" & Pass & ";Database=" & database_name
Set rs = ("select count(*) as n from " & database_name & ". where id = object_id(N'[dbo].[" & table_name & "]')")
if rs("n") <=0 Then
"table have???"
End If
sql1="use " &database_name & ";select count(column_name) from information_schema.columns where table_name='" & table_name & "'"
set rs1=(sql1)
num = rs1(0)
Set rs1 = Nothing
i = 1
sql2="use " &database_name & ";select column_name,data_type,IS_NULLABLE,character_octet_length,collation_name,domain_name from information_schema.columns where table_name='" & table_name & "' order by ordinal_position"
' sql2
set rs2= (sql2)
"if exists (select * from where id = object_id(N'[dbo].[" & table_name & "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)"
"drop table [dbo].[" & table_name & "]"
"GO"
"CREATE TABLE [dbo].[" & table_name & "] ("
do while not
col_dn = rs2("domain_name")
col_name = rs2("column_name")
col_type = rs2("data_type")
col_len = rs2("character_octet_length")
col_an = rs2("collation_name")
col_is = rs2("IS_NULLABLE")
sql = chr(9)&"[" & col_name & "] "
If col_dn = "id" Then
sql = sql & col_dn &" "
Else
sql = sql & "[" & col_type & "] "
If col_len <> "" Then
sql = sql & "(" & col_len & ") "
End If
If col_an <> "" Then
sql = sql & "COLLATE " & col_an
End If
End If
If col_is = "No" Then
sql = sql & " NOT NULL "
Else
sql = sql & " NULL "
End If
If i = num Then
sql = sql & Chr(13)&Chr(10)&") ON [PRIMARY]"
Else
sql = sql & ","
End If
i = i +1
sql
loop
"GO"
Set rs2 = Nothing
Set conn=Nothing
Sub show_help()
"code by N37P47ch "
"cscript show_table.vbs ip user pass database table"
End Sub