简体   繁体   中英

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. Is there any system variable in Delphi I can use to detect the path the the database files by source code ?

If you want to get path of a data file of a certain database, you'll need to query the sys.master_files table. 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:

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.

In case you want to stick with the default settings, ie the default database location/path, see this article for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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