试过列出一个数据库里所有的主键吗?

发表于:2007-06-30来源:作者:点击数: 标签:
% dbname = databasename ConnStr = provider= SQL OLEDB .net work=DBMSSOCN; ConnStr = ConnStr uid=uid;pwd=pwd;server= ConnStr = ConnStr IP Address;database= dbname set Conn = server.createobject(adodb.connection) Conn.Open ConnStr sql = SELEC
<%
dbname = "databasename"
ConnStr = "provider=SQLOLEDB.network=DBMSSOCN;"
ConnStr = ConnStr & "uid=<uid>;pwd=<pwd>;server="
ConnStr = ConnStr & "<IP Address>;database=" & dbname

set Conn = server.createobject("adodb.connection")
Conn.Open ConnStr

sql = "SELECT so1.name AS keyName, so2.name AS tableName "
sql = sql & "FROM sysobjects so1 INNER JOIN sysobjects so2 "
sql = sql & "ON so2.id = so1.parent_obj WHERE (so1.xtype=@#PK@#)"
set rs = Conn.execute(sql)
do while not rs.eof
response.write(rs(0) & " is PrimaryKey for " & rs(1) & "<br>")
rs.movenext
loop
rs.close: set rs = nothing
Conn.Close: set Conn = nothing
%>

原文转自:http://www.ltesting.net