SQL获取表结构的show
来源:本站原创|时间:2020-01-10|栏目:vb|点击: 次
复制代码 代码如下:
set arg=wscript.arguments
If arg.count = 0 Then
show_help()
wsh.quit
End If
Server = arg(0)
User = arg(1)
pass = arg(2)
database_name = arg(3)
table_name = arg(4)
set Conn = CreateObject("ADODB.Connection")
Conn.Open "Driver={SQL Server};Server=" & Server & ";UID=" & User & ";PWD=" & Pass & ";Database=" & database_name
Set rs = conn.execute("select count(*) as n from " & database_name & ".dbo.sysobjects where id = object_id(N'[dbo].[" & table_name & "]')")
if rs("n") <=0 Then
wsh.echo "table have???"
wsh.quit
End If
sql1="use " &database_name & ";select count(column_name) from information_schema.columns where table_name='" & table_name & "'"
set rs1=conn.execute(sql1)
num = rs1(0)
rs1.close
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"
'wsh.echo sql2
set rs2=conn.execute (sql2)
wsh.echo "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" & table_name & "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)"
wsh.echo "drop table [dbo].[" & table_name & "]"
wsh.echo "GO"
wsh.echo "CREATE TABLE [dbo].[" & table_name & "] ("
do while not rs2.eof
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
wsh.echo sql
rs2.movenext
loop
wsh.echo "GO"
rs2.close
Set rs2 = Nothing
conn.close
Set conn=Nothing
Sub show_help()
wsh.echo "code by N37P47ch "
wsh.echo "cscript show_table.vbs ip user pass database table"
End Sub
您可能感兴趣的文章
- 01-10VBS中的正则表达式的用法大全 <font color=red>原创&
- 01-10VBS教程:正则表达式简介 -非打印字符
- 01-10VBS教程:正则表达式简介 -后向引用
- 01-10VBS教程:正则表达式简介
- 01-10VBS教程:正则表达式简介 -建立正则表达式
- 01-10VBS教程:正则表达式简介 -普通字符
- 01-10VBS教程:正则表达式简介 -定位符
- 01-10VBS教程:正则表达式简介 -限定符
- 01-10VBS教程:正则表达式简介 -正则表达式语法
- 01-10VBS教程:正则表达式简介 -选择与编组
阅读排行
本栏相关
- 01-10下载文件到本地运行的vbs
- 01-10飘叶千夫指源代码,又称qq刷屏器
- 01-10SendKeys参考文档
- 01-10什么是一个高效的软件
- 01-10VBS中的正则表达式的用法大全 &l
- 01-10exe2swf 工具(Adodb.Stream版)
- 01-10VBS中SendKeys的基本应用
- 01-10用VBSCRIPT控制ONSUBMIT事件
- 01-10VBScript教程 第十一课深入VBScript
- 01-10VBScript语法速查及实例说明
随机阅读
- 01-10C#中split用法实例总结
- 01-11ajax实现页面的局部加载
- 04-02jquery与jsp,用jquery
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-10SublimeText编译C开发环境设置
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 01-10delphi制作wav文件的方法