Obtain the full path of database files using SQL statements

Source: Internet
Author: User

Obtain the full path of database files using SQL statements

Select filename from master. dbo. sysdatabases where name = @ databasename

Some useful system stored procedures and usage
---------------------------
Obtain the SQL SERVER name.
Select convert (sysname, serverproperty (N 'servername '))

Read key value
Xp_instance_regread N 'HKEY _ LOCAL_MACHINE ', n' SOFTWARE \ Microsoft \ MSSQLServer \ setup', n' sqlpath'

Obtain SQL SERVER platform information
Xp_msver N 'productversion', n' Language ', n' Platform', n' windowsversion', n' ProcessorCount ', n' PhysicalMemory'

Obtain the logon mode of the SQL SERVER instance.
Xp_instance_regread N 'HKEY _ LOCAL_MACHINE ', n' SOFTWARE \ Microsoft \ MSSQLServer', 'loginmode'
LoginMode = 2 indicates Hybrid Authentication = 1 default nt authentication = 0 sa Authentication
The login security mode; 0 indicates Normal, 1 indicates Windows NT Integrated, and 2 indicates Mixed.

Modify the logon mode of an SQL SERVER instance
Xp_instance_regwrite N 'HKEY _ LOCAL_MACHINE ', n' SOFTWARE \ Microsoft \ MSSQLServer', 'loginmode', n' REG _ dword', 1
1 --- Windows Authentication Mode
2---SQL and Windows authentication modes

Obtain the SQL server name and domain name list.
Xp_ntsec_enumdomains

Exec sp_grantdbaccess N 'zhang ', N 'zhang'
Exec sp_droplogin N 'zhang'
Exec sp_revokedbaccess N 'zhang'
Exec sp_dbcmptlevel N 'dbname'

Sp_stored_procedures
Get the Stored Procedure List

Xp_availablemedia 2
Obtain hard disk partition information

EXECUTE master. dbo. xp_dirtree N 'e: \ ', 1, 1
Obtain the file list under E: \.

EXECUTE master. dbo. xp_fileexist N 'f: \ Program Files \ Microsoft SQL Server \ MSSQL \ BACKUP \ fdsa. dat'
Whether the file exists

Backup log database_name with NO_LOG | TRUNCATE_ONLY
Truncation transaction logs

Dbcc shrinkdatabase database_name
Shrink Database

Exec sp_addumpdevice N 'disk', n'bakdevic', n'd: \ BACKUP \ bakdevic'
Add backup device
Exec sp_dropdevice N 'bakdevic'
Delete a backup device

Xp_instance_regread N 'HKEY _ CURRENT_USER ', n' Software \ Microsoft \ MSSQLServer', n' lastbackupfiledir'
Path of the last backup

Xp_instance_regwrite N 'HKEY _ CURRENT_USER ', n' Software \ Microsoft \ MSSQLServer', n' LastBackupFileDir ', REG_SZ, n' D: \ Program Files \ Microsoft SQL Server \ MSSQL $ FANHUI \ BACKUP \'
Rewrite backup path

Sp_rename 'tablename. id1', 'id'
Change Field name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.