分享更有价值
被信任是一种快乐

SQL如何获取表结构

文章页正文上

小编给大家分享一下SQL如何获取表结构,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!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”) 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=” & tab免费主机域名le_name & ” order by ordinal_position”
wsh.echo sql2set rs2=conn.execute (sql2)
wsh.echo “if exists (select * from dbo.sysobjects where id = object_id(N[dbo].[” & table_name & “]) and OBJECTPROPERTY(id, NIsUserTable) = 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 &” ”
Elsesql = 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以上是“SQL如何获取表结构”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注云技术行业资讯频道!

相关推荐: DM7如何使用裸设备搭建DMRAC

这篇文章主要介绍DM7如何使用裸设备搭建DMRAC,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙免费主机域名伴们一定要看完!一、操作环境主机 IP地址(对外服务) IP地址(内部通信) 实例名 操作系统共享存储二、操作系统配置1、关闭防火墙和SELIN…

文章页内容下
赞(0) 打赏
版权声明:本站采用知识共享、学习交流,不允许用于商业用途;文章由发布者自行承担一切责任,与本站无关。
文章页正文下
文章页评论上

云服务器、web空间可免费试用

宝塔面板主机、支持php,mysql等,SSL部署;安全高速企业专供99.999%稳定,另有高防主机、不限制内容等类型,具体可咨询QQ:360163164,Tel同微信:18905205712

主机选购导航云服务器试用

登录

找回密码

注册