显示数据库中的存储过程

存储过程|数据|数据库|显示

  
  It's no easy trick to see stored procedures in a database programmatically with a scripting language like ASP. If you're using MS Access, you're out of luck. Access provides no way to see the actual meat of a stored procedure although you can get the names of the procedures in the database with the ADOX.Catalog COM object.

But, if you are using SQL Server (like you should be because you care about your data), you have a guaranteed way to view all your stored procedures using two globally-available system objects: the built-in sysobjects system table and the sp_helptext system stored procedure.

With a couple of simple loops, everything about your stored procedures can be viewed and accessed programmatically in just a few lines. Here's the results of the function (I'm allowing you to view the first few procedures only because this method can be pretty resource-intensive. If you want the complete list of procedures I use on this site, you can get it here.) Here's how it looks when called:

CREATE PROCEDURE sp_addAdvertLink
(
@m1 DateTime,
@m2 DateTime,
@m3 VarChar(20),
@m4 VarChar(20),
@m5 VarChar(255),
@m6 VarChar(255),
@m7 VarChar(255),
@m8 VarChar(255)
)
AS
INSERT INTO
easyAds
(
display_date, display_time, display_month, display_day,
usr_ip_address, usr_browser, display_adName, usr_referer
)
VALUES
(
@m1, @m2, @m3, @m4, @m5, @m6, @m7, @m8
)

CREATE PROCEDURE sp_AddMailRecip
(
@mIPAddr VarChar(255),
@mEmailAddr VarChar(255)
)
AS
INSERT INTO
autoResponder
(
IPaddress, emailAddress
)
VALUES
(
@mIPAddr, @mEmailAddr
)

CREATE PROCEDURE sp_addUsrAddr
(
@mUsr VarChar(255),
@mFstNme VarChar(255),
@mLastNme VarChar(255),
@mAddr1 VarChar(255),
@mAddr2 VarChar(255),
@mcity VarChar(255),
@mstate VarChar(255),
@mzip VarChar(255),
@mEmail VarChar(255),
@mphone VarChar(255),
@mfax VarChar(255),
@mcell VarChar(255),
@mnotes Text
)
AS
INSERT INTO
dayPlannerAddresses
(
usr, firstname, lastname, streetAddress1, streetAddress2,
city, state, zip, eMailAddress, phone, fax, cell, notes
)
VALUES
(
@mUsr, @mFstNme, @mLastNme, @mAddr1, @mAddr2, @mcity, @mstate,
@mzip, @mEmail, @mphone, @mfax, @mcell, @mnotes
)

------------------sysobjects.asp-------------源程序--------------

<% @ Language = JScript %>
<%
with (Response) {
Buffer = true;
Expires = 0;
Clear();
}

