gpt4 book ai didi

java - SQL SERVER 2008-无法获取 ddl 架构中少数对象的对象定义?

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:26 25 4
gpt4 key购买 nike

我正在使用MS SQL SERVER 2008数据库,在其中创建所有对象,例如过程函数 View 等。现在创建一个示例程序获取所有对象definition(ddl),在这里我发现一些对象定义null,我使用以下sql查询获取所有过程的定义:

Select object_definition(object_id) from sys.objects where type = 'P'

这是我的示例代码:

public class sam {
String userName;
String dbURL;
String password;

public sam(String dbURL, String userName, String password) {
this.dbURL = dbURL;
this.userName = userName;
this.password = password;
}

public void createSQLFile() throws IOException, SQLException, ClassNotFoundException {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(dbURL, userName, password);
Statement statement = con.createStatement();
String queryString = "Select object_definition(object_id) from sys.objects where type = 'P'";
ResultSet rs = statement.executeQuery(queryString);
while (rs.next()) {
System.out.println(rs.getString(1));
}
}

public static void main(String[] args) 抛出 SQLException、IOException、ClassNotFoundException {

    String dbURl = "jdbc:sqlserver://localhost:1433;DatabaseName=db";
String userName = "u";
String password = "P";
new sam(dbURl, userName, password).createSQLFile();

}

}我还附上了我的数据库的屏幕截图,其中列出了程序(注意:突出显示的程序神化为空)
enter image description here

任何人都可以建议-如何在加密时获取这些对象定义?

最佳答案

MSDN

The definition of user objects is visible to the object owner or grantees that have any one of the following permissions:
ALTER,
CONTROL,
TAKE OWNERSHIP,
or VIEW DEFINITION.

关于java - SQL SERVER 2008-无法获取 ddl 架构中少数对象的对象定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40421761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com