一个用来查看MS sql server表结构的一个脚本(本来打算用来剽窃的)
发表于:2007-06-30来源:作者:点击数:
标签:
Set conn = Server.CreateObject("ADODB.Connection") conn.open "ODBC名","用户名","密码" Sql1="select * from dbo.sysobjects where type not in(@#S@#,@#D@#,@#K@#)" Sql1="select * from dbo.sysobjects where type =@#U@#" set rscc = server.createob
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "ODBC名","用户名","密码"
Sql1="select * from dbo.sysobjects where type not in(@#S@#,@#D@#,@#K@#)"
Sql1="select * from dbo.sysobjects where type =@#U@#"
set rscc = server.createobject("ADODB.recordset")
set rs = server.createobject("ADODB.recordset")
rscc.open sql1,conn,1,2
do while not rscc.eof
sql ="select * from "&RS
CC("name")
rs.open sql,conn,1,2
response.write "
表名"&RSCC("name")&"
"
if "1"="1" then
for i=0 to rs.Fields.Count-1
response.write "字段名:"&rs.fields(i).name &"
"
response.write "类型:"
if rs.fields(i).type="3" then
response.write "int"
if rs.fields(i).Attributes="16" then response.write " 自动编号字段"
if rs.fields(i).Attributes="120" then response.write " 允许空"
if rs.fields(i).Attributes="24" then response.write " 不允许空"
elseif rs.fields(i).type="129" then
response.write "char"
response.write "大小"&rs.fields(i).DefinedSize
if rs.fields(i).Attributes="120" then response.write " 允许空"
if rs.fields(i).Attributes="24" then response.write " 不允许空"
elseif rs.fields(i).type="201" then
response.write "text"
if rs.fields(i).Attributes="234" then response.write " 允许空"
if rs.fields(i).Attributes="138" then response.write " 不允许空"
elseif rs.fields(i).type="202" then
response.write "nvarchar"
response.write "大小"&rs.fields(i).DefinedSize
if rs.fields(i).Attributes="8" then response.write " ! 不允许空"
if rs.fields(i).Attributes="104" then response.write "! 允许空"
elseif rs.fields(i).type="131" then
response.write "numeric"
if rs.fields(i).Attributes="120" then response.write " 允许空"
if rs.fields(i).Attributes="24" then response.write " 不允许空"
elseif rs.fields(i).type="2" then
response.write "smallint"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="11" then
response.write "bit"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="135" then
response.write "smalldatetime"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="203" then
response.write "ntext"
if rs.fields(i).Attributes="234" then response.write "! 允许空"
if rs.fields(i).Attributes="138" then response.write " ! 不允许空"
elseif rs.fields(i).type="6" then
response.write "money"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="130" then
response.write "nchar"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="4" then
response.write "real"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="5" then
response.write "flat"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="128" then
response.write "binary"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
else
response.write "未知"&rs.fields(i).type
end if
response.write " 属性:"&rs.fields(i).Attributes
response.write "-------------
"
next
end if
rs.close
@#-------------------------------------
rscc.MoveNext
loop
set rs=nothing
set rscc=nothing
set conn=nothing
%><%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "ODBC名","用户名","密码"
Sql1="select * from dbo.sysobjects where type not in(@#S@#,@#D@#,@#K@#)"
Sql1="select * from dbo.sysobjects where type =@#U@#"
set rscc = server.createobject("ADODB.recordset")
set rs = server.createobject("ADODB.recordset")
rscc.open sql1,conn,1,2
do while not rscc.eof
sql ="select * from "&RSCC("name")
rs.open sql,conn,1,2
response.write "<hr>表名"&RSCC("name")&"<br>"
if "1"="1" then
for i=0 to rs.Fields.Count-1
response.write "字段名:"&rs.fields(i).name &"<br>"
response.write "类型:"
if rs.fields(i).type="3" then
response.write "int"
if rs.fields(i).Attributes="16" then response.write " 自动编号字段"
if rs.fields(i).Attributes="120" then response.write " 允许空"
if rs.fields(i).Attributes="24" then response.write " 不允许空"
elseif rs.fields(i).type="129" then
response.write "char"
response.write "大小"&rs.fields(i).DefinedSize
if rs.fields(i).Attributes="120" then response.write " 允许空"
if rs.fields(i).Attributes="24" then response.write " 不允许空"
elseif rs.fields(i).type="201" then
response.write "text"
if rs.fields(i).Attributes="234" then response.write " 允许空"
if rs.fields(i).Attributes="138" then response.write " 不允许空"
elseif rs.fields(i).type="202" then
response.write "nvarchar"
response.write "大小"&rs.fields(i).DefinedSize
if rs.fields(i).Attributes="8" then response.write " ! 不允许空"
if rs.fields(i).Attributes="104" then response.write "! 允许空"
elseif rs.fields(i).type="131" then
response.write "numeric"
if rs.fields(i).Attributes="120" then response.write " 允许空"
if rs.fields(i).Attributes="24" then response.write " 不允许空"
elseif rs.fields(i).type="2" then
response.write "smallint"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="11" then
response.write "bit"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="135" then
response.write "smalldatetime"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="203" then
response.write "ntext"
if rs.fields(i).Attributes="234" then response.write "! 允许空"
if rs.fields(i).Attributes="138" then response.write " ! 不允许空"
elseif rs.fields(i).type="6" then
response.write "money"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="130" then
response.write "nchar"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="4" then
response.write "real"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="5" then
response.write "flat"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
elseif rs.fields(i).type="128" then
response.write "binary"
if rs.fields(i).Attributes="120" then response.write "! 允许空"
if rs.fields(i).Attributes="24" then response.write " ! 不允许空"
else
response.write "未知"&rs.fields(i).type
end if
response.write " 属性:"&rs.fields(i).Attributes
response.write "-------------<br>"
next
end if
rs.close
@#-------------------------------------
rscc.MoveNext
loop
set rs=nothing
set rscc=nothing
set conn=nothing
%>
原文转自:http://www.ltesting.net