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

Wednesday, September 7, 2022

How to update global password on remote desktop connection manager

 https://www.bytesizedalex.com/microsoft-remote-desktop-connection-manager/


In contrast, the "Global" profiles are saved in your Windows user profile. These can be edited through Tools > Options > General tab > Default group settings > Profile Management tab..

Friday, September 2, 2022

How to export SSIS packages from SQL server

 Run this on SSMS and then run the results on the command prompt.

USE MSDB

SELECT 'DTUTIL /SQL "\' + F.foldername + '\' + P.NAME +'" /ENCRYPT FILE;"F:\FileTransfer\DJPegging\GYRPACKAGES\' + F.foldername + '\'+ P.NAME+'.DTSX";0'

FROM SYSSSISPACKAGES P

LEFT JOIN sysssispackagefolders  F ON P.FolderID = F.folderid

WHERE F.foldername IN

(

'PH DWH',

'PH DWH STG',

'PHAPPCVTSQL04',

'PHAPPLAGSQL07'

)