https://www.sqlshack.com/a-walk-through-of-moving-database-file-in-sql-server-always-on-availability-group/
Friday, October 28, 2022
Sunday, October 16, 2022
Friday, October 14, 2022
How to concat in excel
="select '"&B3&"' as TableName, count(*) as Ctr from "&A3&".dbo."&B3&" with (nolock) union all"
Friday, October 7, 2022
SQL Server trace
exec sp_trace_setstatus 2,1 -- Start trace
exec sp_trace_setstatus 2,0 -- Stop trace
exec sp_trace_setstatus 2,2 -- Delete trace
Thursday, September 22, 2022
SQL Server How to grant user
USE [PS_STAGING]
GO
CREATE USER [svc_psstaging_feed] FOR LOGIN [svc_psstaging_feed]
GO
1> use ps_staging
2> go
Changed database context to 'PS_STAGING'.
1> create user svc_psstaging_feed for login svc_psstaging_feed
2> go
1> grant select on PSA_TimesheetByWeek to svc_psstaging_feed;
2> go
1>
Monday, September 19, 2022
SQL Server check if user has execute permission
DECLARE @username nvarchar(128) = 'user01';
SELECT COUNT(*) FROM sys.database_permissions
WHERE grantee_principal_id = (SELECT UID FROM sysusers WHERE name = @username)
AND class_desc = 'DATABASE'
AND type='EX'
AND permission_name='EXECUTE'
AND state = 'G';
Result 0 means negative answer, 1 means positive.
Thursday, September 8, 2022
Robocopy
Robocopy Syntax
ROBOCOPY <source> <destination> [file…] [options]
<source> Source Directory (local or network path)
<destination> Destination Directory (local or network path) and
[file…] Specifies the file or files to be copied. You can use wildcard characters
(* or ?), if you want. If the File parameter is not specified, *.* is used as the default value.
robocopy Z:\AEDCMSSQL05\SAC_STAGING\FULL\ F:\SQLBackups\FromAEDCSRV01 AEDCMSSQL05_SAC_STAGING_FULL_20220901_130044.bak
Better
robocopy "D:\SQL_BKP\HKGRMA01" "Z:\HKGRMA01\HKGRMA01" /xo /Z /XA:H /W:5 /s