我是服务器我有三个数据库,结构如下:
DatabaseA
- SP_A01 =>是一个定义为
的存储过程INSERT INTO T_A01([Id]) SELECT [Id] FROM [dbo].[T_A04]
- SP_A02 =>是一个定义为
的存储过程INSERT INTO T_A01([Id]) SELECT [Id] FROM [DatabaseB].[dbo].[T_B02]
- SP_A03 =>是一个定义为
的存储过程INSERT INTO T_A01([Id]) SELECT [Id] FROM [DatabaseC].[dbo].[T_C02]
- T_A01 =>是一张表
- T_A02 =>是一张表
- T_A03 =>是一张表
- T_A04 =>是一张表
DatabaseB
- T_B01 =>是一张表
- T_B02 =>是一张表
DatabaseC
- T_C01 =>是一张表
- T_C02 =>是一张表
- T_C03 =>是一张表
我想创建一个查询,查找指向与DatabaseA不同的数据库的DatabaseA的所有SP。 在上面的示例中,查询应该给出以下结果:
因为它们指向DatabaseB和DatabaseC。
我尝试了什么
我有以下查询来查找DatabaseA中的所有SP,但我无法理解如何告诉系统只显示指出DatabaseA的那些。
select * from DatabaseA.information_schema.routines where routine_type = 'PROCEDURE'
答案 0 :(得分:4)
您可以使用
import { Injectable } from '@angular/core';
import { ElectronService } from 'ngx-electron';
import * as fs from 'fs';
import { OpenDialogOptions } from 'electron';
@Injectable()
export class FileService {
dialog = this._electronService.remote.dialog;
window = this._electronService.remote.getCurrentWindow();
constructor(private _electronService: ElectronService) { }
loadFileContent(): void{
this.dialog.showOpenDialog(this.window, {},(fileNames) => {
if(fileNames === undefined){
console.error("no files selected!");
return;
}
fs.readFile(fileNames[0], "utf-8", (err, data) => {
if(err){
console.error("Cannot read file ",err);
return;
}
console.log("The content of the file is : ");
console.log(data);
});
});
}
}
创建以下proc
之后SELECT OBJECT_SCHEMA_NAME(referencing_id),
OBJECT_NAME(referencing_id),
referenced_database_name,
referenced_entity_name
FROM sys.sql_expression_dependencies
WHERE referenced_database_name <> DB_NAME() /*Not NULL and not current DB*/
AND OBJECTPROPERTY(referencing_id, 'IsProcedure') = 1
返回
CREATE PROC [dbo].[P1]
AS
EXEC Foobar.dbo.DFG
SELECT [Id]
FROM [DatabaseB].[dbo].[T_B02]