SELECT name AS LoginName, type_desc AS LoginType, create_date, modify_date FROM sys.server_principals WHERE type IN ('S', 'U', 'G', 'R') ORDERBY LoginName;
查询数据库物理文件位置
1 2 3 4 5 6 7 8
USE master; GO SELECT df.name AS LogicalName, df.physical_name AS PhysicalLocation, df.type_desc AS FileType FROM sys.database_files df;
查询登录用户的信息
1 2 3 4 5 6
SELECT* FROM sys.sql_logins; # 或者使用 select name AS loginName, password_hash from sys.sql_logins orderby loginName;
查询用户名和用户hash
1 2 3 4 5 6 7 8
select name, password_hash from sys.sql_logins;
# 查询结果如下所示: sa 0x0200F4ACE5861FDD34791BDEBD9EF1A20AE69BF34967CB9BDFE5FB091CD85655E40A8F1EDEA6BE21225DC808BEC806D25DE47AA130AD8E1945A676A5A9EBAC3882B933425FBF ##MS_PolicyEventProcessingLogin## 0x0200A294782DD50D374C864939C646EECAB60ABFBA414FD65F04FE4EE7526BD97A969D9BBCA0E37A0DBE6D0CF04EB708170A1A57ADDD6C9E6A08708B687A7155D6EBA658185D ##MS_PolicyTsqlExecutionLogin## 0x0200384DAEF76AB6615AE7248DD3312C01EECA1C640E19F35ED9E6B76951FF3EA1F34FD1F23F79E70B0A4639BB09A4CDB7155CF6A3A141CCFBEEB3AF6985505751EEF3A9FDA7 weakpwdsame 0x0200C359A19A3E84F06A49FD0DD1AB0DED8024DD3512473CCFF49D7F4DB8166EE721CBD82F80141B1D80AD90889F7677AC2CF9B76529C81C9347B3659FD32B6CF6113830BA40
// Set up connection string (as a wide string literal) // Note: You might need to adjust the connection string based on your setup WCHAR connStr[] = L"DRIVER={SQL Server Native Client 10.0};" L"SERVER=myServerAddress;" L"INTEGRATED SECURITY=True;" L"DATABASE=myDatabase;";
// Connect to SQL Server retcode = SQLDriverConnect(hDbc, NULL, connStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);