列出具有模式名称的所有存储过程

时间:2012-09-27 13:47:07

标签: sql-server-2008 stored-procedures database-schema

有人可以建议在数据库中列出所有存储过程及其架构名称吗?谢谢!

7 个答案:

答案 0 :(得分:29)

SELECT [schema] = OBJECT_SCHEMA_NAME([object_id]),
  name
FROM sys.procedures;

SELECT [schema] = SCHEMA_NAME([schema_id]),
  name
FROM sys.procedures;

对于特定数据库,您可以先将该上下文更改为该数据库,或稍微更改Marc的查询(在这种情况下我的查询不好,因为它们依赖于上下文相关的函数): / p>

SELECT 
    SchemaName = s.name,
    ProcedureName = pr.name 
FROM 
    databasename.sys.procedures pr
INNER JOIN 
    databasename.sys.schemas s ON pr.schema_id = s.schema_id;

如果要对所有数据库执行此操作:

DECLARE @sql NVARCHAR(MAX) = N'';

SELECT @sql += N'
  UNION ALL SELECT db = N''' + name + ''', 
    s.name COLLATE Latin1_General_CI_AI,
    o.name COLLATE Latin1_General_CI_AI
  FROM ' + QUOTENAME(name) + '.sys.procedures AS o
  INNER JOIN ' + QUOTENAME(name) + '.sys.schemas AS s
  ON o.[schema_id] = s.[schema_id]'
FROM sys.databases
-- WHERE ... -- probably don't need system databases at least

SELECT @sql = STUFF(@sql, 1, 18, '') 
  -- you may have to adjust  ^^ 18 due to copy/paste, cr/lf, tabs etc 
  + ' ORDER BY by db, s.name, o.name';

EXEC sp_executesql @sql;

如果您的数据库具有不同的排序规则,则必须使用collat​​e子句。

答案 1 :(得分:12)

试试这个:

SELECT 
    SchemaName = s.name,
    ProcedureName = pr.name 
FROM 
    sys.procedures pr
INNER JOIN 
    sys.schemas s ON pr.schema_id = s.schema_id

这应该列出所有存储过程及其模式名称作为结果集。

两种观看次数 - sys.proceduressys.schemas - 都有更多属性 - 如果需要,请查看它们,将它们包含在您的查询中。

答案 2 :(得分:2)

这可能对你有帮助..

  

SELECT * FROM sys.procedures;

答案 3 :(得分:0)

您可以使用脚本生成器来获取它们。在左侧平移中右键单击要获取其存储过程,任务 - >生成脚本的数据库单击下一步并选择选择特定数据库对象并选择存储过程并单击下一步,您可以根据需要自定义并生成脚本。

答案 4 :(得分:0)

试试这个:

execute [sys].[sp_stored_procedures]

或尝试这个并获得所有参数:

execute [sys].[sp_sproc_columns]

好的......你必须使用它来遍历所有数据库目录名称,但是......

答案 5 :(得分:0)

//Getting RSA Key
        NSString *rsaKeyDataStr = [NSString stringWithFormat:@"access_code=%@&order_id=%@",accessCode,orderId];
        NSData *requestData = [NSData dataWithBytes: [rsaKeyDataStr UTF8String] length: [rsaKeyDataStr length]];
        NSMutableURLRequest *rsaRequest = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: rsaKeyUrl]];
        [rsaRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
        [rsaRequest setHTTPMethod: @"POST"];
        [rsaRequest setHTTPBody: requestData];
        NSData *rsaKeyData = [NSURLConnection sendSynchronousRequest: rsaRequest returningResponse: nil error: nil];
        NSString *rsaKey = [[NSString alloc] initWithData:rsaKeyData encoding:NSASCIIStringEncoding];
        rsaKey = [rsaKey stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
        rsaKey = [NSString stringWithFormat:@"-----BEGIN PUBLIC KEY-----\n%@\n-----END PUBLIC KEY-----\n",rsaKey];
        NSLog(@"%@",rsaKey);

        //Encrypting Card Details
        NSString *myRequestString = [NSString stringWithFormat:@"amount=%@&currency=%@",amount,currency];
        CCTool *ccTool = [[CCTool alloc] init];
        NSString *encVal = [ccTool encryptRSA:myRequestString key:rsaKey];
        encVal = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
                                                                                       (CFStringRef)encVal,
                                                                                       NULL,
                                                                                       (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                                       kCFStringEncodingUTF8 ));

        //Preparing for a webview call
        NSString *urlAsString = [NSString stringWithFormat:@"https://secure.ccavenue.com/transaction/initTrans"];
        NSString *Name=[NSString stringWithFormat:@"%@ %@",billing_Fname,billing_Lname];
        NSString *encryptedStr = [NSString stringWithFormat:@"merchant_id=%@&order_id=%@&redirect_url=%@&cancel_url=%@&enc_val=%@&access_code=%@&billing_name=%@&billing_address=%@&billing_city=%@&billing_state=%@&billing_zip=%@&billing_country=India&billing_tel=%@&billing_email=%@&delivery_name=%@&delivery_address=%@&delivery_city=%@&delivery_state=%@&delivery_zip=%@&delivery_country=India&delivery_tel=%@",merchantId,orderId,redirectUrl,cancelUrl,encVal,accessCode,Name,billing_address,billing_city,billing_state,billing_zip,billing_tel,billing_email,Name,billing_address,billing_city,billing_state,billing_zip,billing_tel];

        NSData *myRequestData = [NSData dataWithBytes: [encryptedStr UTF8String] length: [encryptedStr length]];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: urlAsString]];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
        [request setValue:urlAsString forHTTPHeaderField:@"Referer"];
        [request setHTTPMethod: @"POST"];
        [request setHTTPBody: myRequestData];
        [_viewWeb loadRequest:request];

答案 6 :(得分:0)

如果要搜索具有所需架构名称的proc,可以使用以下查询:

SELECT 
    SchemaName = s.name,
    ProcedureName = pr.name 
FROM 
    sys.procedures pr
INNER JOIN 
    sys.schemas s 
ON pr.schema_id = s.schema_id
WHERE s.name = 'YOUR_SCHEMA_NAME'
ORDER BY SchemaName;