function ShowProcs() {
//set-up database connection information
var ConnString = Application("dbConn");
var ConnUser = Application("dbUsr");
var ConnPass = Application("dbPass");

//set this next variable to false to unrestrict the system
var LimitResults = true;
var MagicNumber = 2;

//get a connection
var c = new ActiveXObject("ADODB.Connection");

//open database
c.Open(ConnString, ConnUser, ConnPass);

//enable error-trapping
try {

//attempt to access the sysobjects table.
//if you try this with MS Access, you will get an error...

//sysobjects table contains information about everything
//in your database. From tables to views, and whatever in
//between, all that stuff is in the sysobjects table.

//in my db, a status of 24 indicates that it's a procedure
//that I added and not one of the other bizarre stored procedures
//that were mixed in there as well. A type of P indicates Stored Procedure.
//Other values for type can be 'U' for user tables, 'R' for rule,
//'s' for system tables (like sysobjects), 'TR' for triggers, 'V' for view, //etc... In this case 'P' is the one we want.
var p = c.Execute("SELECT Name FROM sysobjects WHERE status = 24 AND type = 'P' ORDER BY Name;");
} catch(e) {

//oops - sysobjects table not found. You must be using MS Access.
//Or you forgot to re-code the connection string.
Response.Write("This example only works with <B>SQL Server");
Response.Write("</B>. \"sysobjects\" table does not exist!<BR><BR>");
Response.Write("If you are using SQL server, you may need to ");
Response.Write("adjust the ConnString, ConnUs

时间: 2024-10-31 17:30:28

显示数据库中的存储过程的相关文章

显示数据库中的存储过程__转

        It's no easy trick to see stored procedures in a database programmatically with a scripting language like ASP. If you're using MS Access, you're out of luck. Access provides no way to see the actual meat of a stored procedure although you can

jtable显示数据库中的数据,为什么数据显示不完全,第一列列名也没有

问题描述 jtable显示数据库中的数据,为什么数据显示不完全,第一列列名也没有 10C 解决方案 用JTable显示数据库数据将数据库中的数据显示到JTable上将Excel中的数据在JTable中显示 解决方案二: 你for循环写的从1开始的..

SQL 数据库中的存储过程的参数问题

  1.SQL 数据库中的存储过程的参数问题 怎么将SQL数据库中的存储过程中的参数既作为输出变量又作为输出变量? [sql] view plaincopy --drop proc proc_test --go create proc dbo.proc_test @in int, @out int out, @in_out int output as select @out = @in + @in_out, --1 + 2 = 3 @in_out = @out + 1 --3 + 1 = 4 g

asp.net用gridview显示数据库中两个表的数据?

问题描述 asp.net用gridview显示数据库中两个表的数据? asp.net用gridview显示数据库中两个表的数据?把两表绑定在datatable并用gridview显示数据 解决方案 两个表什么关系?如果是一样的表结构,用union连接,如果是主系表关系,那么可以用join.具体按照我说的google下. 解决方案二: 不管是查询几个表,最后通过sql语句走ado.net,查询出来的数据都放入DataTable或DataSet中,然后绑定到gridview 解决方案三: 如果是一起

jfreechart显示数据库中的数据实例

问题描述 jfreechart显示数据库中的数据实例 我想用jfreechart做一个柱状图(只是做个练习),显示数据库(mysql)中的数据,这个可以在jsp中显示吗,请问怎么做,哪位有实例让我看看啊

仪表盘的使用-如何能webform上面用仪表盘,来显示数据库中的数据。

问题描述 如何能webform上面用仪表盘,来显示数据库中的数据. 我想在网页上添加一个仪表盘控件,显示数据库中的数据.请问如何实现?能使用什么控件实现?我用的是VS2010 +SQL2005

select-在C#的combobox中显示数据库中所有的表名,但是sql语句不知道怎么写

问题描述 在C#的combobox中显示数据库中所有的表名,但是sql语句不知道怎么写 List<string> tableNames = "Select( (string)x["Table_Name"] from dt where type=1 and flags=0)"; dt是连接数据库时设定的表名 解决方案 sql语句如下所示:SELECT NAME FROM SYSOBJECTS WHERE TYPE='U' 前提是提前设置好config配置文

c# winform...-C#窗口并排显示数据库中的多张图片

问题描述 C#窗口并排显示数据库中的多张图片 在SQL数据库中有个人员表,人员表中有员工的图片,如何在C#中的窗口显示人员表中所有员工的照片,这些照片并排显示,还有click事件.本人水平有限,谢谢大家.ps 问题的关键不是如何去读取图片,关键是如何把照片全部(个数不定)全部显示出来,因为picturebox只能显示一张图片,而且图片的个数还不定. 解决方案 照片用picturebox装载,不过你如果现实的图片很多的话(个数不定),最好自己做一个mypicturebox控件,然后pictureb

jfreechart mysql-jfreechart显示数据库中的数据实例

问题描述 jfreechart显示数据库中的数据实例 我想用jfreechart做一个柱状图(只是做个练习),显示数据库(mysql)中的数据,这个可以在jsp中显示吗,请问怎么做,哪位有实例让我看看啊