简体   繁体   English

使用delphi查询路径tp mssql服务器表

[英]query path tp mssql server table with delphi

under MSSQL ATTACH DATABASE SQL there is a nice script to attach / detach a database on a MSSQL server. MSSQL ATTACH DATABASE SQL下,有一个很好的脚本可以在MSSQL服务器上附加/分离数据库。 Is there any system variable in Delphi I can use to detect the path the the database files by source code ? Delphi中是否有任何系统变量我可以使用源代码检测数据库文件的路径?

If you want to get path of a data file of a certain database, you'll need to query the sys.master_files table. 如果要获取某个数据库的数据文件的路径,则需要查询sys.master_files表。 In its physical_name column is stored the file name of a database data file, so running a query like this should give you what you need: 在其physical_name列中存储了数据库数据文件的文件名,因此运行这样的查询应该可以满足您的需求:

SELECT
  physical_name
FROM
  sys.master_files
WHERE
  database_id = DB_ID(N'your_database_name')

You can put your database file wherever you want (except network drives, of course), as long as the SQL-Server account has appropriate rights to the file. 只要SQL-Server帐户对文件具有适当的权限,您就可以将数据库文件放在任何位置(当然除了网络驱动器)。

In case you want to stick with the default settings, ie the default database location/path, see this article for details. 如果您想坚持默认设置,即默认数据库位置/路径,请参阅此文章了解详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM