DECLARE @DBNAME VARCHAR(128) SET @DBNAME = 'DB_Name' SELECT TOP 5 A.database_name ,B.physical_device_name ,A.media_set_id ,A.backup_size ,A.backup_start_date ,A.backup_finish_date FROM msdb.dbo.backupset A INNER JOIN msdb.dbo.backupmediafamily B ON A.media_set_id = B.media_set_id WHERE A.Database_Name= @DBNAME ORDER BY A.backup_finish_date DESC
This blog contains information related to Microsoft SQL Server and Oracle Administration: Installation, Configuration, Maintenance and Troubleshooting.
Showing posts with label sys.database_principals. Show all posts
Showing posts with label sys.database_principals. Show all posts
9/12/2012
List of recent database backups
Usually we need to find list of recent database backups. When the backup was taken and where it was saved. Below script will get a 5 recent backups
Labels:
ALTER DATABASE MODIFY FILE,
Attach,
Audit,
Backup history,
Boston DBA,
database backups,
list of recent database backups,
SQL Server 2008,
SQLCMD,
sys.database_principals,
T-SQL,
Troubleshooting
Location:
Boston, MA, USA
8/07/2012
Script User Mappings for all SQL server logins sp_addrolemember
Sometimes after you've copied all users from one server to another (sp_help_revlogin) you need to copy all mappings (sp_addrolemember) as well. Execute the script from below in order to Script User Mappings for all SQL server logins and generate sp_addrolemember for all users.
SELECT 'EXEC sp_addrolemember '''+rp.name+''', '''+mp.name+'''' FROM sys.database_role_members drm
JOIN sys.database_principals rp ON (drm.role_principal_id = rp.principal_id)
JOIN sys.database_principals mp ON (drm.member_principal_id = mp.principal_id)
WHERE mp.name NOT IN ('dbo')
GO
Subscribe to:
Posts (Atom)