initial commit

This commit is contained in:
Thierry Schork
2022-12-30 12:10:12 +01:00
commit 7cf858256a
127 changed files with 12534 additions and 0 deletions

85
ALL - check jobs.sql Normal file
View File

@@ -0,0 +1,85 @@
SET NOCOUNT ON;
/*=============================================================================
List last job status. Can use a filtered job list or all the jobs.
derived from https://sqlconjuror.com/sql-server-t-sql-script-to-check-job-run-status/
Context
----------------------
anywhere
Creation : 30.12.2022 / TSC
Modifications:
=============================================================================*/
DECLARE @allJobs BIT = 0;
DECLARE @jobs TABLE (
[name] sysname NOT NULL
,[job_id] UNIQUEIDENTIFIER NOT NULL
,[failed] BIT NOT NULL
DEFAULT 0
,[lastRun] DATETIME NULL
);
IF @allJobs = 0
BEGIN
INSERT INTO @jobs ([name], [job_id])
SELECT
[s].[name]
,[s].[job_id]
FROM [msdb].[dbo].[sysjobs] [s]
WHERE [s].[name] IN (
'zz_tsc OCTPDBA-440 supra'
,'__D70010 - After APSSynchroLoad'
,'_D73031 - SYNC - H Synchronize items and addresses - Central'
,'_D73061 - ITEM - 000 - Manage data before H synchronization - Central'
,'_D73071 - ITEM - Manage data after H synchronization - Central'
,'_D73110 - SYNC - V Synchronization extraction - Central'
,'D73130 - VESTA - SYNC - Interbase 2.0'
,'__D03011 - After working hours - Central'
);
END
ELSE
BEGIN
INSERT INTO @jobs ([name], [job_id])
SELECT
[s].[name]
,[s].[job_id]
FROM [msdb].[dbo].[sysjobs] [s]
END
SELECT
CONVERT(VARCHAR(20), SERVERPROPERTY('ServerName')) AS [ServerName]
,[j].[name] AS [job_name]
,CASE [j].[enabled]
WHEN 1 THEN 'Enabled'
ELSE 'Disabled'
END AS [job_status]
,CASE [jh].[run_status]
WHEN 0 THEN 'Error Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Cancelled'
WHEN 4 THEN 'In Progress'
ELSE 'Status Unknown'
END AS [last_run_status]
,[ja].[run_requested_date] AS [last_run_date]
,CONVERT(
VARCHAR(10)
,CONVERT(DATETIME, RTRIM(19000101))
+ ([jh].[run_duration] * 9 + [jh].[run_duration] % 10000 * 6 + [jh].[run_duration] % 100 * 10) / 216e4
,108
) AS [run_duration]
,[ja].[next_scheduled_run_date]
,CONVERT(VARCHAR(500), [jh].[message]) AS [step_description]
FROM([msdb].[dbo].[sysjobactivity] [ja]
JOIN @jobs [j2] ON j2.[job_id] = ja.[job_id]
LEFT JOIN [msdb].[dbo].[sysjobhistory] [jh]
ON [ja].[job_history_id] = [jh].[instance_id])
JOIN [msdb].[dbo].[sysjobs_view] [j]
ON [ja].[job_id] = [j].[job_id]
WHERE [ja].[session_id] = (SELECT MAX([session_id])FROM [msdb].[dbo].[sysjobactivity])
ORDER BY [job_name]
,[job_status];

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-335", "OCTPDBA-335\OCTPDBA-335.ssmssqlproj", "{4C6A87C7-5D3B-4C13-8347-E0EA550B5A4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C6A87C7-5D3B-4C13-8347-E0EA550B5A4C}.Default|Default.ActiveCfg = Default
{E9D6F50C-B9C2-43B9-A22E-9CA0452E9073}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {546DEB2C-D146-45CF-ABB1-AAFCD6F6504D}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
<Items>
<LogicalFolder Name="Connections" Type="2" />
<LogicalFolder Name="Queries" Type="0" />
<LogicalFolder Name="Miscellaneous" Type="3" />
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-336", "OCTPDBA-336\OCTPDBA-336.ssmssqlproj", "{D24C6A1F-9CA3-4544-903A-9DBB07216C1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D24C6A1F-9CA3-4544-903A-9DBB07216C1A}.Default|Default.ActiveCfg = Default
{0A737271-2A4F-4D85-89B7-DFB8F0CF4AF5}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {617D5102-24C3-4EBF-92E9-7E9B9D6B96F0}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
<Items>
<LogicalFolder Name="Connections" Type="2" />
<LogicalFolder Name="Queries" Type="0" />
<LogicalFolder Name="Miscellaneous" Type="3" />
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,10 @@
SET XACT_ABORT ON;
SET NOCOUNT ON;
SELECT [name],
[sj].[job_id],
'keyword "wait stats" in name'
FROM msdb.dbo.sysjobs sj
WHERE LOWER(sj.[name]) LIKE '%D92060%';

View File

@@ -0,0 +1,67 @@
USE [HCITools];
GO
/*=============================================================================
Look for specific jobs to delete if they exists on the server.
-----------------------------------------------
US OCTPDBA-336
Clean up of the previously defined jobs to be replaced with [_D92060 - Monitor Wait Stats]
Contexte d'utilisation
----------------------
Everywhere where hciTools exists
Création : 13.10.2022 / TSC
=============================================================================*/
SET XACT_ABORT ON;
SET NOCOUNT ON;
DECLARE @found_jobs_names TABLE (job_name VARCHAR(500) NOT NULL);
INSERT INTO @found_jobs_names ([job_name])
VALUES ('DR92060 - Monitor Wait Stats - Central'),
('ZZ-LPE-Monitor Wait Stats'),
('ZZ-LPE-Monitor Wait Stats - AMAREP'),
('ZZ-LPE-Monitor Wait Stats - AMA051'),
('ZZ-LPE-Monitor Wait Stats - AMA562'),
('ZZ-LPE-Monitor Wait Stats - AMA603');
/* declare variables */
DECLARE @job_name VARCHAR(500);
DECLARE clean_jobs CURSOR FAST_FORWARD READ_ONLY FOR
SELECT job_name
FROM @found_jobs_names;
OPEN clean_jobs;
FETCH NEXT FROM clean_jobs
INTO @job_name;
WHILE @@FETCH_STATUS = 0
BEGIN
IF EXISTS ( SELECT 1
FROM msdb.dbo.sysjobs sj
WHERE LOWER(sj.[name]) = LOWER(@job_name))
BEGIN
RAISERROR(
'found job "%s". Dropping',
1,
1,
@job_name) WITH NOWAIT;
EXEC msdb.dbo.sp_delete_job @job_name = @job_name,
@delete_unused_schedule = 1;
END;
FETCH NEXT FROM clean_jobs
INTO @job_name;
END;
CLOSE clean_jobs;
DEALLOCATE clean_jobs;

View File

@@ -0,0 +1,85 @@
/*=============================================================================
check si une db hciTools existe, ainsi qu'un job avec "wait stats" dans son nom sur 1 serveur
-----------------------------------------------
us 336, pour faire le drop des jobs non standardisés
Contexte d'utilisation
----------------------
sur toute les instances avec une db hciTools et ayant un job dont la logique correspond à xxx
Création : 12.10.2022 / TSC
=============================================================================*/
USE [master];
GO
SET XACT_ABORT ON;
SET NOCOUNT ON;
DECLARE @db_hci BIT = 0;
DECLARE @tbl_job_name TABLE (job_id UNIQUEIDENTIFIER,
job_name VARCHAR(500),
matched_by VARCHAR(500),
treated BIT
DEFAULT 0);
SELECT @db_hci = 1
FROM sys.databases db
WHERE name = 'HCITools';
IF @db_hci = 1
BEGIN
--la db hci_tools existe, on check le job
INSERT INTO @tbl_job_name ([job_name],
[job_id],
[matched_by])
SELECT [name],
[sj].[job_id],
'keyword "wait stats" in name'
FROM msdb.dbo.sysjobs sj
WHERE LOWER(sj.[name]) LIKE '%wait stat%'
AND LOWER(sj.[name]) <> '_D92060 - Monitor Wait Stats';
INSERT INTO @tbl_job_name ([job_name],
[job_id],
[matched_by])
SELECT sj.[name],
sj.[job_id],
'dmv "dm_os_wait_stats" in code'
FROM msdb.dbo.sysjobs sj
INNER JOIN msdb.dbo.[sysjobsteps] sp
ON [sp].[job_id] = [sj].[job_id]
WHERE [sp].[command] LIKE '%sys.dm_os_wait_stats%'
AND LOWER(sj.[name]) <> '_D92060 - Monitor Wait Stats';
END;
IF EXISTS (SELECT 1 FROM @tbl_job_name)
AND @db_hci = 1
BEGIN
DECLARE @job_name VARCHAR(500);
DECLARE @job_id UNIQUEIDENTIFIER;
DECLARE @job_source VARCHAR(500);
WHILE EXISTS (SELECT 1 FROM @tbl_job_name WHERE [treated] = 0)
BEGIN
SELECT TOP (1) @job_name = [j].[job_name],
@job_id = [j].[job_id],
@job_source = j.[matched_by]
FROM @tbl_job_name j
WHERE [j].[treated] = 0;
RAISERROR(
'Non standard job seems to be here, check if "%s" should be dropped. (matched by %s)',
1,
1,
@job_name,
@job_source) WITH NOWAIT;
UPDATE @tbl_job_name
SET [treated] = 1
WHERE [job_id] = @job_id
AND [job_name] = @job_name;
END;
END;

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-337", "OCTPDBA-337\OCTPDBA-337.ssmssqlproj", "{3E560419-B009-4CE6-82F5-922C4B5B31F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3E560419-B009-4CE6-82F5-922C4B5B31F4}.Default|Default.ActiveCfg = Default
{CC2C5108-2D39-4901-AEA4-94A171B710D2}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E0692D04-049F-4C6A-AF17-9FEFDB36D6DF}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-337">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="(local):CENTRALINFRA\ua208700">
<Created>2022-10-18T11:56:37.7597663+02:00</Created>
<Type>SQL</Type>
<Server>(local)</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
<ConnectionNode Name="ssunbdevdb01.sunstore.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-10-14T17:34:14.3402632+02:00</Created>
<Type>SQL</Type>
<Server>ssunbdevdb01.sunstore.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="logins.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>logins.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,487 @@
USE [master];
GO
--#region N+1 - test
IF @@SERVERNAME IN ( 'SSUNBQMSREF02\TAM000REF', --AMA
'SSUNBQMSREF02\TCVI000REF', --CVI
'SSUNBQMSREF02\TSU000REF' ) --SUN
BEGIN
--N+2
EXEC ('
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrTest'')
BEGIN
ALTER LOGIN [SqlAppPrescAppTmpUsrTest] WITH PASSWORD = N''FoAZBmWxJBPmZ4Uf:fG8'', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
ALTER LOGIN [SqlAppPrescAppTmpUsrTest] ENABLE
END
ELSE
BEGIN
CREATE LOGIN [SqlAppPrescAppTmpUsrTest] WITH PASSWORD = N''FoAZBmWxJBPmZ4Uf:fG8'', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
END
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrProd'')
begin
DROP LOGIN SqlAppPrescAppTmpUsrProd;
DROP USER SqlAppPrescAppTmpUsrProd;
end
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrInt'')
begin
DROP LOGIN SqlAppPrescAppTmpUsrInt;
DROP USER SqlAppPrescAppTmpUsrInt;
end
');
END;
GO
--#endregion
--#region N+2 - integration
IF @@SERVERNAME IN ( 'SSUNBDEVREF01\DAMA000REF', --AMA
'SSUNBDEVREF01\DCVI000REF', --CVI
'SSUNBDEVREF01\DSUN000REF' ) --SUN
BEGIN
--n+2
EXEC ('
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrInt'')
BEGIN
ALTER LOGIN [SqlAppPrescAppTmpUsrInt] WITH PASSWORD = N''&^CoFlawoo6lRwHGob#E'', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
ALTER LOGIN [SqlAppPrescAppTmpUsrInt] ENABLE
END
ELSE
BEGIN
CREATE LOGIN [SqlAppPrescAppTmpUsrInt] WITH PASSWORD = N''&^CoFlawoo6lRwHGob#E'', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
END
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrProd'')
begin
DROP LOGIN SqlAppPrescAppTmpUsrProd;
DROP USER SqlAppPrescAppTmpUsrProd;
end
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrTest'')
begin
DROP LOGIN SqlAppPrescAppTmpUsrTest;
DROP USER SqlAppPrescAppTmpUsrTest;
end
');
END;
--#endregion
--#region prod
IF @@SERVERNAME IN ( 'SAMNBREP01\APSSQL', --AMA
'SCVNBREP01\APSSQL', --CVI
'SSUNBREP01\APSSQL' ) --SUN
BEGIN
--prod
EXEC ('
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrProd'')
BEGIN
ALTER LOGIN [SqlAppPrescAppTmpUsrProd] WITH PASSWORD = N''KNHz1T=Bft^v!2&ikGA8'', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
ALTER LOGIN [SqlAppPrescAppTmpUsrProd] ENABLE
END
ELSE
BEGIN
CREATE LOGIN [SqlAppPrescAppTmpUsrProd] WITH PASSWORD = N''KNHz1T=Bft^v!2&ikGA8'', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
END
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrInt'')
begin
DROP LOGIN SqlAppPrescAppTmpUsrInt;
DROP USER SqlAppPrescAppTmpUsrInt;
end
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = ''SqlAppPrescAppTmpUsrTest'')
begin
DROP LOGIN SqlAppPrescAppTmpUsrTest;
DROP USER SqlAppPrescAppTmpUsrTest;
end
');
--#endregion
END;
GO
USE ArizonaREP;
GO
/*=============================================================================
Script to create dbRolePrescriptionApp role.
Role Name: dbRolePrescriptionApp
TEMPLATE: Default
EXAMPLE OF SECURABLES TO SET:
INSERT INTO #Securables
VALUES
('DB','GRANT','VIEW DEFINITION','',''),
('SCHEMA','GRANT','SELECT,EXECUTE,INSERT,UPDATE,DELETE','','AP'),
('TABLE','GRANT','INSERT,UPDATE','Address','dbo'),
('SP','GRANT','EXECUTE','sp_bmc_GetNextID','dbo'),
('ROLE','GRANT','db_datareader','','')
-----------------------------------------------
Generate date : 2022-10-13 / up208700
=============================================================================*/
DECLARE @Command NVARCHAR(MAX),
@RoleName VARCHAR(60),
@Users VARCHAR(255),
@typeofobject VARCHAR(50),
@grantordeny VARCHAR(10),
@rightsaction VARCHAR(255),
@objectname VARCHAR(255),
@schemaid VARCHAR(10),
@sysTarget VARCHAR(255),
@sysType VARCHAR(255);
SET @RoleName = 'dbRolePrescriptionApp';
SET @Command = N'';
/* TEMP TABLES */
CREATE TABLE #UsersOnRole (username VARCHAR(255));
CREATE TABLE #Securables (typeofobject VARCHAR(50),
grantordeny VARCHAR(10),
rightsaction VARCHAR(255),
objectname VARCHAR(255),
schemaid VARCHAR(10),
N2 BIT);
/* !!! LIST OF SECURABLES TO CHANGE !!! */
INSERT INTO #Securables
VALUES ('TABLE', 'GRANT', 'SELECT', 'Address', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Address_key', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Address_OU_Link', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'aps_authosization', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Autorization_status_history', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Telecom', 'dbo', 0);
/* GET ALL USERS ON THIS ROLE */
INSERT INTO #UsersOnRole
SELECT members.name
FROM sys.database_role_members
JOIN sys.database_principals roles
ON database_role_members.role_principal_id = roles.principal_id
JOIN sys.database_principals members
ON database_role_members.member_principal_id = members.principal_id
WHERE roles.name = @RoleName;
/* CREATE ROLE */
SELECT @Command
= N'
IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = ''' + @RoleName
+ N''' AND type = ''R'')
BEGIN
CREATE ROLE [' + @RoleName + N'] AUTHORIZATION [dbo]
PRINT ''CREATE ROLE [' + @RoleName + N']''
END
';
EXEC sp_executesql @Command;
SET @Command = N'
DECLARE @SP_Name varchar(255)
';
/* SET ALL ROLE SECURABLES */
DECLARE SecurablesCurs CURSOR FOR
SELECT typeofobject,
grantordeny,
rightsaction,
objectname,
schemaid
FROM #Securables
WHERE N2 = 0;
OPEN SecurablesCurs;
FETCH NEXT FROM SecurablesCurs
INTO @typeofobject,
@grantordeny,
@rightsaction,
@objectname,
@schemaid;
WHILE @@FETCH_STATUS = 0
BEGIN
IF @typeofobject = 'DB'
BEGIN
IF EXISTS ( SELECT 1
FROM sys.fn_builtin_permissions('DATABASE')
WHERE permission_name = '' + @rightsaction + '')
BEGIN
SET @Command = @Command + @grantordeny + N' ' + @rightsaction + N' TO [' + @RoleName + N']
' ;
END;
END;
IF @typeofobject = 'SCHEMA'
BEGIN
SET @Command
= @Command + N'
IF EXISTS (SELECT 1 FROM sys.schemas WHERE name = ''' + @schemaid
+ N''')
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''SCHEMA'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
' + @grantordeny + N' ' + @rightsaction + N' ON SCHEMA::' + @schemaid + N' TO [' + @RoleName
+ N']
END
END
' ;
END;
IF @typeofobject IN ( 'TABLE', 'SP', 'FUNCTIONS', 'VIEWS' )
BEGIN
IF @objectname LIKE '%[%]%'
BEGIN
IF @typeofobject = 'TABLE'
BEGIN
SET @sysTarget = 'sys.tables';
SET @sysType = '';
END;
IF @typeofobject = 'SP'
BEGIN
SET @sysTarget = 'sys.procedures';
SET @sysType = '';
END;
IF @typeofobject = 'FUNCTIONS'
BEGIN
SET @sysTarget = 'sys.objects';
SET @sysType = ' and p.Type IN ( N''FN'', N''IF'', N''TF'', N''FS'', N''FT'' )';
END;
IF @typeofobject = 'VIEWS'
BEGIN
SET @sysTarget = 'sys.views';
SET @sysType = '';
END;
SET @Command
= @Command + N'
DECLARE SP_cursor CURSOR FOR
SELECT p.name FROM ' + @sysTarget + N' p JOIN sys.schemas s ON s.schema_id = p.schema_id WHERE (p.name like '''
+ @objectname + N''') and s.name = ''' + @schemaid + N'' + @sysType
+ N'''
OPEN SP_cursor
FETCH NEXT FROM SP_cursor INTO @SP_Name
WHILE @@FETCH_STATUS = 0
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''OBJECT'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
EXEC(''' + @grantordeny + N' ' + @rightsaction + N' ON [' + @schemaid
+ N'].['' + @SP_Name + ''] TO [' + @RoleName
+ N']'')
END
FETCH NEXT FROM SP_cursor INTO @SP_Name
END
CLOSE SP_cursor
DEALLOCATE SP_cursor
' ;
END;
ELSE
BEGIN
SET @Command
= @Command
+ N'
IF EXISTS(SELECT 1 FROM sys.objects o WITH (NOLOCK) JOIN sys.schemas s ON s.schema_id = o.schema_id WHERE o.name = '''
+ @objectname + N''' AND o.type IN (N''U'',''P'',''V'',''FN'',''IF'',''TF'') AND s.name = '''
+ @schemaid
+ N''')
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''OBJECT'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
' + @grantordeny + N' ' + @rightsaction + N' ON [' + @schemaid + N'].[' + @objectname
+ N'] TO [' + @RoleName + N']
END
END
' ;
END;
END;
IF @typeofobject = 'ASSEMBLIES'
BEGIN
SET @Command
= @Command + N'
IF EXISTS(SELECT 1 FROM sys.assemblies WHERE NAME = ''' + @objectname
+ N''')
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''ASSEMBLY'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
' + @grantordeny + N' ' + @rightsaction + N'::[' + @objectname + N'] TO [' + @RoleName
+ N']
END
END
' ;
END;
IF @typeofobject = 'ROLE'
BEGIN
SET @Command
= @Command
+ N'
IF NOT EXISTS (SELECT 1 FROM sys.database_role_members JOIN sys.database_principals roles ON database_role_members.role_principal_id = roles.principal_id JOIN sys.database_principals members ON database_role_members.member_principal_id = members.principal_id WHERE roles.name = '''
+ @rightsaction + N''' AND members.name = ''' + @RoleName + N''')
BEGIN
EXEC sp_addrolemember N''' + @rightsaction + N''', N''' + @RoleName + N'''
END
' ;
END;
FETCH NEXT FROM SecurablesCurs
INTO @typeofobject,
@grantordeny,
@rightsaction,
@objectname,
@schemaid;
END;
CLOSE SecurablesCurs;
DEALLOCATE SecurablesCurs;
PRINT 'SET ALL SECURABLES ON ROLE [' + @RoleName + ']';
EXEC sp_executesql @Command;
/* ADD USER */
DECLARE UsersCurs CURSOR FOR SELECT username FROM #UsersOnRole;
OPEN UsersCurs;
FETCH NEXT FROM UsersCurs
INTO @Users;
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @Command = N'
EXEC sp_addrolemember N''' + @RoleName + N''', N''' + @Users + N'''
PRINT ''ADD USER [' + @Users + N'] ON ROLE [' + @RoleName + N']''
' ;
FETCH NEXT FROM UsersCurs
INTO @Users;
END;
CLOSE UsersCurs;
DEALLOCATE UsersCurs;
EXEC sp_executesql @Command;
/*=============================================================================
Drop temp tables
=============================================================================*/
DROP TABLE #Securables;
DROP TABLE #UsersOnRole;
/*=============================================================================
Script to create / map all users
=============================================================================*/
DECLARE @username VARCHAR(255),
@Database VARCHAR(255);
SET @username = '';
SET @Command = N'';
SET @Database = '';
CREATE TABLE #AllUsersAndRoles (databasename VARCHAR(255),
rolename VARCHAR(255),
username VARCHAR(255));
INSERT INTO #AllUsersAndRoles
VALUES ('ArizonaREP', 'dbRolePrescriptionApp', 'SqlAppPrescAppTmpUsrInt'),
('ArizonaREP', 'dbRolePrescriptionApp', 'SqlAppPrescAppTmpUsrProd'),
('ArizonaREP', 'dbRolePrescriptionApp', 'SqlAppPrescAppTmpUsrTest');
DECLARE MapUsersAndRolesCurs CURSOR FOR
SELECT databasename,
rolename,
username
FROM #AllUsersAndRoles AUAR
JOIN master.sys.databases D
ON D.name = AUAR.databasename;
OPEN MapUsersAndRolesCurs;
FETCH NEXT FROM MapUsersAndRolesCurs
INTO @Database,
@RoleName,
@username;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @Command
= N'USE ' + @Database + N'
IF EXISTS (SELECT 1 FROM master.dbo.syslogins WHERE name = ''' + @username
+ N''')
BEGIN
IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = N''' + @RoleName
+ N''' AND [type] = ''R'')
BEGIN
IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = N''' + @username
+ N''')
BEGIN
ALTER USER [' + @username + N'] WITH LOGIN = [' + @username + N']
EXEC sp_addrolemember N''' + @RoleName + N''', N''' + @username
+ N'''
END
ELSE
BEGIN
CREATE USER [' + @username + N'] FOR LOGIN [' + @username
+ N'] WITH DEFAULT_SCHEMA=[dbo]
EXEC sp_addrolemember N''' + @RoleName + N''', N''' + @username + N'''
END
END
END
' ;
EXEC sp_executesql @Command;
FETCH NEXT FROM MapUsersAndRolesCurs
INTO @Database,
@RoleName,
@username;
END;
CLOSE MapUsersAndRolesCurs;
DEALLOCATE MapUsersAndRolesCurs;
DROP TABLE #AllUsersAndRoles;
GO
--#region clean old temp login
IF EXISTS ( SELECT name
FROM master.sys.server_principals
WHERE name = 'SqlPrescAppTmpUsr')
BEGIN
DROP LOGIN SqlPrescAppTmpUsr;
DROP USER SqlPrescAppTmpUsr;
END;
--#endregion

View File

@@ -0,0 +1,390 @@
BEGIN TRANSACTION
SET XACT_ABORT ON;
SET NOCOUNT ON;
USE [master]
IF EXISTS(SELECT 1 FROM master.dbo.syslogins WHERE name = 'SqlPrescAppTmpUsr')
BEGIN
ALTER LOGIN SqlPrescAppTmpUsr WITH PASSWORD = N'exzIzPJ@2y9cErHbZh0@', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
ALTER LOGIN SqlPrescAppTmpUsr ENABLE
END
ELSE
BEGIN
CREATE LOGIN SqlPrescAppTmpUsr WITH PASSWORD = N'exzIzPJ@2y9cErHbZh0@', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
END
GO
USE ArizonaREP;
GO
/*=============================================================================
Script to create dbRolePrescriptionApp role.
Role Name: dbRolePrescriptionApp
TEMPLATE: Default
EXAMPLE OF SECURABLES TO SET:
INSERT INTO #Securables
VALUES
('DB','GRANT','VIEW DEFINITION','',''),
('SCHEMA','GRANT','SELECT,EXECUTE,INSERT,UPDATE,DELETE','','AP'),
('TABLE','GRANT','INSERT,UPDATE','Address','dbo'),
('SP','GRANT','EXECUTE','sp_bmc_GetNextID','dbo'),
('ROLE','GRANT','db_datareader','','')
-----------------------------------------------
Generate date : 2022-10-13 / up208700
=============================================================================*/
DECLARE @Command NVARCHAR(MAX),
@RoleName VARCHAR(60),
@Users VARCHAR(255),
@typeofobject VARCHAR(50),
@grantordeny VARCHAR(10),
@rightsaction VARCHAR(255),
@objectname VARCHAR(255),
@schemaid VARCHAR(10),
@sysTarget VARCHAR(255),
@sysType VARCHAR(255);
SET @RoleName = 'dbRolePrescriptionApp';
SET @Command = N'';
/* TEMP TABLES */
CREATE TABLE #UsersOnRole (username VARCHAR(255));
CREATE TABLE #Securables (typeofobject VARCHAR(50),
grantordeny VARCHAR(10),
rightsaction VARCHAR(255),
objectname VARCHAR(255),
schemaid VARCHAR(10),
N2 BIT);
/* !!! LIST OF SECURABLES TO CHANGE !!! */
INSERT INTO #Securables
VALUES ('TABLE', 'GRANT', 'SELECT', 'Address', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Address_key', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Address_OU_Link', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'aps_authosization', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Autorization_status_history', 'dbo', 0),
('TABLE', 'GRANT', 'SELECT', 'Telecom', 'dbo', 0);
/* GET ALL USERS ON THIS ROLE */
INSERT INTO #UsersOnRole
SELECT members.name
FROM sys.database_role_members
JOIN sys.database_principals roles
ON database_role_members.role_principal_id = roles.principal_id
JOIN sys.database_principals members
ON database_role_members.member_principal_id = members.principal_id
WHERE roles.name = @RoleName;
/* CREATE ROLE */
SELECT @Command
= N'
IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = ''' + @RoleName
+ N''' AND type = ''R'')
BEGIN
CREATE ROLE [' + @RoleName + N'] AUTHORIZATION [dbo]
PRINT ''CREATE ROLE [' + @RoleName + N']''
END
';
EXEC sp_executesql @Command;
SET @Command = N'
DECLARE @SP_Name varchar(255)
';
/* SET ALL ROLE SECURABLES */
DECLARE SecurablesCurs CURSOR FOR
SELECT typeofobject,
grantordeny,
rightsaction,
objectname,
schemaid
FROM #Securables
WHERE N2 = 0;
OPEN SecurablesCurs;
FETCH NEXT FROM SecurablesCurs
INTO @typeofobject,
@grantordeny,
@rightsaction,
@objectname,
@schemaid;
WHILE @@FETCH_STATUS = 0
BEGIN
IF @typeofobject = 'DB'
BEGIN
IF EXISTS ( SELECT 1
FROM sys.fn_builtin_permissions('DATABASE')
WHERE permission_name = '' + @rightsaction + '')
BEGIN
SET @Command = @Command + @grantordeny + N' ' + @rightsaction + N' TO [' + @RoleName + N']
' ;
END;
END;
IF @typeofobject = 'SCHEMA'
BEGIN
SET @Command
= @Command + N'
IF EXISTS (SELECT 1 FROM sys.schemas WHERE name = ''' + @schemaid
+ N''')
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''SCHEMA'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
' + @grantordeny + N' ' + @rightsaction + N' ON SCHEMA::' + @schemaid + N' TO [' + @RoleName
+ N']
END
END
' ;
END;
IF @typeofobject IN ( 'TABLE', 'SP', 'FUNCTIONS', 'VIEWS' )
BEGIN
IF @objectname LIKE '%[%]%'
BEGIN
IF @typeofobject = 'TABLE'
BEGIN
SET @sysTarget = 'sys.tables';
SET @sysType = '';
END;
IF @typeofobject = 'SP'
BEGIN
SET @sysTarget = 'sys.procedures';
SET @sysType = '';
END;
IF @typeofobject = 'FUNCTIONS'
BEGIN
SET @sysTarget = 'sys.objects';
SET @sysType = ' and p.Type IN ( N''FN'', N''IF'', N''TF'', N''FS'', N''FT'' )';
END;
IF @typeofobject = 'VIEWS'
BEGIN
SET @sysTarget = 'sys.views';
SET @sysType = '';
END;
SET @Command
= @Command + N'
DECLARE SP_cursor CURSOR FOR
SELECT p.name FROM ' + @sysTarget + N' p JOIN sys.schemas s ON s.schema_id = p.schema_id WHERE (p.name like '''
+ @objectname + N''') and s.name = ''' + @schemaid + N'' + @sysType
+ N'''
OPEN SP_cursor
FETCH NEXT FROM SP_cursor INTO @SP_Name
WHILE @@FETCH_STATUS = 0
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''OBJECT'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
EXEC(''' + @grantordeny + N' ' + @rightsaction + N' ON [' + @schemaid
+ N'].['' + @SP_Name + ''] TO [' + @RoleName
+ N']'')
END
FETCH NEXT FROM SP_cursor INTO @SP_Name
END
CLOSE SP_cursor
DEALLOCATE SP_cursor
' ;
END;
ELSE
BEGIN
SET @Command
= @Command
+ N'
IF EXISTS(SELECT 1 FROM sys.objects o WITH (NOLOCK) JOIN sys.schemas s ON s.schema_id = o.schema_id WHERE o.name = '''
+ @objectname + N''' AND o.type IN (N''U'',''P'',''V'',''FN'',''IF'',''TF'') AND s.name = '''
+ @schemaid
+ N''')
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''OBJECT'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
' + @grantordeny + N' ' + @rightsaction + N' ON [' + @schemaid + N'].[' + @objectname
+ N'] TO [' + @RoleName + N']
END
END
' ;
END;
END;
IF @typeofobject = 'ASSEMBLIES'
BEGIN
SET @Command
= @Command + N'
IF EXISTS(SELECT 1 FROM sys.assemblies WHERE NAME = ''' + @objectname
+ N''')
BEGIN
IF EXISTS(SELECT 1 FROM sys.fn_builtin_permissions(''ASSEMBLY'') WHERE permission_name = ''' + @rightsaction
+ N''')
BEGIN
' + @grantordeny + N' ' + @rightsaction + N'::[' + @objectname + N'] TO [' + @RoleName
+ N']
END
END
' ;
END;
IF @typeofobject = 'ROLE'
BEGIN
SET @Command
= @Command
+ N'
IF NOT EXISTS (SELECT 1 FROM sys.database_role_members JOIN sys.database_principals roles ON database_role_members.role_principal_id = roles.principal_id JOIN sys.database_principals members ON database_role_members.member_principal_id = members.principal_id WHERE roles.name = '''
+ @rightsaction + N''' AND members.name = ''' + @RoleName + N''')
BEGIN
EXEC sp_addrolemember N''' + @rightsaction + N''', N''' + @RoleName + N'''
END
' ;
END;
FETCH NEXT FROM SecurablesCurs
INTO @typeofobject,
@grantordeny,
@rightsaction,
@objectname,
@schemaid;
END;
CLOSE SecurablesCurs;
DEALLOCATE SecurablesCurs;
PRINT 'SET ALL SECURABLES ON ROLE [' + @RoleName + ']';
EXEC sp_executesql @Command;
/* ADD USER */
DECLARE UsersCurs CURSOR FOR SELECT username FROM #UsersOnRole;
OPEN UsersCurs;
FETCH NEXT FROM UsersCurs
INTO @Users;
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @Command = N'
EXEC sp_addrolemember N''' + @RoleName + N''', N''' + @Users + N'''
PRINT ''ADD USER [' + @Users + N'] ON ROLE [' + @RoleName + N']''
' ;
FETCH NEXT FROM UsersCurs
INTO @Users;
END;
CLOSE UsersCurs;
DEALLOCATE UsersCurs;
EXEC sp_executesql @Command;
/*=============================================================================
Drop temp tables
=============================================================================*/
DROP TABLE #Securables;
DROP TABLE #UsersOnRole;
/*=============================================================================
Script to create / map all users
=============================================================================*/
DECLARE @username VARCHAR(255),
@Database VARCHAR(255);
SET @username = '';
SET @Command = N'';
SET @Database = '';
CREATE TABLE #AllUsersAndRoles (databasename VARCHAR(255),
rolename VARCHAR(255),
username VARCHAR(255));
INSERT INTO #AllUsersAndRoles
VALUES ('ArizonaREP', 'dbRolePrescriptionApp', 'SqlAppPrescAppTmpUsrInt'),
('ArizonaREP', 'dbRolePrescriptionApp', 'SqlAppPrescAppTmpUsrProd'),
('ArizonaREP', 'dbRolePrescriptionApp', 'SqlAppPrescAppTmpUsrTest'),
('ArizonaREP', 'dbRolePrescriptionApp', 'SqlPrescAppTmpUsr');
DECLARE MapUsersAndRolesCurs CURSOR FOR
SELECT databasename,
rolename,
username
FROM #AllUsersAndRoles AUAR
JOIN master.sys.databases D
ON D.name = AUAR.databasename;
OPEN MapUsersAndRolesCurs;
FETCH NEXT FROM MapUsersAndRolesCurs
INTO @Database,
@RoleName,
@username;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @Command
= N'USE ' + @Database + N'
IF EXISTS (SELECT 1 FROM master.dbo.syslogins WHERE name = ''' + @username
+ N''')
BEGIN
IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = N''' + @RoleName
+ N''' AND [type] = ''R'')
BEGIN
IF EXISTS (SELECT 1 FROM sys.database_principals WHERE name = N''' + @username
+ N''')
BEGIN
ALTER USER [' + @username + N'] WITH LOGIN = [' + @username + N']
EXEC sp_addrolemember N''' + @RoleName + N''', N''' + @username
+ N'''
END
ELSE
BEGIN
CREATE USER [' + @username + N'] FOR LOGIN [' + @username
+ N'] WITH DEFAULT_SCHEMA=[dbo]
EXEC sp_addrolemember N''' + @RoleName + N''', N''' + @username + N'''
END
END
END
' ;
EXEC sp_executesql @Command;
FETCH NEXT FROM MapUsersAndRolesCurs
INTO @Database,
@RoleName,
@username;
END;
CLOSE MapUsersAndRolesCurs;
DEALLOCATE MapUsersAndRolesCurs;
DROP TABLE #AllUsersAndRoles;
GO
--ROLLBACK TRANSACTION
COMMIT TRANSACTION

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-345", "OCTPDBA-345\OCTPDBA-345.ssmssqlproj", "{AB935609-D0BA-4D5E-8EA9-DAA22DEEAFBB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AB935609-D0BA-4D5E-8EA9-DAA22DEEAFBB}.Default|Default.ActiveCfg = Default
{DD6A9FEB-284B-4FAC-A1A2-BE32F857ED4D}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8490A918-22C6-46B7-B726-FD2B66824BB5}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-345">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="(local):CENTRALINFRA\ua208700">
<Created>2022-10-18T14:18:35.0573868+02:00</Created>
<Type>SQL</Type>
<Server>(local)</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
<ConnectionNode Name="ssunbqmsdb02.sunstore.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-10-18T14:24:06.6989503+02:00</Created>
<Type>SQL</Type>
<Server>ssunbqmsdb02.sunstore.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="check dbmail status.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:ssunbqmsdb02.sunstore.ch\apssql:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>ssunbqmsdb02.sunstore.ch\apssql</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>check dbmail status.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,177 @@
USE [HCITools];
SET NOCOUNT ON;
IF OBJECT_ID('dbo.mon_get_dbMail_status') IS NOT NULL BEGIN
DROP PROCEDURE dbo.mon_get_dbMail_status;
END;
GO
/*=============================================================================
Vérifie que tout les composants nécessaire à db_mail soient actif et configuré, ainsi que l'on ait pas de mail(s) en erreurs
adapté depuis https://www.mssqltips.com/sqlservertip/5258/sql-server-database-mail-health-check-for-all-sql-servers/
Les composants vérifiés sont:
* Sql express
db_mail n'est pas disponible sur cette version
* Est-ce que l'agent SQL tourne ?
* Est-ce que db_mail est actif ?
* Est-ce qu'un profil db_mail existe
* Est-ce qu'un accompte mail existe ?
* Est-ce que l'agent SQL à la fonction mail active ?
* Est-ce que le profil db_mail est associé à l'agent SQL ?
* Est-ce que l'ont trouve des entrées en erreur dans le log des mails dans les derniers X jours (défaut = 7) ?
Si aucun de ces composants est en echec, la valeur de "mails_are_sent" dans l'output est à 1.
Si n'importe quel de ces composant empêche l'envoi de mails, ou que des mails sont en erreur, la valeur est 0
Le champ "notes" contient un détail en toute lettre de ce qui peut bloquer / est bloquant lorsque "mails_are_sent" = 0
Contexte d'utilisation
----------------------
Sur tous les serveurs où db_mail est supposé tourner
Création : 18.10.2022 / TSC
=============================================================================*/
CREATE PROCEDURE dbo.mon_get_dbMail_status @check_failed_mail_in_past_days INT = 7
AS BEGIN
DECLARE
@SQLAgentEnabled INT = 0
,@SQLAgentStarted INT = 0
,@DBMailEnabled INT = 0
,@MailProfileEnabled INT = 0
,@MailAccountEnabled INT = 0
,@SQLAgentMailEnabled INT = 0
,@SQLAgentMailProfileEnabled sysname = ''
,@failed_email_error INT = 0;
-- SQL Server Agent enabled
SELECT @SQLAgentEnabled = CAST(value_in_use AS INT)
FROM sys.configurations
WHERE [name] = 'Agent XPs';
-- SQL Server Agent status
IF (SELECT CAST(SERVERPROPERTY('Edition') AS VARCHAR(30))) NOT LIKE 'Express Edition%' BEGIN
SELECT @SQLAgentStarted = CASE
WHEN status_desc = 'Running' THEN 1
ELSE 0
END
FROM sys.dm_server_services
WHERE SERVICENAME LIKE 'SQL Server Agent%'
OR servicename LIKE 'sqlagent$%'
;
END
-- SQL Database Mail is enabled
SELECT @DBMailEnabled = CAST(value_in_use AS INT)
FROM sys.configurations
WHERE [name] = 'Database Mail XPs';
-- @SQLAgentMailEnabled
SELECT @MailProfileEnabled = CASE
WHEN COUNT(*) > 0 THEN 1
ELSE 0
END
FROM msdb.dbo.sysmail_profile;
-- @MailAccountEnabled
SELECT @MailAccountEnabled = CASE
WHEN COUNT(*) > 0 THEN 1
ELSE 0
END
FROM msdb.dbo.sysmail_account;
-- SQL Server Agent is enabled to use Database Mail
EXECUTE master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE'
,N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent'
,N'UseDatabaseMail'
,@SQLAgentMailEnabled OUTPUT;
-- SQL Server Agent is enabled to use Database Mail and Mail Profile is assigned
EXECUTE master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE'
,N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent'
,N'DatabaseMailProfile'
,@SQLAgentMailProfileEnabled OUTPUT;
-- Check if there are failed email send in the last x days
--SELECT @failed_email_error = CASE
-- WHEN COUNT(*) > 0 THEN 1
-- ELSE 0 END
SELECT @failed_email_error = COUNT(1)
--SELECT *
FROM msdb.dbo.sysmail_event_log
WHERE event_type = 'error'
AND log_date > DATEADD(DAY, @check_failed_mail_in_past_days * -1, CURRENT_TIMESTAMP);
/*
--check each conditions
SELECT
@SQLAgentEnabled AS SQLAgentEnabled
,@SQLAgentStarted AS SQLAgentStarted
,@DBMailEnabled AS DBMailEnabled
,@MailProfileEnabled AS MailProfileEnabled
,@MailAccountEnabled AS MailAccountEnabled
,@SQLAgentMailEnabled AS SQLAgentMailEnabled
,@SQLAgentMailProfileEnabled AS SQLAgentMailProfileEnabled
,@failed_email_error AS failed_email_error
;
*/
-- Final report
SELECT
@@SERVERNAME AS Server_Name
,CAST(CURRENT_TIMESTAMP AS SMALLDATETIME) AS Run_Date
,@SQLAgentEnabled * @SQLAgentStarted * @DBMailEnabled * @MailProfileEnabled * @MailAccountEnabled
* @SQLAgentMailEnabled * (CASE WHEN @SQLAgentMailProfileEnabled IS NOT NULL THEN 1 ELSE 0 END)
* (CASE WHEN ISNULL(@failed_email_error, 0) = 0 THEN 1 ELSE 0 END) AS mails_are_sent
,CASE
WHEN CAST(SERVERPROPERTY('Edition') AS VARCHAR(30)) LIKE 'Express Edition%' THEN
'Express Edition, DB Mail not supported'
ELSE
CASE
WHEN @SQLAgentEnabled = 0 THEN 'SQL Agent disabled; '
ELSE ''
END
+
CASE
WHEN @SQLAgentStarted = 0 THEN 'SQL Agent is stopped; '
ELSE ''
END
+
CASE
WHEN @DBMailEnabled = 0 THEN 'DB Mail disabled; '
ELSE ''
END
+
CASE
WHEN @MailProfileEnabled = 0 THEN 'Mail Profile disabled; '
ELSE ''
END
+
CASE
WHEN @MailAccountEnabled = 0 THEN 'Mail Account disabled; '
ELSE ''
END
+
CASE
WHEN @SQLAgentMailEnabled = 0 THEN 'SQL Agent Mail disabled; '
ELSE ''
END
+
CASE
WHEN @SQLAgentMailProfileEnabled IS NOT NULL THEN ''
ELSE 'SQL Agent Mail Profile disabled; '
END
+
CASE
WHEN @failed_email_error > 0 THEN
'found ' + CAST(@failed_email_error AS VARCHAR(10)) + ' failed email(s) during last '
+ CONVERT(VARCHAR(5), @check_failed_mail_in_past_days) + ' days; '
ELSE ''
END
END AS Notes;
END;
GO
--sur ssunbqmsdb02.sunstore.ch\apssql, l'agent est stoppé et il y a des mails en erreur depuis le 12.10.22
EXECUTE HCITools.[dbo].[mon_get_dbMail_status] @check_failed_mail_in_past_days = 30; -- int

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-347 perfs ama051 and ama201", "OCTPDBA-347 perfs ama051 and ama201.ssmssqlproj", "{210D62C9-E92C-48F2-A085-C8E8A93B48EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{210D62C9-E92C-48F2-A085-C8E8A93B48EC}.Default|Default.ActiveCfg = Default
{DFCD700F-ED92-4F7F-989C-44A5C07F3123}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65739266-9A11-4F5E-94B0-5F2D25B228AF}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
<Items>
<LogicalFolder Name="Connections" Type="2" />
<LogicalFolder Name="Queries" Type="0" />
<LogicalFolder Name="Miscellaneous" Type="3" />
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,54 @@
--ama201
-- NCIX_entry_covering_acounting
IF INDEXPROPERTY(OBJECT_ID('dbo.Entry'), 'NCIX_entry_covering_acounting', 'IndexID') IS NOT NULL
BEGIN;
PRINT 'idx NCIX_entry_covering_acounting drop'
DROP INDEX dbo.Entry.NCIX_entry_covering_acounting;
END;
-- NCIX_entry_ET_reconciliation_status
IF INDEXPROPERTY(OBJECT_ID('dbo.Entry'), 'NCIX_entry_ET_reconciliation_status', 'IndexID') IS NOT NULL
BEGIN;
PRINT 'idx NCIX_entry_ET_reconciliation_status drop';
DROP INDEX dbo.Entry.NCIX_entry_ET_reconciliation_status;
END;
GO
IF INDEXPROPERTY(OBJECT_ID('dbo.Entry'), 'NCIX_entry_COL_ET_reconciliation_status', 'IndexID') IS NOT NULL
BEGIN;
PRINT 'idx NCIX_entry_COL_ET_reconciliation_status drop';
DROP INDEX dbo.Entry.NCIX_entry_COL_ET_reconciliation_status;
END;
GO
IF INDEXPROPERTY(OBJECT_ID('dbo.Entry'), 'NCIX_entry_COL_ET_reconciliation_status', 'IndexID') IS NULL
BEGIN;
PRINT 'idx NCIX_entry_COL_ET_reconciliation_status create';
CREATE NONCLUSTERED INDEX NCIX_entry_COL_ET_reconciliation_status
ON [dbo].[Entry] ([ET_reconciliation_status])
INCLUDE
([ET_document_header],
[ET_account],
[ET_debit_base_amount],
[ET_credit_base_amount],
[ET_reconciliation_base_amount]
);
END;
GO
-- NCIX_Document_header_COL_DH_predefined_entry
IF INDEXPROPERTY(OBJECT_ID('dbo.Document_header'), 'NCIX_Document_header_COL_DH_predefined_entry' , 'IndexID' ) IS NOT NULL
BEGIN;
PRINT 'idx NCIX_Document_header_COL_DH_predefined_entry drop'
DROP INDEX dbo.Document_header.NCIX_Document_header_COL_DH_predefined_entry;
END;
GO
IF INDEXPROPERTY(OBJECT_ID('dbo.Document_header'), 'NCIX_Document_header_COL_DH_predefined_entry' , 'IndexID' ) IS NULL
BEGIN;
PRINT 'idx NCIX_Document_header_COL_DH_predefined_entry create'
CREATE INDEX NCIX_Document_header_COL_DH_predefined_entry ON dbo.Document_header(DH_predefined_entry, DH_state) INCLUDE(Document_header_ID, DH_doc_date);
END;
GO

View File

@@ -0,0 +1,94 @@
USE [Arizona];
BEGIN TRANSACTION;
SET XACT_ABORT ON;
DECLARE
@mode INT = 2 /* 1 = SELECT / 2 = UPDATE */
,@cvRecordIDLowerLimit INT;
BEGIN TRY
SELECT @cvRecordIDLowerLimit = [bapd].[BAPD_value]
FROM [dbo].[Bmc_application_key] [bapk] (NOLOCK)
JOIN [dbo].[Bmc_application_default] [bapd] (NOLOCK)
ON [bapd].[BAPD_bmc_application_key] = [bapk].[Bmc_application_key_ID]
WHERE [bapk].[BAPK_key] = 'cvRecordIDLowerLimit';
CREATE TABLE [#temp_address] (
[Address_ID] INT
,[AD_last_name] VARCHAR(30)
,[ad_first_name] VARCHAR(30)
,[ad_name] VARCHAR(60)
,[ad_name_supplement] VARCHAR(255)
,[ad_vguid] UNIQUEIDENTIFIER
);
INSERT INTO [#temp_address] (
[Address_ID]
,[AD_last_name]
,[ad_first_name]
,[ad_name]
,[ad_name_supplement]
,[ad_vguid]
)
SELECT
[ad].[Address_ID]
,[ad].[AD_last_name]
,[ad].[AD_first_name]
,[ad].[AD_name]
,[ad].[AD_name_supplement]
,[ad].[AD_VGUID]
FROM [Arizona].[dbo].[Customer] [cust] (NOLOCK)
JOIN [Arizona].[dbo].[Address] [ad] (NOLOCK)
ON [ad].[Address_ID] = [cust].[CUST_address]
AND [ad].[Address_ID] >= @cvRecordIDLowerLimit;
UPDATE [t1]
SET
[t1].[AD_last_name] = [t2].[AD_last_name]
,[t1].[ad_name] = LEFT(ISNULL([t2].[AD_last_name], '') + ' ' + ISNULL([t1].[ad_first_name], ''), 60)
FROM [#temp_address] [t1] (NOLOCK)
JOIN [#temp_address] [t2] (NOLOCK)
ON [t2].[Address_ID] = (
SELECT TOP 1
[t3].[Address_ID]
FROM [#temp_address] [t3] (NOLOCK)
WHERE [t3].[Address_ID] > [t1].[Address_ID]
ORDER BY NEWID()
);
IF @mode = 2
BEGIN
UPDATE [ad]
SET
[ad].[AD_last_name] = [t1].[AD_last_name]
,[ad].[AD_name] = [t1].[ad_name]
FROM [#temp_address] [t1] (NOLOCK)
JOIN [dbo].[Address] [ad] (NOLOCK)
ON [ad].[Address_ID] = [t1].[Address_ID]
WHERE ISNULL([ad].[AD_last_name], '') <> ISNULL([t1].[AD_last_name], '')
OR ISNULL([ad].[AD_name], '') <> ISNULL([t1].[ad_name], '');
END
ELSE
BEGIN
SELECT --top 100
[ad].[AD_last_name]
,'-->'
,[t1].[AD_last_name]
,[ad].[AD_name]
,'-->'
,[t1].[ad_name]
FROM [#temp_address] [t1] (NOLOCK)
JOIN [dbo].[Address] [ad] (NOLOCK)
ON [ad].[Address_ID] = [t1].[Address_ID]
WHERE ISNULL([ad].[AD_last_name], '') <> ISNULL([t1].[AD_last_name], '')
OR ISNULL([ad].[AD_name], '') <> ISNULL([t1].[ad_name], '');
END; /* @mode = 2 */
DROP TABLE [#temp_address];
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE()
PRINT 'on line '+CAST(ERROR_LINE() AS VARCHAR(6))
ROLLBACK TRANSACTION
END CATCH

View File

@@ -0,0 +1,27 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-352 - Anonymize data on 888 environments", "OCTPDBA-352 - Anonymize data on 888 environments.ssmssqlproj", "{0C39E624-3849-4D70-B06D-C91E54E192AE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5BBD3D1F-889A-4164-9FEF-3877628F9609}"
ProjectSection(SolutionItems) = preProject
Mélanger noms et prénoms.sql = Mélanger noms et prénoms.sql
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C39E624-3849-4D70-B06D-C91E54E192AE}.Default|Default.ActiveCfg = Default
{6F0E9359-ADBB-43CA-9DC0-02439CB4FEEA}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5C8AC2AD-00EE-460F-BFA5-766D45D3C722}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-352 - Anonymize data on 888 environments">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="ama888aps.amavita.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-12-09T08:23:04.5768114+01:00</Created>
<Type>SQL</Type>
<Server>ama888aps.amavita.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName />
</ConnectionNode>
<ConnectionNode Name="cvi888aps.coop-vitality.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-12-09T08:22:56.0060079+01:00</Created>
<Type>SQL</Type>
<Server>cvi888aps.coop-vitality.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName />
</ConnectionNode>
<ConnectionNode Name="sun888aps.sunstore.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-12-09T08:23:11.8639922+01:00</Created>
<Type>SQL</Type>
<Server>sun888aps.sunstore.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName />
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items />
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-353 - check commvault bckps", "OCTPDBA-353 - check commvault bckps.ssmssqlproj", "{08AAA460-70F1-4355-8AA1-3E31479AFD05}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09679D02-BCF2-44B5-AC03-534D21ECA9ED}.Default|Default.ActiveCfg = Default
{08AAA460-70F1-4355-8AA1-3E31479AFD05}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FEF0AF96-E9E8-4E0C-B875-6DBDBD774AA7}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
<Items>
<LogicalFolder Name="Connections" Type="2" />
<LogicalFolder Name="Queries" Type="0" />
<LogicalFolder Name="Miscellaneous" Type="3" />
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,270 @@
/*
Server: ssunb006db01.sunstore.ch
Format: GCM
Business: TPPHAR
type: VALI
Version: 22.1.11010.00065
24.10.2022, TSC
*/
USE master;
BEGIN TRANSACTION;
SET XACT_ABORT ON;
SET NOCOUNT ON;
--#region variables
DECLARE @dbs TABLE (dbName VARCHAR(400),
have_commvault_bkp BIT
DEFAULT 0,
have_system_bkp BIT
DEFAULT 0,
last_system_backup DATETIME,
backup_type VARCHAR(50) NULL);
DECLARE @tbl_log_msg TABLE (tstamp DATETIME NOT NULL
DEFAULT CURRENT_TIMESTAMP,
msg VARCHAR(500) NOT NULL);
--#endregion
--#region fetch list of db's
INSERT INTO @dbs (dbName)
SELECT name
FROM sys.databases d
WHERE name NOT IN ( N'master', N'tempdb', N'model', N'msdb' );
--#endregion
--#region fetch backups in the last week
IF OBJECT_ID('tempdb..#bkps') IS NOT NULL
BEGIN
DROP TABLE #bkps;
END
SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SERVER,
bs.database_name,
bs.backup_start_date,
bs.backup_finish_date,
bs.expiration_date,
bs.backup_size,
mf.logical_device_name,
mf.physical_device_name,
bs.name AS backupset_name,
bs.description,
CASE
WHEN bs.type = 'D' THEN 'Database'
WHEN bs.type = 'I' THEN 'Differential'
WHEN bs.type = 'L' THEN 'Log'
WHEN bs.type = 'F' THEN 'File or filegroup'
WHEN bs.type = 'G' THEN 'Differential file'
WHEN bs.type = 'P' THEN 'Partial'
WHEN bs.type = 'Q' THEN 'Differential partial'
ELSE 'Unknown' END AS backup_type,
CASE
WHEN CHARINDEX(':', mf.physical_device_name, 0) > 0 THEN 1
WHEN mf.logical_device_name IS NOT NULL THEN 2
ELSE 0 END AS to_file,
CASE
WHEN bs.name LIKE '%commvault%'
AND CHARINDEX(':', mf.physical_device_name, 0) = 0
AND mf.logical_device_name IS NULL THEN 1
ELSE 0 END AS is_commVault_bkp
INTO #bkps
FROM msdb.dbo.backupmediafamily mf
INNER JOIN msdb.dbo.backupset bs
ON mf.media_set_id = bs.media_set_id
WHERE (CONVERT(DATETIME, bs.backup_start_date, 102) >= GETDATE() - 7)
AND bs.type = 'D' --ignore log backups
ORDER BY bs.database_name,
bs.backup_finish_date;
--#endregion
--#region Look for commvault backups for each databases
UPDATE d
SET d.have_commvault_bkp = 1,
d.backup_type = b.backup_type
FROM @dbs d
INNER JOIN #bkps b
ON b.database_name = d.dbName
WHERE b.is_commVault_bkp = 1;
--#endregion
--#region Look for system backups for each databases
UPDATE d
SET d.have_system_bkp = 1,
d.last_system_backup = lastBkp.backup_finish_date,
d.backup_type = b.backup_type
FROM @dbs d
INNER JOIN #bkps b
ON b.database_name = d.dbName
INNER JOIN ( SELECT b2.database_name,
MAX(b2.backup_finish_date) AS backup_finish_date
FROM #bkps b2
GROUP BY b2.database_name) lastBkp
ON lastBkp.database_name = b.database_name
WHERE b.is_commVault_bkp = 0;
--#endregion
SELECT d.dbName,
d.have_commvault_bkp,
d.have_system_bkp,
d.last_system_backup,
d.backup_type
FROM @dbs d;
--#region check if we are on a REF or AAI server
DECLARE @is_ref_srv BIT = 0;
DECLARE @is_aai_srv BIT = 0;
IF (@@SERVERNAME IN (
--sun
'ssunbrefde02.sunstore.ch\apssql', 'ssunbrefde02\apssql', 'ssunbreffr02.sunstore.ch\apssql', 'ssunbreffr02\apssql',
--cvi
'scvnbrefdb01.coop-vitality.ch\apssql', 'scvnbrefdb01\apssql', 'scvnbrefdb02.coop-vitality.ch\apssql', 'scvnbrefdb02\apssql',
--ama
'samnbrefde02.amavita.ch\apssql', 'samnbrefde02\apssql', 'samnbreffr02.amavita.ch\apssql', 'samnbreffr02\apssql',
--aai, should not be used anyhow
'saainbref02.aai.local\apssql', 'saainbref02\apssql'))
BEGIN
SET @is_ref_srv = 1;
PRINT 'We are on a REF server.';
END
IF(OBJECT_ID('master.cfg.Identity'))IS NOT NULL BEGIN
IF EXISTS(SELECT 1 FROM master.cfg.[Identity] [i] WHERE i.[Format] = 'AAI')
BEGIN
SET @is_aai_srv = 1;
PRINT 'We are on a AAI server.'
END
END
ELSE BEGIN
PRINT 'No table identity in master, skipping AAI detection.'
END
--#endregion
--#region populate list of jobs to drop and fetch job_id
DECLARE @tbl_job_name TABLE (job_id UNIQUEIDENTIFIER NULL,
job_name VARCHAR(500) NOT NULL,
treated BIT NOT NULL
DEFAULT 0);
INSERT INTO @tbl_job_name (job_name)
VALUES ('D91040 - Backup of simple databases'),
('D91050 - Backup of full databases'),
('D91010 - Backup of several databases'),
('DR91020 - Log-backup');
UPDATE tjn
SET tjn.job_id = j.job_id
FROM msdb.dbo.sysjobs j
INNER JOIN @tbl_job_name tjn
ON tjn.job_name = j.name;
--#endregion
--#region Check for unknown backup job
INSERT INTO @tbl_log_msg (tstamp,msg)
SELECT DISTINCT
CURRENT_TIMESTAMP AS tstamp,
'job doing a "backup database ... to file" ' + j.name AS msg
--SELECT
-- DISTINCT 'Jobs making a backup not in the recognized jobs' AS msg,
-- j.name,
-- j.enabled,
-- s.schedule_id,
-- LTRIM(SUBSTRING(js.command, CHARINDEX('to disk', js.command) - 40, 100)) AS command_fragment
FROM msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobsteps js
ON js.job_id = j.job_id
INNER JOIN msdb.dbo.sysjobschedules s
ON s.job_id = j.job_id
WHERE js.command LIKE '%backup database%to disk%'
AND j.name <> 'D91030 - Backup ActivePos_Read'
AND NOT EXISTS (SELECT 1 FROM @tbl_job_name tjn WHERE tjn.job_name = j.name);
--#endregion
--#region check that all db's have commvault backups before dropping jobs
DECLARE @is_commvault_active BIT = 0;
SELECT @is_commvault_active = CASE
WHEN MAX(dbCnt.cnt) = COUNT(1) AND MAX(dbCnt.cnt) > 0 THEN 1
ELSE 0
END
FROM @dbs d
CROSS APPLY (
SELECT COUNT(1) AS cnt
FROM @dbs d2
) AS dbCnt
WHERE d.have_commvault_bkp = 1
;
If @is_commvault_active = 0
PRINT 'Commvault is not active on all db''s.'
--#endregion
IF @is_ref_srv = 0 AND @is_aai_srv = 0 AND @is_commvault_active = 1
BEGIN
--#region delete jobs known to be stopped
/* declare variables */
DECLARE @job_id UNIQUEIDENTIFIER,
@job_name VARCHAR(500);
DECLARE delDisabledBkpJob CURSOR FAST_FORWARD READ_ONLY FOR
SELECT tjn.job_id,
tjn.job_name
FROM @tbl_job_name tjn
WHERE tjn.treated = 0
AND tjn.job_id IS NOT NULL;
OPEN delDisabledBkpJob;
FETCH NEXT FROM delDisabledBkpJob
INTO @job_id,
@job_name;
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC msdb.dbo.sp_delete_job @job_id = @job_id, -- uniqueidentifier
@job_name = NULL, -- sysname
@originating_server = NULL, -- sysname
@delete_history = 1, -- bit
@delete_unused_schedule = 1; -- bit
INSERT INTO @tbl_log_msg (tstamp,msg)
VALUES (GETDATE(), 'Dropped job ' + @job_name);
UPDATE @tbl_job_name
SET treated = 1
WHERE job_id = @job_id;
PRINT 'Deleted job ' + @job_name + ' (job id: ' + CONVERT(VARCHAR(100), @job_id) + ')';
FETCH NEXT FROM delDisabledBkpJob
INTO @job_id,
@job_name;
END
CLOSE delDisabledBkpJob;
DEALLOCATE delDisabledBkpJob;
--#endregion
END
ELSE BEGIN
INSERT INTO @tbl_log_msg (tstamp,msg)
SELECT
CURRENT_TIMESTAMP
,CASE
WHEN @is_ref_srv = 1 THEN 'Not dropping jobs on pharmacy reference servers...'
WHEN @is_aai_srv = 1 THEN 'Not dropping jobs on AAI servers...'
WHEN @is_commvault_active = 0 THEN 'Not dropping jobs where CommVault is not active...'
ELSE 'Skipping job deletion'
END AS msg
;
END
SELECT
tld.tstamp,
tld.msg
FROM @tbl_log_msg tld;
ROLLBACK TRANSACTION;

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-359 - CommVault log backup frequency", "OCTPDBA-359 - CommVault log backup frequency.ssmssqlproj", "{B7D2025A-A374-467C-A4FA-C449E6B095EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B7D2025A-A374-467C-A4FA-C449E6B095EE}.Default|Default.ActiveCfg = Default
{E88413B5-F896-4F4F-949E-7D4C1D41FD44}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {762276EF-25EE-45B8-B8FA-487705F4CAA0}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,58 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-359 - CommVault log backup frequency">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="ama293aps.amavita.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-10-31T16:27:08.1953456+01:00</Created>
<Type>SQL</Type>
<Server>ama293aps.amavita.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
<ConnectionNode Name="sun008aps.sunstore.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-10-31T09:33:53.6641248+01:00</Created>
<Type>SQL</Type>
<Server>sun008aps.sunstore.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB>ActivePos_read</InitialDB>
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
<ConnectionNode Name="sun211aps.sunstore.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-10-31T16:26:06.3401914+01:00</Created>
<Type>SQL</Type>
<Server>sun211aps.sunstore.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="check bkp frequency.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:ama293aps.amavita.ch\apssql:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>ama293aps.amavita.ch\apssql</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>check bkp frequency.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,98 @@
/*
Server: ssunb008vm01.sunstore.ch
Format: GCM
Business: TPPHAR
type: DEVE
Version: 23.1.10015.00066
31.10.2022, TSC
*/
SET XACT_ABORT ON;
SET NOCOUNT ON;
IF OBJECT_ID('tempdb..#bkps') IS NOT NULL
BEGIN
DROP TABLE #bkps;
END;
SELECT DISTINCT
CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SERVER,
bs.[database_name],
bs.backup_start_date,
bs.backup_finish_date,
bs.backup_size,
bs.[name] AS backupset_name,
bs.[description],
CASE
WHEN bs.TYPE = 'D' THEN 'Full'
WHEN bs.TYPE = 'I' THEN 'Differential'
WHEN bs.TYPE = 'L' THEN 'Log'
WHEN bs.TYPE = 'F' THEN 'File or filegroup'
WHEN bs.TYPE = 'G' THEN 'Differential file'
WHEN bs.TYPE = 'P' THEN 'Partial'
WHEN bs.TYPE = 'Q' THEN 'Differential partial'
ELSE 'Unknown' END AS backup_type
,ROW_NUMBER()OVER(PARTITION BY bs.[database_name], bs.TYPE ORDER BY bs.backup_start_date) AS rid
INTO #bkps
FROM msdb.[dbo].backupset bs
WHERE (CONVERT(DATETIME, bs.backup_start_date, 102) >= DATEADD(DAY, -7, CURRENT_TIMESTAMP))
AND bs.[name] LIKE '%commvault%'
AND bs.[database_name] NOT IN ('model','msdb','master','tempdb','HCITools')
/*AND (
bs.database_name LIKE 'arizona%'
OR bs.database_name LIKE 'activepos%'
)
*/
;
WITH chkFull AS (
SELECT b.SERVER
,b.[database_name]
,b.backup_start_date
,b.backup_finish_date
,b.backup_size
,b.backupset_name
,b.[description]
,b.backup_type
,b.rid
,hiera = 1
,CAST(NULL AS INT) AS delta_min
FROM #bkps b
WHERE b.rid = 1
UNION ALL
SELECT b.SERVER
,b.[database_name]
,b.backup_start_date
,b.backup_finish_date
,b.backup_size
,b.backupset_name
,b.[description]
,b.backup_type
,b.rid
,p.hiera + 1 AS hiera
,DATEDIFF(MINUTE, p.backup_start_date, b.backup_start_date) AS delta_min
FROM chkFull p
INNER JOIN #bkps b
ON b.[database_name] = p.[database_name]
AND b.backup_type = p.backup_type
AND b.rid = p.rid + 1
)
SELECT
f.[database_name]
, f.backup_type
, SUM(CAST(CAST(f.delta_min AS NUMERIC(12,2)) / 60 AS NUMERIC(12,2))) / COUNT(1) AS mean_delta_hour
FROM chkFull f
WHERE 1=1
GROUP BY f.[database_name], f.backup_type
OPTION(MAXRECURSION 5000);
SELECT *
FROM #bkps b
WHERE b.backup_type = 'log'
AND b.[database_name]='arizona'
ORDER BY b.[database_name] ASC, b.rid ASC
;

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-365 Check index usage stats of [Entry] table", "OCTPDBA-365 Check index usage stats of [Entry] table.ssmssqlproj", "{E04A24E8-E4A1-425A-8196-6773BE0C4FB7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E04A24E8-E4A1-425A-8196-6773BE0C4FB7}.Default|Default.ActiveCfg = Default
{A53850FA-C396-4B1D-A94D-52E99FD87951}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17EEE1F6-27D6-4E4A-B903-570D9844FE78}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,70 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-365 Check index usage stats of [Entry] table">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="(local):CENTRALINFRA\ua208700">
<Created>2022-12-06T13:24:23.3133285+01:00</Created>
<Type>SQL</Type>
<Server>(local)</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
<ConnectionNode Name="ama001aps\apssql:CENTRALINFRA\ua208700">
<Created>2022-12-06T11:15:49.8449403+01:00</Created>
<Type>SQL</Type>
<Server>ama001aps\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
<ConnectionNode Name="sun008aps.sunstore.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-11-07T09:36:04.9485106+01:00</Created>
<Type>SQL</Type>
<Server>sun008aps.sunstore.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="idx usage with definition.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:sun008aps.sunstore.ch\apssql:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>sun008aps.sunstore.ch\apssql</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>idx usage with definition.sql</FullPath>
</FileNode>
<FileNode Name="maintain entry indexes.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>maintain entry indexes.sql</FullPath>
</FileNode>
<FileNode Name="Search table in dbs.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>Search table in dbs.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,51 @@
/*
Server: HCIMON
Format: HCI
Business: OTHER
type: PROD
Version: No Arizona db on this instance
01.11.2022, TSC
*/
USE master;
DECLARE @dbs TABLE([name] VARCHAR(100));
DECLARE @results TABLE([schema] VARCHAR(100), [table] VARCHAR(100), [db_name] VARCHAR(100));
DECLARE @keyword VARCHAR(100) = 'batch';
DECLARE @query VARCHAR(MAX);
DECLARE @tpl VARCHAR(MAX)=' USE @db@;
SELECT DISTINCT c.TABLE_SCHEMA, c.TABLE_NAME, DB_NAME()
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.TABLE_NAME LIKE ''%@keyword@%'' ';
INSERT INTO @dbs([name])
SELECT db.name
FROM sys.databases db
WHERE db.database_id > 4;
/* declare variables */
DECLARE @db_name VARCHAR(MAX);
DECLARE scan_db CURSOR FAST_FORWARD READ_ONLY FOR
SELECT [name] FROM @dbs d
OPEN scan_db
FETCH NEXT FROM scan_db INTO @db_name
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @query = REPLACE(REPLACE(@tpl,'@keyword@', @keyword), '@db@', @db_name);
INSERT INTO @results ([schema], [table], [db_name])
EXEC(@query);
FETCH NEXT FROM scan_db INTO @db_name
END
CLOSE scan_db
DEALLOCATE scan_db
SELECT *
FROM @results r;

View File

@@ -0,0 +1,165 @@
/*
Server: sun791aps.sunstore.ch
Format: GCM
Business: TPPHAR
type: PROD
Version: 21.3.11111.00064
02.11.2022, TSC
*/
USE [Arizona];
BEGIN TRANSACTION;
SET XACT_ABORT ON;
SET NOCOUNT ON;
DECLARE @index_to_drop TABLE ([columns_in_index] VARCHAR(MAX) NOT NULL,
[index_name] VARCHAR(500) NULL);
INSERT @index_to_drop ([columns_in_index])
VALUES ('ET_APS_TS'),
('ET_entry_address'),
('ET_entry_type'),
('ET_master_ID'),
('ET_predefined_entry'),
('ET_sales_tax_code'),
('ET_bmc_user_profile'),
('ET_currency');
/* find index name with defined columns */
WITH [ColInfo]
AS (SELECT [o].[name] AS [TblName],
[s].[name] + '.' + [o].[name] AS [SchemaTbl],
[i].[name] AS [IndexName],
[i].[is_primary_key] AS [IsPrimaryKey],
[i].[is_unique_constraint] AS [IsUniqueConstraint],
[i].[is_unique] AS [IsUnique],
[c].[name] AS [ColName],
[c].[is_computed] AS [IsComputedCol],
[ic].[is_included_column] AS [IsIncludedCol],
[ic].[key_ordinal],
[i].[filter_definition] AS [FilterDefinition],
CHAR(13) + CHAR(10) AS [crlf],
';' + CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) AS [crlfgo]
FROM [sys].[objects] [o]
INNER JOIN [sys].[schemas] [s]
ON [o].[schema_id] = [s].[schema_id]
INNER JOIN [sys].[columns] [c]
ON [o].[object_id] = [c].[object_id]
INNER JOIN [sys].[indexes] [i]
ON [c].[object_id] = [i].[object_id]
INNER JOIN [sys].[index_columns] [ic]
ON [i].[index_id] = [ic].[index_id]
AND [o].[object_id] = [ic].[object_id]
AND [c].[column_id] = [ic].[column_id]
WHERE [o].[name] = 'entry'
--AND i.filter_definition IS NOT NULL
)
--SELECT itd.columns_in_index
-- ,itd.index_name
-- ,lst.IndexName
-- ,lst.IndexColumns
-- ,lst.IncludedColumns
UPDATE [itd]
SET [itd].[index_name] = [lst].[IndexName]
FROM ( SELECT DISTINCT [x].[TblName],
[x].[IndexName],
[x].[IsPrimaryKey],
[x].[IsUniqueConstraint],
[x].[IsUnique],
--,size.IndexSizeKB
[c].[IndexColumns],
[ci].[IncludedColumns],
[cc].[ComputedColumns],
[x].[FilterDefinition],
[x].[crlf] + '-- ' + [x].[IndexName] + [x].[crlf] +
--check drop
'IF INDEXPROPERTY(OBJECT_ID(''' + [x].[SchemaTbl] + '''), ''' + [x].[IndexName]
+ ''' , ''IndexID'' ) IS NOT NULL BEGIN;' + [x].[crlf]
+ CASE
WHEN [x].[IsPrimaryKey] = 1 THEN NULL
WHEN [x].[IsUniqueConstraint] = 1 THEN
--drop statement
' ALTER TABLE ' + [x].[SchemaTbl] + ' DROP CONSTRAINT ' + [x].[IndexName] + ';'
+ [x].[crlf] + 'END' + [x].[crlfgo]
--check create
+ 'IF INDEXPROPERTY(OBJECT_ID(''' + [x].[SchemaTbl] + '''), ''' + [x].[IndexName]
+ ''' , ''IndexID'' ) IS NULL BEGIN;' + [x].[crlf] +
--create statement
+' ALTER TABLE '
+ [x].[SchemaTbl] + ' ADD CONSTRAINT ' + [x].[IndexName] + ' UNIQUE ('
+ [c].[IndexColumns] + ');' + [x].[crlf] + 'END' + [x].[crlfgo]
ELSE
--drop statement
' DROP INDEX ' + [x].[SchemaTbl] + '.' + [x].[IndexName] + ';' + [x].[crlf]
+ 'END' + [x].[crlfgo]
--check create
+ 'IF INDEXPROPERTY(OBJECT_ID(''' + [x].[SchemaTbl] + '''), ''' + [x].[IndexName]
+ ''' , ''IndexID'' ) IS NULL BEGIN;' + [x].[crlf] +
--create statement
+' CREATE '
+ CASE
WHEN [x].[IsUnique] = 1 THEN 'UNIQUE '
ELSE '' END + 'INDEX ' + [x].[IndexName] + ' ON ' + [x].[SchemaTbl] + '('
+ [c].[IndexColumns] + ')'
+ ISNULL(' INCLUDE(' + [ci].[IncludedColumns] + ')', '')
+ ISNULL(' WHERE ' + [x].[FilterDefinition], '') + ';' + [x].[crlf] + 'END'
+ [x].[crlfgo] END AS [DropCreateSQL]
FROM [ColInfo] [x]
CROSS APPLY ( SELECT STUFF([sq].[strXML], 1, 2, '') AS [IndexColumns]
FROM ( SELECT ', ' + ISNULL([x2].[ColName], '')
FROM [ColInfo] [x2]
WHERE [x].[TblName] = [x2].[TblName]
AND [x].[IndexName] = [x2].[IndexName]
AND [x2].[IsIncludedCol] = 0
ORDER BY [x2].[key_ordinal]
FOR XML PATH('')) [sq]([strXML]) ) [c]
OUTER APPLY ( SELECT STUFF([sq].[strXML], 1, 2, '') AS [IncludedColumns]
FROM ( SELECT ', ' + ISNULL([x2].[ColName], '')
FROM [ColInfo] [x2]
WHERE [x].[TblName] = [x2].[TblName]
AND [x].[IndexName] = [x2].[IndexName]
AND [x2].[IsIncludedCol] = 1
ORDER BY [x2].[key_ordinal]
FOR XML PATH('')) [sq]([strXML]) ) [ci]
OUTER APPLY ( SELECT STUFF([sq].[strXML], 1, 2, '') AS [ComputedColumns]
FROM ( SELECT ', ' + ISNULL([x2].[ColName], '')
FROM [ColInfo] [x2]
WHERE [x].[TblName] = [x2].[TblName]
AND [x].[IndexName] = [x2].[IndexName]
AND [x2].[IsComputedCol] = 1
ORDER BY [x2].[key_ordinal]
FOR XML PATH('')) [sq]([strXML]) ) [cc] ) [lst]
INNER JOIN @index_to_drop [itd]
ON [lst].[IndexColumns] = [itd].[columns_in_index];
SELECT *
FROM @index_to_drop [itd];
/* declare variables */
DECLARE @index_name VARCHAR(MAX);
DECLARE [drop_index] CURSOR LOCAL FAST_FORWARD READ_ONLY FOR
SELECT [itd].[index_name]
FROM @index_to_drop [itd]
WHERE [itd].[index_name] IS NOT NULL;
OPEN [drop_index];
FETCH NEXT FROM [drop_index]
INTO @index_name;
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC ('DROP INDEX ' + @index_name + ' ON dbo.entry;');
FETCH NEXT FROM [drop_index]
INTO @index_name;
END;
CLOSE [drop_index];
DEALLOCATE [drop_index];
ROLLBACK TRANSACTION;

View File

@@ -0,0 +1,343 @@
/*
Server: ssunb008vm01.sunstore.ch
Format: GCM
Business: TPPHAR
type: DEVE
Version: 23.1.10016.00066
01.11.2022, TSC
*/
USE Arizona;
BEGIN TRANSACTION;
SET XACT_ABORT ON;
SET NOCOUNT ON;
IF OBJECT_ID('tempdb..#chkRes') IS NOT NULL BEGIN;
DROP TABLE #chkRes;
END
DECLARE @ref_schema VARCHAR(50) = 'dbo';
DECLARE @ref_table VARCHAR(100) = 'entry';
CREATE TABLE #chkRes (
tbl_name NVARCHAR(128) NOT NULL
,[schema_name] VARCHAR(50) NOT NULL
,[type] CHAR(2) NULL
,index_name NVARCHAR(128) NULL
,[index_id] INT NOT NULL
,[Reads] BIGINT NOT NULL
,[Writes] BIGINT NOT NULL
,[delta] BIGINT NOT NULL
,[index_type] NVARCHAR(60) NULL
,[FillFactor] TINYINT NULL
,[has_filter] BIT NOT NULL
,[filter_definition] NVARCHAR(MAX) NULL
,[last_user_scan] DATETIME NULL
,[last_user_lookup] DATETIME NULL
,[last_user_seek] DATETIME NULL
,[IndexColumns] NVARCHAR(MAX) NULL
,[IncludedColumns] NVARCHAR(MAX) NULL
,[primary_table] NVARCHAR(500) NULL
,[pk_column_name] NVARCHAR(128) NULL
,[fk_constraint_name] NVARCHAR(128) NULL
,comp_drop_cmd AS 'DROP INDEX ' + index_name + ' ON ' + [schema_name] + '.' + tbl_name + ';'
);
;WITH ColInfo
AS (
SELECT
o.name AS TblName
,s.name + '.' + o.name AS SchemaTbl
,i.name AS IndexName
,i.is_primary_key AS IsPrimaryKey
,i.is_unique_constraint AS IsUniqueConstraint
,i.is_unique AS IsUnique
,c.name AS ColName
,c.is_computed AS IsComputedCol
,ic.is_included_column AS IsIncludedCol
,ic.key_ordinal
,i.filter_definition AS FilterDefinition
FROM sys.objects o
INNER JOIN sys.schemas s
ON o.schema_id = s.schema_id
INNER JOIN sys.columns c
ON o.object_id = c.object_id
INNER JOIN sys.indexes i
ON c.object_id = i.object_id
INNER JOIN sys.index_columns ic
ON i.index_id = ic.index_id
AND o.object_id = ic.object_id
AND c.column_id = ic.column_id
)
--- Index Read/Write stats (all tables in current DB) ordered by Reads (Query 62) (Overall Index Usage - Reads)
INSERT INTO #chkRes (
tbl_name
,[schema_name]
,[type]
,index_name
,index_id
,Reads
,Writes
,delta
,index_type
,[FillFactor]
,has_filter
,filter_definition
,last_user_scan
,last_user_lookup
,last_user_seek
,IndexColumns
,IncludedColumns
,primary_table
,pk_column_name
,fk_constraint_name
)
SELECT
o.name AS [tbl_Name]
,SCHEMA_NAME(o.schema_id) AS [schema_name]
,o.type
,i.name AS [index_name]
,i.index_id
,user_seeks + user_scans + user_lookups AS [Reads]
,s.user_updates AS [Writes]
,CASE
WHEN s.user_updates > user_seeks + user_scans + user_lookups THEN
s.user_updates - (user_seeks + user_scans + user_lookups)
ELSE (user_seeks + user_scans + user_lookups) - s.user_updates
END AS delta
,i.type_desc AS [index_type]
,i.fill_factor AS [fill_factor]
,i.has_filter
,i.filter_definition
,s.last_user_scan
,s.last_user_lookup
,s.last_user_seek
,idx_cols.IndexColumns
,idx_cols.IncludedColumns
,fk.primary_table
,fk.pk_column_name
,fk.fk_constraint_name
FROM sys.dm_db_index_usage_stats AS s WITH (NOLOCK)
INNER JOIN sys.indexes AS i WITH (NOLOCK)
ON s.object_id = i.object_id
INNER JOIN sys.objects o WITH (NOLOCK)
ON s.object_id = o.object_id
OUTER APPLY (
SELECT DISTINCT
x.TblName
,x.IndexName
,x.IsPrimaryKey
,x.IsUniqueConstraint
,x.IsUnique
--,size.IndexSizeKB
,c.IndexColumns
,ci.IncludedColumns
,cc.ComputedColumns
,x.FilterDefinition
FROM ColInfo x
CROSS APPLY (
SELECT STUFF(sq.strXML, 1, 2, '') AS IndexColumns
FROM (
SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName
AND x.IndexName = x2.IndexName
AND x2.IsIncludedCol = 0
ORDER BY x2.key_ordinal
FOR XML PATH('')
) sq(strXML)
) c
OUTER APPLY (
SELECT STUFF(sq.strXML, 1, 2, '') AS IncludedColumns
FROM (
SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName
AND x.IndexName = x2.IndexName
AND x2.IsIncludedCol = 1
ORDER BY x2.key_ordinal
FOR XML PATH('')
) sq(strXML)
) ci
OUTER APPLY (
SELECT STUFF(sq.strXML, 1, 2, '') AS ComputedColumns
FROM (
SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName
AND x.IndexName = x2.IndexName
AND x2.IsComputedCol = 1
ORDER BY x2.key_ordinal
FOR XML PATH('')
) sq(strXML)
) cc
WHERE x.TblName = o.name
AND x.IndexName = i.name
) idx_cols
LEFT OUTER JOIN (
SELECT
SCHEMA_NAME(tab.schema_id) + '.' + tab.name AS [table]
,col.column_id
,col.name AS column_name
,CASE
WHEN fk.object_id IS NOT NULL THEN '>-'
ELSE NULL
END AS rel
,SCHEMA_NAME(pk_tab.schema_id) + '.' + pk_tab.name AS primary_table
,pk_col.name AS pk_column_name
,fk_cols.constraint_column_id AS NO
,fk.name AS fk_constraint_name
,tab.name AS tbl_name
FROM sys.tables tab
INNER JOIN sys.columns col
ON col.object_id = tab.object_id
LEFT OUTER JOIN sys.foreign_key_columns fk_cols
ON fk_cols.parent_object_id = tab.object_id
AND fk_cols.parent_column_id = col.column_id
LEFT OUTER JOIN sys.foreign_keys fk
ON fk.object_id = fk_cols.constraint_object_id
LEFT OUTER JOIN sys.tables pk_tab
ON pk_tab.object_id = fk_cols.referenced_object_id
LEFT OUTER JOIN sys.columns pk_col
ON pk_col.column_id = fk_cols.referenced_column_id
AND pk_col.object_id = fk_cols.referenced_object_id
WHERE fk.object_id IS NOT NULL
) fk
ON fk.tbl_name = o.name
AND idx_cols.IndexColumns LIKE '%' + fk.column_name + '%'
WHERE o.type = 'U' -- user table
AND i.index_id = s.index_id
AND s.database_id = DB_ID()
AND o.name = @ref_table
AND SCHEMA_NAME(o.schema_id) = @ref_schema
ORDER BY delta DESC
--ORDER BY user_seeks + user_scans + user_lookups DESC -- Order by reads
--ORDER BY s.user_updates DESC OPTION -- Order by writes
OPTION (RECOMPILE);
/* list back data */
SELECT cr.tbl_name
,cr.[schema_name]
,cr.[type]
,cr.index_name
,cr.index_id
,cr.Reads
,cr.Writes
,cr.delta
,cr.index_type
,cr.[FillFactor]
,cr.has_filter
,cr.filter_definition
,cr.last_user_scan
,cr.last_user_lookup
,cr.last_user_seek
,cr.IndexColumns
,cr.IncludedColumns
,cr.primary_table
,cr.pk_column_name
,cr.fk_constraint_name
FROM #chkRes cr
ORDER BY IndexColumns
;
ROLLBACK TRANSACTION
RETURN
--/* Check if index with FK are in the list, alert if it's the case */
--IF EXISTS(
-- SELECT 1
-- FROM #chkRes cr
-- WHERE cr.Reads = 0 --not used
-- AND cr.Writes > 100 --but maintained
-- AND cr.fk_constraint_name IS NOT NULL --is part of a FK
--) BEGIN
-- SELECT
-- 'This index is tied to a column part of a FK, check if dropping is to be done.' AS msg
-- ,cr.[schema_name]
-- ,cr.tbl_name
-- ,cr.index_name
-- ,cr.Reads
-- ,cr.Writes
-- ,cr.primary_table
-- ,cr.pk_column_name
-- ,cr.fk_constraint_name
-- FROM #chkRes cr
-- WHERE cr.Reads = 0 --not used
-- AND cr.Writes > 100 --but maintained
-- AND cr.fk_constraint_name IS NOT NULL --is part of a FK
-- AND cr.index_type = 'NONCLUSTERED'
--END
--/* declare variables */
--DECLARE
-- @table_name VARCHAR(MAX)
-- ,@schema_name VARCHAR(20)
-- ,@index_name VARCHAR(500)
-- ,@drop_cmd VARCHAR(MAX)
-- ;
--DECLARE dropIdx CURSOR LOCAL FORWARD_ONLY FAST_FORWARD READ_ONLY FOR
-- SELECT
-- cr.tbl_name
-- ,cr.[schema_name]
-- ,cr.index_name
-- ,cr.comp_drop_cmd
-- FROM #chkRes cr
-- WHERE cr.Reads = 0 --not used on select
-- AND cr.Writes > 100 --but maintained on insert / update
-- AND cr.fk_constraint_name IS NULL --not part of a FK
-- AND cr.index_type = 'NONCLUSTERED' --ignore clustered & heaps
-- ;
--OPEN dropIdx;
--FETCH NEXT FROM dropIdx
--INTO
-- @table_name
-- ,@schema_name
-- ,@index_name
-- ,@drop_cmd
-- ;
--WHILE @@FETCH_STATUS = 0 BEGIN
-- PRINT @drop_cmd;--'Dropping index ' + @index_name + ' on ' + @schema_name + '.' + @table_name;
-- --EXEC(@drop_cmd);
-- FETCH NEXT FROM dropIdx
-- INTO
-- @table_name
-- ,@schema_name
-- ,@index_name
-- ,@drop_cmd
-- ;
--END
--CLOSE dropIdx;
--DEALLOCATE dropIdx;
--SELECT cr.tbl_name
-- ,cr.[schema_name]
-- ,cr.index_name
-- ,cr.Reads
-- ,cr.Writes
-- ,cr.delta
-- ,cr.index_type
-- ,cr.last_user_scan
-- ,cr.last_user_lookup
-- ,cr.last_user_seek
-- ,cr.IndexColumns
-- ,cr.IncludedColumns
-- ,cr.primary_table
-- ,cr.pk_column_name
-- ,cr.fk_constraint_name
--FROM #chkRes cr
--ORDER BY cr.delta DESC
--;
--ROLLBACK TRANSACTION;

View File

@@ -0,0 +1,686 @@
/*=============================================================================
Maintain and align indexes on Arizona.dbo.entry
TODO:
allow to skip INDEX DROP for unlisted indexes
Parameters
----------------------
Populate the var table @indexesToMaintains to drop / create and rename indexes to be aligned.
You need to specify those fields:
* schemaName, tableName: the schema and table name for which you want to maintain the indexes.
This script was written with working against several tables in mind, but is not (yet) tested to handle this case.
* columnsName: What columns are part of the index key, in the correct order
As we have divergent indexes names, we must use the index columns as the key to find the indexes.
* includedColumns_inp: if the index have included columns, list them here.
When an index is found, the included columns list it also compared to determine if the index is aligned.
* expectedIndexName_inp: The name the index should have. It will be used when creating missing indexes or renaming existing indexes
The index name is optionnal if we specify in the table that the index must be dropped.
* isToBeDeleted_inp: if true, indicate that the index should be dropped.
* isToBeRecreated_inp: if true, will drop and re-create the index even if the structure matches.
* isClustered_inp: if true and the index must be (re-)created, it will be created as a clustered index
* isUnique_inp: if true and the index must be (re-)created, it will be created as a unique index
Note that:
* Matching is always made from the columns of the index, never on the name of the index.
The reason is that we might have difference in the name of the index between several servers.
* If an index exists with the name A, but your list contains a similar index with the name B, index A will be renamed to B with sp_rename
* For each table(s) referenced in @indexesToMaintains, if an index exists that is not listed in the variable table it will be considered to be
dropped if @DoDropExistingIndexesNotReferenced is set to 1.
* If you list a specific existing index to be dropped in @indexesToMaintains then the following fields are optionnal:
expected index name
flag isClustered
flag isUnique
Context
----------------------
In any databases
Creation : 09.11.2022 / TSC
Modifications:
=============================================================================*/
USE [Arizona];
GO
BEGIN TRANSACTION;
SET XACT_ABORT ON;
SET NOCOUNT ON;
DECLARE @query VARCHAR(MAX); /* for dynamic sql */
DECLARE @schemaName VARCHAR(100); /* used in cursor */
DECLARE @tableName VARCHAR(100); /* used in cursor */
/*
If set to true, the script will not apply the change.
Generated statements are always printed on the message tab.
*/
DECLARE @DoOnlyOutputStatement BIT = 0;
/*
If the script find local indexes that are not listed in the variable table, should it drop them or not ?
An index whose definition is not aligned with the temp table or flagged "to be rebuilt" will always be dropped before creation.
*/
DECLARE @DoDropExistingIndexesNotReferenced BIT = 0;
DECLARE @indexesToMaintains TABLE(
[Id] INT IDENTITY NOT NULL
,[SchemaName] VARCHAR(100) NOT NULL /* the schema the table is part of */
,[TableName] VARCHAR(100) NOT NULL /* On which table is the index, whithout the schema */
,columnsName_inp VARCHAR(MAX) NOT NULL /* list all the columns of the index, in the correct orders */
,isClustered_inp BIT NOT NULL DEFAULT 0 /* Is the indexe a clustered index ? */
,isUnique_inp BIT NOT NULL DEFAULT 0 /* Is the index unique ? */
,includedColumns_inp VARCHAR(MAX)NULL /* list all the included columns the index should have. only relevant for idx not to be dropped */
,isToBeDeleted_inp BIT NOT NULL DEFAULT 0 /* must the script drop this index ? */
,isToBeRecreated_inp BIT NOT NULL DEFAULT 0 /* must the script recreate this index ?
If an existing index differs from the definition, it will be dropped and the correct one created.
Use this only to force the re-creation even if the structure is identical */
,expectedIndexName_inp VARCHAR(MAX) NULL /* the name the index should have, used to determine if a rename of the existing index should be done */
,indexName VARCHAR(MAX) NULL /* computed by the script. The index name on this system, as indexes name can be different accross systems*/
,isIndexFound_comp BIT NOT NULL DEFAULT 0 /* computed by the script. set to 1 if the index is present on the server */
,isToBeCreated_comp BIT NULL DEFAULT 0 /* computed by the script. does this index will be created on the server ? */
,isToBeRenamed_comp BIT NULL DEFAULT 0 /* computed by the script. does this index will be renamed ? */
,isToBeDeleted_comp BIT NULL DEFAULT 0 /* computed by the script. does this index will be deleted ? */
,isToBeRecreated_comp BIT NULL DEFAULT 0 /* computed by the script. does this index will be re-created ? */
,internal_includedColumnsMatch BIT NULL /* computed ba the script. Are the expected and actual included columns identical ? */
,internal_actualColumns VARCHAR(MAX) NULL /* the actual columns in the existing index */
,internal_actualIncludedColumns VARCHAR(MAX) NULL /* the actual columns in the INCLUDE part of the index */
,internal_statusMsg VARCHAR(MAX) /* Message, used for debug */
);
/* Declare the expected structure of the indexes */
INSERT INTO @indexesToMaintains ([columnsName_inp],
[isToBeDeleted_inp],
[isToBeRecreated_inp],
[expectedIndexName_inp],
[includedColumns_inp],
[schemaName],
[tableName],
[isClustered_inp],
[isUnique_inp])
/* indexe(s) we do want */
VALUES('Entry_id',0,0,'PK_Entry_id', NULL,'dbo','entry',0,0)
,('ET_batch_run',0,0,'NCIX_Entry_COL_ET_batch_run',NULL,'dbo','entry',0,0)
,('ET_accounting_period',0,0,'NCIX_Entry_COL_ET_accounting_period','Entry_ID','dbo','entry',0,0)
,('ET_document_header',0,0,'NCIX_Entry_COL_ET_document_header','ET_debit_currency_amount, ET_credit_currency_amount','dbo','entry',0,0)
,('ET_account, ET_document_header',0,0,'NCIX_Entry_COL_ET_account','Entry_ID','dbo','entry',0,0)
,('ET_reconciliation_status, ET_account, ET_document_header',0,0,'NCIX_Entry_COL_ET_reconciliation_status','ET_debit_base_amount, ET_credit_base_amount, ET_reconciliation_base_amount','dbo','entry',0,0)
,('ET_predefined_entry',0,0,'NCIX_Entry_COL_ET_predefined_entry',NULL,'dbo','entry',0,0)
,('ET_entry_address',0,0,'NCIX_Entry_COL_ET_entry_address',NULL,'dbo','entry',0,0)
,('ET_currency',0,0,'NCIX_Entry_COL_ET_currency',NULL,'dbo','entry',0,0)
/* indexe(s) used in central, even if not in pharmacies*/
,('ET_entry_type',0,0,'NCIX_Entry_COL_ET_entry_type',NULL,'dbo','entry',0,0)
/* indexe(s) we really want to drop*/
,('ET_master_ID',1,0,'NCIX_Entry_COL_ET_master_ID',NULL,'dbo','entry',0,0)
,('ET_bmc_user_profile',1,0,'NCIX_Entry_COL_ET_bmc_user_profile',NULL,'dbo','entry',0,0)
,('ET_sales_tax_code',1,0,'NCIX_Entry_COL_ET_sales_tax_code',NULL,'dbo','entry',0,0)
,('ET_APS_TS', 1, 0, 'NCIX_Entry_COL_ET_APS_TS',NULL,'dbo','entry',0,0)
;
/* check for duplicate */
DECLARE @msg VARCHAR(MAX) = '';
SELECT @msg = @msg + 'Duplicate index (on expected index name) found in indexes definition. Table ['+[itm].[SchemaName]+'].['+[itm].[TableName]+'], expected index name ['+[itm].[expectedIndexName_inp]+']'+CHAR(13)+CHAR(10)
FROM @indexesToMaintains [itm]
JOIN (
SELECT
[ii].[expectedIndexName_inp] AS [key]
FROM @indexesToMaintains [ii]
GROUP BY [ii].[expectedIndexName_inp]
HAVING COUNT(1)>1
) d ON d.[key] = [itm].[expectedIndexName_inp]
GROUP BY [itm].[SchemaName], [itm].[TableName], [itm].[expectedIndexName_inp]
;
/* stop here if we have an issue in the variable table */
IF @msg <> ''
BEGIN
RAISERROR(@msg, 16, 4);
IF @@TRANCOUNT>0
BEGIN
ROLLBACK TRANSACTION;
END
RETURN
END
SET @msg = '';
SELECT @msg = @msg + 'Duplicate index (on column definition) found in indexes definition. Table ['+[itm].[SchemaName]+'].['+[itm].[TableName]+'], columns in index: '+[itm].[columnsName_inp]
+ CASE
WHEN [itm].[includedColumns_inp] IS NOT NULL THEN ', included colum(s): '+[itm].[includedColumns_inp]
ELSE ''
END
+CHAR(13)+CHAR(10)
FROM @indexesToMaintains [itm]
JOIN (
SELECT
[ii].[columnsName_inp]+'_'+ISNULL([ii].[includedColumns_inp],'') AS [key]
FROM @indexesToMaintains [ii]
GROUP BY [ii].[columnsName_inp]+'_'+ISNULL([ii].[includedColumns_inp],'')
HAVING COUNT(1)>1
) d ON d.[key] = [itm].[columnsName_inp]+'_'+ISNULL([itm].[includedColumns_inp],'')
GROUP BY [itm].[SchemaName], [itm].[TableName], [itm].[columnsName_inp], [itm].[includedColumns_inp]
;
/* stop here if we have an issue in the variable table */
IF @msg <> ''
BEGIN
RAISERROR(@msg, 16, 4);
IF @@TRANCOUNT>0
BEGIN
ROLLBACK TRANSACTION;
END
RETURN
END
/* fetch the indexes name on the current instance */
DECLARE curIdxName CURSOR FAST_FORWARD READ_ONLY FOR
SELECT DISTINCT [itm].[schemaName], [itm].[tableName]
FROM @indexesToMaintains [itm];
OPEN curIdxName;
FETCH NEXT FROM curIdxName INTO @schemaName, @tableName;
WHILE @@FETCH_STATUS = 0
BEGIN
;WITH ColInfo
AS (
SELECT
o.[Name] AS TblName
,s.[Name] + '.' + o.[Name] AS SchemaTbl
,i.[Name] AS IndexName
,i.[is_primary_key] AS IsPrimaryKey
,i.[is_unique_constraint] AS IsUniqueConstraint
,i.[is_unique] AS IsUnique
,c.[Name] AS ColName
,c.[is_computed] AS IsComputedCol
,ic.[is_included_column] AS IsIncludedCol
,ic.[key_ordinal]
,i.[filter_definition] AS FilterDefinition
FROM [sys].[objects] o
INNER JOIN [sys].[schemas] s
ON o.SCHEMA_ID = s.SCHEMA_ID
INNER JOIN [sys].[COLUMNS] c
ON o.OBJECT_ID = c.OBJECT_ID
INNER JOIN [sys].[indexes] i
ON c.OBJECT_ID = i.OBJECT_ID
INNER JOIN [sys].[index_columns] ic
ON i.[index_id] = ic.[index_id]
AND o.OBJECT_ID = ic.OBJECT_ID
AND c.[column_id] = ic.[column_id]
)
/* map the list to the actual indexes */
UPDATE [itm] SET [itm].[indexName] = i.[name]
,[itm].[internal_includedColumnsMatch] = CASE
WHEN ISNULL([itm].[includedColumns_inp],'') = ISNULL([idx_cols].[includedColumns],'') THEN 1
ELSE 0
END
,[itm].[internal_actualIncludedColumns] = [idx_cols].[includedColumns]
,[itm].[internal_actualColumns] = [idx_cols].[IndexColumns]
,[itm].[isIndexFound_comp] = 1
,[itm].[isToBeCreated_comp] = 0
FROM [sys].[indexes] AS i WITH (NOLOCK)
INNER JOIN [sys].[objects] o WITH (NOLOCK)
ON i.OBJECT_ID = o.OBJECT_ID
OUTER APPLY (
SELECT DISTINCT
x.TblName
,x.IndexName
,x.IsPrimaryKey
,x.IsUniqueConstraint
,x.IsUnique
,c.IndexColumns
,ci.includedColumns
,cc.ComputedColumns
,x.FilterDefinition
FROM ColInfo x
CROSS APPLY (
SELECT STUFF(sq.strXML, 1, 2, '') AS IndexColumns
FROM (
SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName
AND x.IndexName = x2.IndexName
AND x2.IsIncludedCol = 0
ORDER BY x2.[key_ordinal]
FOR XML PATH('')
) sq(strXML)
) c
OUTER APPLY (
SELECT STUFF(sq.strXML, 1, 2, '') AS includedColumns
FROM (
SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName
AND x.IndexName = x2.IndexName
AND x2.IsIncludedCol = 1
ORDER BY x2.[key_ordinal]
FOR XML PATH('')
) sq(strXML)
) ci
OUTER APPLY (
SELECT STUFF(sq.strXML, 1, 2, '') AS ComputedColumns
FROM (
SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName
AND x.IndexName = x2.IndexName
AND x2.IsComputedCol = 1
ORDER BY x2.[key_ordinal]
FOR XML PATH('')
) sq(strXML)
) cc
WHERE x.TblName = o.[Name]
AND x.IndexName = i.[Name]
) idx_cols
LEFT OUTER JOIN (
SELECT
SCHEMA_NAME(tab.SCHEMA_ID) + '.' + tab.[Name] AS [table]
,col.[column_id]
,col.[Name] AS [COLUMN_NAME]
,CASE
WHEN fk.OBJECT_ID IS NOT NULL THEN '>-'
ELSE NULL
END AS rel
,SCHEMA_NAME(pk_tab.SCHEMA_ID) + '.' + pk_tab.[Name] AS primary_table
,pk_col.[Name] AS pk_column_name
,fk_cols.[constraint_column_id] AS NO
,fk.[Name] AS fk_constraint_name
,tab.[Name] AS tbl_name
FROM [sys].[TABLES] tab
INNER JOIN [sys].[COLUMNS] col
ON col.OBJECT_ID = tab.OBJECT_ID
LEFT OUTER JOIN [sys].[foreign_key_columns] fk_cols
ON fk_cols.[parent_object_id] = tab.OBJECT_ID
AND fk_cols.[parent_column_id] = col.[column_id]
LEFT OUTER JOIN [sys].[foreign_keys] fk
ON fk.OBJECT_ID = fk_cols.[constraint_object_id]
LEFT OUTER JOIN [sys].[TABLES] pk_tab
ON pk_tab.OBJECT_ID = fk_cols.[referenced_object_id]
LEFT OUTER JOIN [sys].[COLUMNS] pk_col
ON pk_col.[column_id] = fk_cols.[referenced_column_id]
AND pk_col.OBJECT_ID = fk_cols.[referenced_object_id]
WHERE fk.OBJECT_ID IS NOT NULL
) fk
ON fk.tbl_name = o.[Name]
AND idx_cols.IndexColumns LIKE '%' + fk.[COLUMN_NAME] + '%'
INNER JOIN @indexesToMaintains [itm]
ON itm.[schemaName] = @schemaName
AND itm.[tableName] = @tableName
AND itm.[columnsName_inp] COLLATE Latin1_General_CI_AI = [idx_cols].[IndexColumns] COLLATE Latin1_General_CI_AI
AND ISNULL([itm].[includedColumns_inp],'') COLLATE Latin1_General_CI_AI = ISNULL([idx_cols].[includedColumns],'') COLLATE Latin1_General_CI_AI
WHERE o.TYPE = 'U' -- user table
--AND i.[index_id] = s.[index_id]
--AND s.[database_id] = DB_ID()
AND o.[Name] = @tableName
AND SCHEMA_NAME(o.SCHEMA_ID) = @schemaName
OPTION (RECOMPILE);
/* Add the indexes not in the list but present on the server to the list */
;WITH ColInfo
AS (
SELECT
o.[Name] AS TblName
,SCHEMA_NAME(o.[schema_id]) AS SchemaName
,s.[Name] + '.' + o.[Name] AS SchemaTbl
,i.[Name] AS IndexName
,i.[is_primary_key] AS IsPrimaryKey
,i.[is_unique_constraint] AS IsUniqueConstraint
,i.[is_unique] AS IsUnique
,c.[Name] AS ColName
,c.[is_computed] AS IsComputedCol
,ic.[is_included_column] AS IsIncludedCol
,ic.[key_ordinal]
,i.[filter_definition] AS FilterDefinition
FROM [sys].[objects] o
INNER JOIN [sys].[schemas] s
ON o.SCHEMA_ID = s.SCHEMA_ID
INNER JOIN [sys].[COLUMNS] c
ON o.OBJECT_ID = c.OBJECT_ID
INNER JOIN [sys].[indexes] i
ON c.OBJECT_ID = i.OBJECT_ID
INNER JOIN [sys].[index_columns] ic
ON i.[index_id] = ic.[index_id]
AND o.OBJECT_ID = ic.OBJECT_ID
AND c.[column_id] = ic.[column_id]
)
INSERT INTO @indexesToMaintains (
[schemaName]
,[tableName]
,[columnsName_inp]
,[indexName]
,[isToBeDeleted_inp]
,[isToBeDeleted_comp]
,[isToBeRecreated_inp]
,[internal_statusMsg]
,[internal_actualIncludedColumns]
,[internal_actualColumns]
,[isIndexFound_comp]
,[isToBeCreated_comp]
,[expectedIndexName_inp]
)
SELECT DISTINCT
@schemaName AS [SchemaName]
,@tableName AS [TableName]
,c.[IndexColumns] AS [columnsName]
,x.[IndexName] AS indexName
,0 AS [isToBeDeleted_inp]
,CASE
WHEN EXISTS(
SELECT 1
FROM @indexesToMaintains [itm]
WHERE itm.[expectedIndexName_inp] = x.[IndexName]
OR ISNULL(itm.[columnsName_inp],'') <> ISNULL(itm.[internal_actualColumns],'')
OR ISNULL(itm.[includedColumns_inp],'') <> ISNULL(itm.[internal_actualIncludedColumns],'')
) THEN 1
WHEN @DoDropExistingIndexesNotReferenced = 1 THEN 1
ELSE 0
END AS [isToBeDeleted_comp]
,0 AS [isToBeRecreated_inp]
,CASE
WHEN EXISTS(
SELECT 1
FROM @indexesToMaintains [itm]
WHERE itm.[expectedIndexName_inp] = x.[IndexName]
OR ISNULL(itm.[columnsName_inp],'') <> ISNULL(itm.[internal_actualColumns],'')
OR ISNULL(itm.[includedColumns_inp],'') <> ISNULL(itm.[internal_actualIncludedColumns],'')
) THEN 'Index present locally not as expected, drop before creation'
WHEN @DoDropExistingIndexesNotReferenced = 1 THEN 'Index present locally only'
ELSE NULL
END AS [internal_statusMsg]
,ci.[includedColumns] AS [internal_actualIncludedColumns]
,c.[IndexColumns] AS [internal_actualColumns]
,1 AS [isIndexFound_comp]
,0 AS [isToBeCreated_comp]
,x.[IndexName] AS [expectedIndexName_inp]
FROM ColInfo x
CROSS APPLY(SELECT IndexColumns = STUFF(sq.strXML, 1, 2, '')
FROM ( SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName AND x.IndexName = x2.IndexName AND x2.IsIncludedCol = 0
ORDER BY x2.key_ordinal
FOR XML PATH('')
) sq (strXML)
) c
Outer APPLY(SELECT IncludedColumns = STUFF(sq.strXML, 1, 2, '')
FROM ( SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName AND x.IndexName = x2.IndexName AND x2.IsIncludedCol = 1
ORDER BY x2.key_ordinal
FOR XML PATH('')
) sq (strXML)
) ci
Outer APPLY(SELECT ComputedColumns = STUFF(sq.strXML, 1, 2, '')
FROM ( SELECT ', ' + ISNULL(x2.ColName, '')
FROM ColInfo x2
WHERE x.TblName = x2.TblName AND x.IndexName = x2.IndexName AND x2.IsComputedCol = 1
ORDER BY x2.key_ordinal
FOR XML PATH('')
) sq (strXML)
) cc
LEFT OUTER JOIN (
SELECT
SCHEMA_NAME(tab.SCHEMA_ID) + '.' + tab.[Name] AS [table]
,col.[column_id]
,col.[Name] AS [COLUMN_NAME]
,CASE
WHEN fk.OBJECT_ID IS NOT NULL THEN '>-'
ELSE NULL
END AS rel
,SCHEMA_NAME(pk_tab.SCHEMA_ID) + '.' + pk_tab.[Name] AS primary_table
,pk_col.[Name] AS pk_column_name
,fk_cols.[constraint_column_id] AS NO
,fk.[Name] AS fk_constraint_name
,tab.[Name] AS tbl_name
FROM [sys].[TABLES] tab
INNER JOIN [sys].[COLUMNS] col
ON col.OBJECT_ID = tab.OBJECT_ID
LEFT OUTER JOIN [sys].[foreign_key_columns] fk_cols
ON fk_cols.[parent_object_id] = tab.OBJECT_ID
AND fk_cols.[parent_column_id] = col.[column_id]
LEFT OUTER JOIN [sys].[foreign_keys] fk
ON fk.OBJECT_ID = fk_cols.[constraint_object_id]
LEFT OUTER JOIN [sys].[TABLES] pk_tab
ON pk_tab.OBJECT_ID = fk_cols.[referenced_object_id]
LEFT OUTER JOIN [sys].[COLUMNS] pk_col
ON pk_col.[column_id] = fk_cols.[referenced_column_id]
AND pk_col.OBJECT_ID = fk_cols.[referenced_object_id]
WHERE fk.OBJECT_ID IS NOT NULL
) fk
ON fk.tbl_name = x.[TblName]
AND [c].[IndexColumns] LIKE '%' + fk.[COLUMN_NAME] + '%'
WHERE x.[SchemaName] =@schemaName
AND x.[TblName] =@tableName
AND NOT EXISTS(
SELECT 1
FROM @indexesToMaintains [itm2]
WHERE 1=1
AND ISNULL(itm2.[internal_actualColumns],'') = ISNULL(c.[IndexColumns],'')
AND ISNULL(itm2.[internal_actualIncludedColumns],'') = ISNULL(ci.[includedColumns],'')
)
OPTION (RECOMPILE);
FETCH NEXT FROM curIdxName INTO @schemaName, @tableName;
END
CLOSE curIdxName;
DEALLOCATE curIdxName;
/* Adjust the "_comp" flags to create a matrix of actions */
/* to be created */
UPDATE [itm]
SET
[itm].[isToBeCreated_comp] = CASE
WHEN [itm].[isToBeDeleted_inp] = 0 THEN 1
ELSE 0
END
FROM @indexesToMaintains [itm]
WHERE [itm].[indexName] IS NULL /* index was not found on the server */
AND [itm].[expectedIndexName_inp] IS NOT NULL /* we did gave an index name, ie: we want to create it if missing */
;
/* to be renamed */
UPDATE [itm]
SET
[itm].[isToBeRenamed_comp] = 1
FROM @indexesToMaintains [itm]
WHERE [itm].[indexName] IS NOT NULL /* index was not found on the server */
AND [itm].[expectedIndexName_inp] IS NOT NULL /* we did gave an index name, ie: we expect that index to be present */
AND [indexName] <> [itm].[expectedIndexName_inp]
AND [isToBeDeleted_inp] = 0
AND [isToBeDeleted_comp] = 0
;
/* to be re-created */
UPDATE [itm]
SET
[itm].[isToBeRecreated_comp] = 1
FROM @indexesToMaintains [itm]
WHERE [isToBeRecreated_inp] = 1
;
/* to be deleted, because specified in table */
UPDATE itm
SET
[itm].[isToBeDeleted_comp] = CASE
WHEN [itm].[isIndexFound_comp] = 0 THEN 0
ELSE 1
END
,[itm].[isToBeRecreated_comp] = 0 /* deletion override re-create */
,[itm].[isToBeRenamed_comp] = 0 /* deletion override rename */
FROM @indexesToMaintains [itm]
WHERE [itm].[isToBeDeleted_inp] = 1
;
/* to be deleted, because different to specs. link on index name */
UPDATE [exp]
SET
[exp].[isToBeCreated_comp] = 1 /* flag the expected index "to be created" */
FROM @indexesToMaintains [exp] --expected
JOIN @indexesToMaintains [act] --actual
ON [act].[indexName] = [exp].[expectedIndexName_inp]
WHERE [exp].[isToBeDeleted_comp] = 0
AND [exp].[isToBeCreated_comp] = 0
AND [exp].[isToBeRenamed_comp] = 0
AND [exp].[isToBeRecreated_inp] = 0
AND (
[exp].[columnsName_inp] != [act].[internal_actualColumns]
OR [exp].[includedColumns_inp] != [act].[internal_actualIncludedColumns]
)
;
UPDATE [act]
SET
[act].[isToBeDeleted_comp] = 1 /* flag the actual index "to be deleted" */
FROM @indexesToMaintains [exp] --expected
JOIN @indexesToMaintains [act] --actual
ON [act].[indexName] = [exp].[expectedIndexName_inp]
WHERE (
[exp].[columnsName_inp] != [act].[internal_actualColumns]
OR [exp].[includedColumns_inp] != [act].[internal_actualIncludedColumns]
)
;
/* to be deleted, because different to specs. link on index columns */
UPDATE [exp]
SET
[exp].[isToBeCreated_comp] = 1 /* flag the expected index "to be created" */
FROM @indexesToMaintains [exp] --expected
JOIN @indexesToMaintains [act] --actual
ON [act].[internal_actualColumns] = [exp].[columnsName_inp]
WHERE (
[exp].[columnsName_inp] != [act].[internal_actualColumns]
OR [exp].[includedColumns_inp] != [act].[internal_actualIncludedColumns]
)
;
UPDATE [act]
SET
[act].[isToBeDeleted_comp] = 1 /* flag the actual index "to be deleted" */
FROM @indexesToMaintains [exp] --expected
JOIN @indexesToMaintains [act] --actual
ON [act].[internal_actualColumns] = [exp].[columnsName_inp]
WHERE (
[exp].[columnsName_inp] != [act].[internal_actualColumns]
OR [exp].[includedColumns_inp] != [act].[internal_actualIncludedColumns]
)
;
/* if we have both "rename" and "delete" actions, remove the "rename" action */
UPDATE @indexesToMaintains
SET [isToBeRenamed_comp] = 0
WHERE [isToBeRenamed_comp] = 1
AND [isToBeDeleted_comp] = 1
;
/* ensure that we don't have clash between indexes to create and indexes to rename */
UPDATE ir
SET [ir].[isToBeRenamed_comp] = 0 /* do not rename this index */
, [ir].[isToBeDeleted_inp] = 1 /* drop this index instead, as we have one with the correct structure about to be created */
FROM @indexesToMaintains [ic] /* to create */
JOIN @indexesToMaintains [ir] /* to rename */
ON ic.[expectedIndexName_inp] = ir.[expectedIndexName_inp]
WHERE [ic].[isToBeCreated_comp] = 1
AND [ir].[isToBeRenamed_comp] = 1
/* Show the action matrix */
SELECT [itm].[isIndexFound_comp]
,[itm].[isToBeCreated_comp]
,[itm].[isToBeRenamed_comp]
,[itm].[isToBeDeleted_comp]
,[itm].[isToBeRecreated_comp]
,[itm].[internal_statusMsg]
,'....'
,[itm].[isToBeDeleted_inp]
,[itm].[isToBeRecreated_inp]
,[itm].[indexName]
,[itm].[expectedIndexName_inp]
,[itm].[columnsName_inp]
,[itm].[internal_actualColumns]
,[itm].[includedColumns_inp]
,[itm].[internal_actualIncludedColumns]
FROM @indexesToMaintains [itm]
ORDER BY [itm].[isIndexFound_comp],[itm].[isToBeDeleted_inp], [itm].[columnsName_inp];
/* Drop the indexe(s) that are to be deleted or recreated */
SET @query='';
SELECT @query = @query + 'DROP INDEX '+[itm].[indexName]+' ON dbo.entry;'+CHAR(13)+CHAR(10)
FROM @indexesToMaintains [itm]
WHERE [itm].[isToBeDeleted_comp] = 1
OR [itm].[isToBeRecreated_comp] = 1
;
PRINT REPLICATE('-', 40);
PRINT '-- execute DROP INDEX';
PRINT REPLICATE('-', 40);
PRINT @query;
PRINT REPLICATE('-', 40);
PRINT CHAR(13)+CHAR(10);
IF @DoOnlyOutputStatement = 0
BEGIN
EXECUTE(@query);
END
/* rename existing indexe(s) */
SET @query = '';
SELECT @query = @query + 'EXEC sp_rename @objname ='''+[itm].[tableName]+'.'+[itm].[indexName]+''', @newname = '''+[itm].[expectedIndexName_inp]+''';'+CHAR(13)+CHAR(10)
FROM @indexesToMaintains [itm]
WHERE [itm].[isToBeRenamed_comp] = 1
;
PRINT REPLICATE('-', 40);
PRINT '-- execute sp_rename';
PRINT REPLICATE('-', 40);
PRINT @query;
PRINT REPLICATE('-', 40);
PRINT CHAR(13)+CHAR(10);
IF @DoOnlyOutputStatement = 0
BEGIN
EXECUTE(@query);
END
/* create indexe(s) */
SET @query='';
SELECT @query = @query + 'CREATE '
+CASE WHEN [itm].[isClustered_inp]=1 THEN 'CLUSTERED' ELSE 'NONCLUSTERED' END
+CASE WHEN [itm].[isUnique_inp]=1 THEN ' UNIQUE' ELSE '' END
+' INDEX '+[itm].[expectedIndexName_inp]
+' ON '+[itm].[schemaName]+'.'+[itm].[tableName]+'('+[itm].[columnsName_inp]+')'
+ CASE
WHEN [itm].[includedColumns_inp] IS NOT NULL THEN ' INCLUDE ('+[itm].[includedColumns_inp]+')'
ELSE ''
END
+';'
+CHAR(13)+CHAR(10)
FROM @indexesToMaintains [itm]
WHERE (
[itm].[isToBeCreated_comp] = 1
OR [itm].[isToBeRecreated_comp] = 1
)
;
PRINT REPLICATE('-', 40);
PRINT '-- execute CREATE INDEX';
PRINT REPLICATE('-', 40);
PRINT @query;
PRINT REPLICATE('-', 40);
PRINT CHAR(13)+CHAR(10);
IF @DoOnlyOutputStatement = 0
BEGIN
EXECUTE(@query);
END
--ROLLBACK TRANSACTION;
COMMIT TRANSACTION

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-373 - alert and monitoring structure", "OCTPDBA-373 - alert and monitoring structure.ssmssqlproj", "{7177190D-8629-4E51-BBE7-D81C2F9F6331}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7177190D-8629-4E51-BBE7-D81C2F9F6331}.Default|Default.ActiveCfg = Default
{218719E2-5FDB-4331-8CBF-3508BA7C3A18}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {344BCD75-0967-4714-8248-D9C6D00E8B77}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-373 - alert and monitoring structure">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="(local):CENTRALINFRA\ua208700">
<Created>2022-10-28T08:34:19.0911022+02:00</Created>
<Type>SQL</Type>
<Server>(local)</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB>sandbox</InitialDB>
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="structure proposal.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>structure proposal.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,106 @@
/*
OCTPDBA-373
Proposition of structure for alerts in dbaTools, for reporting via Scom
27.10.2022, TSC
*/
USE sandbox
IF OBJECT_ID('dbo.alert_type') IS NOT NULL BEGIN;
IF OBJECT_ID('fk_alert_log__ref__alert_type') IS NOT NULL BEGIN
ALTER TABLE dbo.alert_log DROP CONSTRAINT fk_alert_log__ref__alert_type;
END
IF OBJECT_ID('fk_alert_overview__ref__alert_type') IS NOT NULL BEGIN
ALTER TABLE dbo.alert_overview DROP CONSTRAINT fk_alert_overview__ref__alert_type;
END
DROP TABLE dbo.alert_type;
END;
/*
Define the types of alerts we handle.
Each alert type is identified by an unique code
We can define a window of time in between alerts will not be recorded, or have a master switch to enable / disable the alert
If an alert is enabled (alert_enabled = 1) but we are in a disabled time window (current_timestamp between alert_disabled_from and alert_disabled_to) then we do not record any new alerts
the field keep_for_days define how long we keep a record of this alert in the log, once an alert is older that this value, it will be cleaned up.
The severity of the alert is at the alert level and not tied to the definition of the alert itself.
*/
CREATE TABLE dbo.alert_type (
alert_type_id INT NOT NULL IDENTITY
,alert_type VARCHAR(50) NOT NULL --a code to identify the alert
,alert_enabled BIT NOT NULL --global switch to disable / enable the alert outside a time window
CONSTRAINT def_alert_enabled
DEFAULT 1
,alert_disabled_from SMALLDATETIME NULL --if a window is planned for deativating the alert, beginning of the window
,alert_disabled_to SMALLDATETIME NULL --if a window is planned for deativating the alert, end of the window
,keep_for_days INT NOT NULL --how long does the alert should stay in the log. After that age passes, alerts in the log will be deleted.
DEFAULT 365
,comp_alert_is_enabled AS CONVERT(BIT --computed column to get the current state of the alert (enabled or disabled)
,alert_enabled * CASE
WHEN CURRENT_TIMESTAMP BETWEEN alert_disabled_from
AND alert_disabled_to THEN 0
ELSE 1
END
)
,CONSTRAINT pk_alert_type
PRIMARY KEY (alert_type_id)
);
CREATE UNIQUE NONCLUSTERED INDEX NCUIX_alert_type__alert_type
ON dbo.alert_type (alert_type);
IF OBJECT_ID('dbo.alert_log') IS NOT NULL BEGIN;
DROP TABLE dbo.alert_log;
END;
/*
This table will holds every alerts that have been recorded.
*/
CREATE TABLE dbo.alert_log (
alert_log_id INT NOT NULL IDENTITY
,alert_type VARCHAR(50) NOT NULL --point to alert_type, FK
,alert_creation_date SMALLDATETIME NOT NULL --when was this alert created
CONSTRAINT def_alert_creation_date
DEFAULT CURRENT_TIMESTAMP
,alert_treated_date SMALLDATETIME NULL --when was the alert treated, if it was
,alert_source VARCHAR(1000) NULL --what is the source of the alert (job name, script, parsing system logs, audits, extended events ?)
,alert_resolution_comment VARCHAR(MAX) NULL --to leave a comment on the resolution, if needed
,alert_severity INT NULL -- 0 = info / 1 = warning / 2 = error
,CONSTRAINT pk_alert_log
PRIMARY KEY (alert_log_id)
);
IF OBJECT_ID('fk_alert_log__ref__alert_type') IS NULL
ALTER TABLE dbo.alert_log
ADD CONSTRAINT fk_alert_log__ref__alert_type
FOREIGN KEY (alert_type)
REFERENCES dbo.alert_type (alert_type)
;
IF OBJECT_ID('dbo.alert_overview')IS NOT NULL BEGIN;
DROP TABLE dbo.alert_overview;
END;
/*
This overview table is recreated by a job every night.
It only contains 1 row per alert type, if the alert is enabled in alert_type.
A timestamp of the rebuild of this table is present, to ensure that the job did rebuild it daily.
The highest severity of all the alerts of that type is recorded, as well as the oldest non treated alert
A computed column gives the age of the oldest alert of that type in days
*/
CREATE TABLE dbo.alert_overview(
alert_type VARCHAR(50) NOT NULL --1 entry per alert type, this is an overview
,overview_creation_date SMALLDATETIME NOT NULL --when was this overview created
,alert_oldest SMALLDATETIME NOT NULL --The oldest alert entry not treated for this alert type
,alert_severity INT NOT NULL --the highest level of alert severity not treated for this alert type
,comp_days_since_alert_exists AS DATEDIFF(DAY, alert_oldest, CURRENT_TIMESTAMP) --Oldest not treated alert of that type is X days old
,CONSTRAINT pk_alert_overview PRIMARY KEY(alert_type)
);
IF OBJECT_ID('fk_alert_overview__ref__alert_type') IS NULL
ALTER TABLE dbo.alert_overview
ADD CONSTRAINT fk_alert_overview__ref__alert_type
FOREIGN KEY(alert_type)
REFERENCES dbo.alert_type(alert_type)
;

View File

@@ -0,0 +1,72 @@
IF OBJECT_ID('[dbo].[MaintainHCIChangeTrackingHistory]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[MaintainHCIChangeTrackingHistory];
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*=============================================================================
Description
----------------------
OCTP-2459
Cleans history data in HCIChangeTracking.
Deletes all records older than 2 years in the following tables:
* [OlpDirectoryChangeLog]
* [OlpfactChangeLog]
* [OlpfactValidatorChangeLog]
Where
----------------------
On all TriaFact instances
Dependencies
----------------------
Called by job [W030100 - Cleanup HCIChangeTracking]
Creation:
03.11.2022 / TSC
Modifications:
=============================================================================*/
CREATE PROCEDURE dbo.MaintainHCIChangeTrackingHistory
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@deleted INT
,@batch_size INT = 100000
,@today DATE = DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 0);
SET @deleted = 1;
WHILE @deleted > 0 BEGIN
DELETE TOP (@batch_size) cl
FROM dbo.[OlpDirectoryChangeLog] cl
WHERE cl.CreationDate < DATEADD(YEAR, -2, @today);
SET @deleted = @@ROWCOUNT;
END
SET @deleted = 1;
WHILE @deleted > 0 BEGIN
DELETE TOP (@batch_size) cl
FROM dbo.[OlpfactChangeLog] cl
WHERE cl.CreationDate < DATEADD(YEAR, -2, @today);
SET @deleted = @@ROWCOUNT;
END
SET @deleted = 1;
WHILE @deleted > 0 BEGIN
DELETE TOP (@batch_size) cl
FROM dbo.[OlpfactValidatorChangeLog] cl
WHERE cl.CreationDate < DATEADD(YEAR, -2, @today);
SET @deleted = @@ROWCOUNT;
END
END

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-379 - cleanup hciChangeTracking", "OCTPDBA-379 - cleanup hciChangeTracking.ssmssqlproj", "{0C063DF9-C600-47CB-A702-A09D2B620F0C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C063DF9-C600-47CB-A702-A09D2B620F0C}.Default|Default.ActiveCfg = Default
{486BAABC-4895-4B4A-B50F-D60324239538}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {21012A30-E112-4401-B134-71314DC7DDAB}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-379 - cleanup hciChangeTracking">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="swtfdev01.centralinfra.net\DGALTFAC:CENTRALINFRA\ua208700">
<Created>2022-11-07T09:17:46.0882714+01:00</Created>
<Type>SQL</Type>
<Server>swtfdev01.centralinfra.net\DGALTFAC</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="MaintainHCIChangeTrackingHistory.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:swtfdev01.centralinfra.net\DGALTFAC:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>swtfdev01.centralinfra.net\DGALTFAC</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>MaintainHCIChangeTrackingHistory.sql</FullPath>
</FileNode>
<FileNode Name="W030100 - Cleanup HCIChangeTracking.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:swtfdev01.centralinfra.net\DGALTFAC:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>swtfdev01.centralinfra.net\DGALTFAC</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>W030100 - Cleanup HCIChangeTracking.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-411 - insurance contracts new fields", "OCTPDBA-411 - insurance contracts new fields.ssmssqlproj", "{C5115BF3-B6B3-4439-A537-D54AC800B363}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C5115BF3-B6B3-4439-A537-D54AC800B363}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCA17A92-B699-4F53-B2C0-E93CA17B63EB}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-411 - insurance contracts new fields">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="cgal41556:CENTRALINFRA\ua208700">
<Created>2022-11-25T15:00:32.1756269+01:00</Created>
<Type>SQL</Type>
<Server>cgal41556</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items />
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,105 @@
USE [Arizona]
GO
/****** Object: View [dbo].[v_Sync_V_PH_Insurance] Script Date: 25.11.2022 15:31:31 ******/
IF OBJECT_ID('[dbo].[v_Sync_V_PH_Insurance]') IS NOT NULL
DROP VIEW [dbo].[v_Sync_V_PH_Insurance]
GO
/****** Object: View [dbo].[v_Sync_V_PH_Insurance] Script Date: 25.11.2022 15:31:31 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE VIEW [dbo].[v_Sync_V_PH_Insurance]
AS
/*===========================================================================
Vue utilisee dans les synchro verticales pour la sp 'aps_Sync_V_Template_3'
permettant de selectionner la subsidiary d'une table detail dans sa table
master.
******************************************************
* Attention le nom de la vue doit respecter *
* le standard 'v_Sync_V_nom_de_la_table' *
******************************************************
Creation: 17.06.03 / rc
Modifications:
21.01.21 / spe : #TFS63351# Modify SyncV view and configuration to avoid CERES pharmacy_code problems on pharmacies
25.11.22 / TSC : OCTPDBA-411: Create new field in DB to represent the string value of special insurance contracts
============================================================================*/
SELECT adk.ADK_subsidiary 'calc_subsidiary_id',
phin.PH_insurance_GUID,
phin.PHIN_address,
phin.PHIN_key,
phin.PHIN_EAN_key,
phin.PHIN_type,
phin.PHIN_invoice_type,
phin.PHIN_name_french,
phin.PHIN_name_german,
phin.PHIN_name_italian,
phin.PHIN_slogan_french,
phin.PHIN_slogan_german,
phin.PHIN_slogan_italian,
phin.PHIN_type_of_proof,
phin.PHIN_plan_LS,
phin.PHIN_plan_HL,
phin.PHIN_plan_MC,
phin.PHIN_plan_LPPA,
phin.PHIN_plan_FHLN,
phin.PHIN_check_physician_number,
phin.PHIN_address_1,
phin.PHIN_address_2,
phin.PHIN_zip_code,
phin.PHIN_location,
phin.PHIN_language,
phin.PHIN_telephone,
phin.PHIN_fax,
phin.PHIN_IN_minimum_length,
phin.PHIN_IN_maximum_length,
phin.PHIN_IN_type,
phin.PHIN_IN_alignment,
phin.PHIN_IN_start_position,
phin.PHIN_IN_end_position,
phin.PHIN_IN_check_digit_ref,
phin.PHIN_ISO_key,
phin.PHIN_section_minimum_length,
phin.PHIN_section_maximum_length,
phin.PHIN_section_type,
phin.PHIN_section_alignment,
phin.PHIN_invoicing_method,
phin.PHIN_origin,
phin.PHIN_invoice_transmission,
phin.PHIN_APS_TS,
phin.PHIN_TS,
phin.PHIN_VGUID,
phin.PHIN_master_ID,
phin.PHIN_bill_to,
phin.PHIN_status,
phin.PHIN_renewable_bonus_factor,
phin.PHIN_insurance_bonus_factor,
phin.PHIN_recipient_EAN_key,
phin.PHIN_Invoice_delay,
phin.PHIN_Invoice_gap,
phin.PHIN_view_prescription_image,
phin.PHIN_hl_accept_limited_coverage,
phin.PHIN_mc_accept_limited_coverage,
phin.PHIN_code_model,
phin.PHIN_benefit_number,
phin.PHIN_tp_min_amount,
phin.PHIN_tp_min_amount_invoice,
phin.PHIN_assignment_of_claim,
phin.PHIN_rowguid,
[phin].[PHIN_contract_name]
FROM PH_insurance phin (NOLOCK)
LEFT OUTER JOIN Address_key adk (NOLOCK)
ON adk.ADK_address = phin.PHIN_address
AND adk.ADK_type = 1
GO

View File

@@ -0,0 +1,29 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-412 arizonaCash.dbo.cr_point_of_sale deprecated", "OCTPDBA-412 arizonaCash.dbo.cr_point_of_sale deprecated.ssmssqlproj", "{5C48E5C0-6DA0-4579-82E1-6F065B36C27B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FA70565B-C803-4A66-A57C-87EAD812951C}"
ProjectSection(SolutionItems) = preProject
..\..\repos\ActivePharmacy\Source\Database\Source\ActiveSystemServer\Migration\_000900.StoredProcedures\001200.dbo.RepairReplication.sql = ..\..\repos\ActivePharmacy\Source\Database\Source\ActiveSystemServer\Migration\_000900.StoredProcedures\001200.dbo.RepairReplication.sql
C:\dev\dbaTools\DBA.Tools\Main\StoredProcedures\Replication_Check.sql = C:\dev\dbaTools\DBA.Tools\Main\StoredProcedures\Replication_Check.sql
todo.txt = todo.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5C48E5C0-6DA0-4579-82E1-6F065B36C27B}.Default|Default.ActiveCfg = Default
{4EBFFE19-C8C0-4353-98E9-E18DEB2410A9}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0FF98CC6-E9AD-4405-8F32-9F19F7FD496B}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
<Items>
<LogicalFolder Name="Connections" Type="2" />
<LogicalFolder Name="Queries" Type="0" />
<LogicalFolder Name="Miscellaneous" Type="3" />
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,12 @@
The content of arizonaCash.dbo.cr_point_of_sale has been migrated to arizona.dbo.point_of_sale during the update.
We must ensure that no procs / functions / views / triggers are referencing arizonaCash.dbo.cr_point_of_sale anymore.
1. Identify and adapt every db object referencing the deprecated table.
[ ] ActiveSystemServer.[dbo].[RepairReplication]
[ ] HCITools.[dbo].[Replication_Check]
2. Create a bug for G# team (it could also be taken by Code Brewers). Prioritize it with them.
[ ]
3. Clean existing [dbo].[ExecuteOnAllPos] on HCITools on all pharmacies
[ ]

View File

@@ -0,0 +1,31 @@
USE [Arizona];
BEGIN TRANSACTION;
SET XACT_ABORT ON;
IF NOT EXISTS(
SELECT *
FROM [sys].[tables] [t]
WHERE [t].[name] = 'CCI_item'
AND SCHEMA_NAME([t].[schema_id]) = 'dbo'
)
BEGIN
CREATE TABLE [dbo].[CCI_item]
(
[CCI_item_ID] [dbo].[Unique_identifier] NOT NULL,
[CCIIT_item] [dbo].[Unique_identifier] NOT NULL,
[CCIIT_predefined_entry] [dbo].[Unique_identifier] NOT NULL,
[CCIIT_sequence] [dbo].[Sequence_numbers] NULL,
[CCIIT_print_sequence] [dbo].[Small_alphabetical_field] NULL,
[CCIIT_TS] [timestamp] NOT NULL,
[CCIIT_VGUID] [dbo].[VGUID_identifier] NULL CONSTRAINT [DF__CCI_item__CCIIT___77EF7824] DEFAULT (NEWID()),
[CCIIT_master_ID] [dbo].[Large_name_field] NULL
) ON [PRIMARY];
ALTER TABLE [dbo].[CCI_item] ADD CONSTRAINT [PK__CCI_item__53385258] PRIMARY KEY NONCLUSTERED ([CCI_item_ID]) WITH (FILLFACTOR=90) ON [PRIMARY];
CREATE NONCLUSTERED INDEX [XIF1852CCI_item] ON [dbo].[CCI_item] ([CCIIT_predefined_entry]) WITH (FILLFACTOR=90) ON [PRIMARY];
CREATE NONCLUSTERED INDEX [XIF1853CCI_item] ON [dbo].[CCI_item] ([CCIIT_item]) WITH (FILLFACTOR=90) ON [PRIMARY];
CREATE NONCLUSTERED INDEX [XIEAPS1CCI_item] ON [dbo].[CCI_item] ([CCIIT_VGUID]) WITH (FILLFACTOR=90) ON [PRIMARY];
CREATE NONCLUSTERED INDEX [XIEAPS2CCI_item] ON [dbo].[CCI_item] ([CCIIT_master_ID]) WITH (FILLFACTOR=90) ON [PRIMARY];
PRINT 'table is created';
END;
COMMIT TRANSACTION;

View File

@@ -0,0 +1,27 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-429 - end of year billing", "OCTPDBA-429 - end of year billing.ssmssqlproj", "{92936BF0-A79C-48E5-9197-C9F5032E1CFC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{55653D81-31F3-430B-A5E4-EC5B3F764B19}"
ProjectSection(SolutionItems) = preProject
Tasks in order to force the Invoice.sql = Tasks in order to force the Invoice.sql
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{92936BF0-A79C-48E5-9197-C9F5032E1CFC}.Default|Default.ActiveCfg = Default
{88E31270-4274-4B53-8AD2-E93500C09909}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ADC9E635-CD62-404C-9CB4-F521489B9AA5}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="SqlWorkbenchSqlProject">
<Items>
<LogicalFolder Name="Connections" Type="2" />
<LogicalFolder Name="Queries" Type="0" />
<LogicalFolder Name="Miscellaneous" Type="3" />
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,190 @@
use arizona
;
/*=======================================================================
Galenica - End Of Year - Tasks in order to force the Invoice
STEP 01 - Déclaration des variables
STEP 02 - Création / suppression de la table PHOU historisée
STEP 03 - Remplissage de la table PHOU historisée
STEP 04 - Construction de la table de changements
STEP 05 - Application des changements
STEP 06 - Rétablissement des anciennes valeurs
=======================================================================*/
/*=======================================================================
STEP 01 - Déclaration des variables
=======================================================================*/
declare @force_delete int = 08,
@mode int = 1, /* 1 = Check | 2 = Just do IT !!! */
@cmdsql varchar(max),
@today datetime = getdate()
;
declare @day_delay table (
day_from      int,
day_to      int,
delivery_delay int,    
closing_mode   int)
;
/*=======================================================================
STEP 02 - Création / suppression de la table PHOU historisée
=======================================================================*/
if (EXISTS (select *
from arizonacust.INFORMATION_SCHEMA.TABLES
where TABLE_SCHEMA = 'dbo'
and TABLE_NAME = 'PH_Organizational_Unit_history'))
begin
if @force_delete = 1 begin
select @cmdsql = 'drop table arizonacust.dbo.PH_Organizational_Unit_history'
exec (@cmdsql)
end
end else begin
create table arizonacust.dbo.PH_Organizational_Unit_history (
PH_Organizational_Unit_history_id int identity (1,1),
phouh_year int,
phouh_PH_Organizational_Unit_guid uniqueidentifier,
phouh_PHOU_AB_delivery_delay smallint,
phouh_PHOU_AB_closing_mode smallint
)
end
/*=======================================================================
STEP 03 - Remplissage de la table PHOU historisée
=======================================================================*/
insert into arizonacust.dbo.PH_Organizational_Unit_history (
phouh_year,
phouh_PH_Organizational_Unit_guid,
phouh_PHOU_AB_delivery_delay,
phouh_PHOU_AB_closing_mode)
select year(@today),
PH_Organizational_Unit_guid,
PHOU_AB_delivery_delay,
PHOU_AB_closing_mode
from dbo.Organizational_Unit ou (nolock)  
join PH_Organizational_Unit P (nolock)  
on PHOU_Organizational_Unit = Organizational_Unit_Id 
join dbo.OU_store_history oush (nolock)
on oush.OU_store_history_GUID = (
select top 1 oush2.OU_store_history_GUID
from dbo.OU_store_history oush2 (nolock)
where isnull(oush2.OUSH_end_date,'2050-01-01') >= @today
and oush2.OUSH_organizational_unit = ou.Organizational_unit_ID
order by oush2.OUSH_start_date desc
)
join dbo.Address_criteria AC (nolock)  
on AC.ADCR_subsidiary = ou.OU_subsidiary  
and AC.ADCR_address = ou.OU_address  
join dbo.Criteria C (nolock)  
on C.Criteria_ID = AC.ADCR_criteria  
and C.CR_code = 'PROD'  
join dbo.Criteria_Type Ct (nolock)  
on Ct.Criteria_type_ID = C.CR_criteria_type  
and Ct.CRT_code = 'ENV'
where not exists (
select 1
from arizonacust.dbo.PH_Organizational_Unit_history p (nolock)
where p.phouh_year = year(@today)
and p.phouh_PH_Organizational_Unit_guid = PH_Organizational_Unit_guid
)
/*=======================================================================
STEP 04 - Construction de la table de changements
=======================================================================*/
/* 1. From December 12th to December 17th (included) set the Delivery_delay to 10 */
insert into @day_delay (day_from, day_to, delivery_delay,closing_mode)
select 12, 17, 10, 0
/* 2. From December 18th to December 24th (included) set the Delivery_delay to 5 */
insert into @day_delay (day_from, day_to, delivery_delay,closing_mode)
select 18, 24, 5, 0
/* 3. From December 25th to December 31th (included) set the Delivery_delay to 2 ClosingMode   */
insert into @day_delay (day_from, day_to, delivery_delay,closing_mode)
select 25, 30, 2, 1
/*=======================================================================
STEP 05 - Application des changements
=======================================================================*/
if @mode = 2 begin
update phou   
set phou.PHOU_AB_delivery_delay = case when d.delivery_delay <= phou.PHOU_AB_delivery_delay                                            
then d.delivery_delay 
else PHOU.PHOU_AB_delivery_delay 
end,
phou.PHOU_AB_closing_mode = case when phou.PHOU_AB_closing_mode = 1                                        
then PHOU.PHOU_AB_closing_mode                                         
else d.closing_mode                          
end 
from dbo.PH_organizational_unit PHOU (nolock)
join @day_delay d  
on day(@today) between d.day_from and d.day_to
and month(@today) = 12
where PHOU_AB_delivery_delay is not null
and (PHOU_AB_delivery_delay <> case when d.delivery_delay <= phou.PHOU_AB_delivery_delay                                            
then d.delivery_delay 
else PHOU.PHOU_AB_delivery_delay 
end
or phou.PHOU_AB_closing_mode <> case when phou.PHOU_AB_closing_mode = 1                                        
then PHOU.PHOU_AB_closing_mode                                         
else d.closing_mode                          
end)
end else begin
select phou.PH_organizational_unit_GUID,
phou.PHOU_AB_delivery_delay ,'-->', case when d.delivery_delay <= phou.PHOU_AB_delivery_delay                                            
then d.delivery_delay 
else PHOU.PHOU_AB_delivery_delay 
end,
phou.PHOU_AB_closing_mode ,'-->', case when phou.PHOU_AB_closing_mode = 1                                        
then PHOU.PHOU_AB_closing_mode                                         
else d.closing_mode                          
end  
from dbo.PH_organizational_unit PHOU (nolock)
join @day_delay d  
on day(@today) between d.day_from and d.day_to
and month(@today) = 12
where PHOU_AB_delivery_delay is not null
and (PHOU_AB_delivery_delay <> case when d.delivery_delay <= phou.PHOU_AB_delivery_delay                                            
then d.delivery_delay 
else PHOU.PHOU_AB_delivery_delay 
end
or phou.PHOU_AB_closing_mode <> case when phou.PHOU_AB_closing_mode = 1                                        
then PHOU.PHOU_AB_closing_mode                                         
else d.closing_mode                          
end  )
end
/*=======================================================================
STEP 06 - Rétablissement des anciennes valeurs
=======================================================================*/
if month(@today) = 12 and day(@today) = 31 begin
if @mode = 2 begin
update phou
set phou.PHOU_AB_delivery_delay = phouh.phouh_PHOU_AB_delivery_delay,
phou.PHOU_AB_closing_mode = phouh.phouh_PHOU_AB_closing_mode
from dbo.PH_organizational_unit phou (nolock)
join arizonacust.dbo.PH_organizational_unit_history phouh (nolock)  
on phouh.phouh_PH_Organizational_Unit_guid = phou.PH_organizational_unit_GUID
and phouh.phouh_year = year(@today)
end else begin
select phou.PHOU_AB_delivery_delay ,'-->', phouh.phouh_PHOU_AB_delivery_delay,
phou.PHOU_AB_closing_mode ,'-->', phouh.phouh_PHOU_AB_closing_mode
from dbo.PH_organizational_unit phou (nolock)
join arizonacust.dbo.PH_organizational_unit_history phouh (nolock)  
on phouh.phouh_PH_Organizational_Unit_guid = phou.PH_organizational_unit_GUID
and phouh.phouh_year = year(@today)
end
end

View File

@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-431 - Spike create numeric Pharmacode column to improve joins", "OCTPDBA-431 - Spike create numeric Pharmacode column to improve joins.ssmssqlproj", "{49200D75-CCE8-4BF7-B00C-8B96138E067A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{49200D75-CCE8-4BF7-B00C-8B96138E067A}.Default|Default.ActiveCfg = Default
{B1C08864-F827-4CCF-AB1E-F948C7534FD0}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AC82683E-EB50-4B8A-AEA5-71EC0DEBFD45}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-431 - Spike create numeric Pharmacode column to improve joins">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="(local):CENTRALINFRA\ua208700">
<Created>2022-12-23T13:40:23.74883+01:00</Created>
<Type>SQL</Type>
<Server>(local)</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB>Arizona</InitialDB>
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="check data.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>check data.sql</FullPath>
</FileNode>
<FileNode Name="ddl.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>ddl.sql</FullPath>
</FileNode>
<FileNode Name="todo.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>todo.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,25 @@
USE [Arizona]
SELECT [PHGD_ACSC_PharmacodeNum]
FROM [dbo].[PHGD_ACSC] [pa]
WHERE TRY_CONVERT(INT,[pa].[PHGD_ACSC_PharmacodeNum]) IS NULL
SELECT [pa].[PHGD_ACXI_PharmacodeNum]
FROM [dbo].[PHGD_ACXI] [pa]
WHERE TRY_CONVERT(INT,[pa].[PHGD_ACXI_PharmacodeNum]) IS NULL
SELECT TOP 10 *
FROM [dbo].[Item_key] [ik]
WHERE [ik].[ITK_type]=1 --phcode
SELECT TOP 10
i.*
,[it].[ITTX_description]
,[it].[ITTX_language]
,ik.[Item_key_ID]
,ik.[ITK_key]
,ik.[ITK_label_text]
FROM [dbo].[Item] [i]
JOIN [dbo].[Item_text] [it] ON it.[ITTX_item] = i.[Item_ID]
JOIN [dbo].[Item_key] [ik] ON ik.[ITK_item] = i.[Item_ID]

View File

@@ -0,0 +1,135 @@
USE [Arizona]
SELECT TOP 10 *
FROM PHGD_ACXI
/*
CREATE TABLE [dbo].[PHGD_ACXI]
(
[PHGD_ACXI_GUID] [dbo].[GUID_identifier] NOT NULL,
[PHGD_ACXI_pharmacode] [dbo].[GUID_identifier] NULL,
[PHGD_ACXI_interaction] [dbo].[GUID_identifier] NULL,
[PHGD_ACXI_classification] [dbo].[Alpha_table_key] NULL,
[PHGD_ACXI_relevance] [dbo].[Small_integer] NULL,
[PHGD_ACXI_status] [dbo].[Small_integer] NULL,
[PHGD_ACXI_TS] [timestamp] NOT NULL,
[PHGD_ACXI_VGUID] [dbo].[VGUID_identifier] NULL CONSTRAINT [DF__PHGD_ACXI__PHGD___59CFA7C1] DEFAULT (newid()),
[PHGD_ACXI_master_ID] [dbo].[Large_name_field] NULL,
[PHGD_ACXI_PharmacodeNum] [dbo].[Small_alphabetical_field] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PHGD_ACXI] ADD CONSTRAINT [PK__PHGD_ACXI__58DB8388] PRIMARY KEY NONCLUSTERED ([PHGD_ACXI_GUID]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [NCIX_PHGD_ACXI_COL_PHGD_ACXI_PharmacodeNum] ON [dbo].[PHGD_ACXI] ([PHGD_ACXI_PharmacodeNum]) WITH (FILLFACTOR=100) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [NCIX_PHGD_ACXI_PharmacodeNum_Interaction_Classification] ON [dbo].[PHGD_ACXI] ([PHGD_ACXI_PharmacodeNum], [PHGD_ACXI_interaction], [PHGD_ACXI_classification]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
*/
SELECT TOP 10 *
FROM PHGD_ACSC
/*
CREATE TABLE [dbo].[PHGD_ACSC]
(
[PHGD_ACSC_GUID] [dbo].[GUID_identifier] NOT NULL,
[PHGD_ACSC_pharmacode] [dbo].[GUID_identifier] NULL,
[PHGD_ACSC_substance] [dbo].[GUID_identifier] NULL,
[PHGD_ACSC_sequence] [dbo].[Unique_identifier] NULL,
[PHGD_ACSC_quantity] [dbo].[Small_alphabetical_field] NULL,
[PHGD_ACSC_quantity_unit] [dbo].[Normal_name_field] NULL,
[PHGD_ACSC_code] [dbo].[Alpha_table_key] NULL,
[PHGD_ACSC_status] [dbo].[Small_integer] NULL,
[PHGD_ACSC_TS] [timestamp] NOT NULL,
[PHGD_ACSC_VGUID] [dbo].[VGUID_identifier] NULL CONSTRAINT [DF__PHGD_ACSC__PHGD___513A61C0] DEFAULT (newid()),
[PHGD_ACSC_master_ID] [dbo].[Large_name_field] NULL,
[PHGD_ACSC_PharmacodeNum] [dbo].[Small_alphabetical_field] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PHGD_ACSC] ADD CONSTRAINT [PK__PHGD_ACSC__50463D87] PRIMARY KEY NONCLUSTERED ([PHGD_ACSC_GUID]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [NCUIX_PHGDACSC_COL_PHGDPharmacodeNum] ON [dbo].[PHGD_ACSC] ([PHGD_ACSC_PharmacodeNum], [PHGD_ACSC_sequence]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
*/
SELECT TOP 10 *
FROM [dbo].[PH_item] [pi]
/*
CREATE TABLE [dbo].[PH_item]
(
[PH_item_GUID] [dbo].[GUID_identifier] NOT NULL,
[PHIT_OICM_code] [dbo].[GUID_identifier] NULL,
[PHIT_refund_code] [dbo].[GUID_identifier] NULL,
[PHIT_item] [dbo].[Unique_identifier] NOT NULL,
[PHIT_std_posology] [dbo].[GUID_identifier] NULL,
[PHIT_code] [dbo].[Small_alphabetical_field] NULL,
[PHIT_type] [dbo].[Small_integer] NULL,
[PHIT_tax] [dbo].[Boolean_Code] NOT NULL CONSTRAINT [DF__PH_item__PHIT_ta__566BF0CA] DEFAULT (0),
[PHIT_points] [dbo].[Quantities] NULL,
[PHIT_OFAC_code] [dbo].[Small_alphabetical_field] NULL,
[PHIT_tariff_code] [dbo].[Alpha_table_key] NULL,
[PHIT_prescription_mandatory] [dbo].[Boolean_Code] NOT NULL CONSTRAINT [DF__PH_item__PHIT_pr__57601503] DEFAULT (0),
[PHIT_posology_mandatory] [dbo].[Boolean_Code] NOT NULL CONSTRAINT [DF__PH_item__PHIT_po__5854393C] DEFAULT (0),
[PHIT_APS_TS] [dbo].[APS_timestamp] NOT NULL CONSTRAINT [DF__PH_item__PHIT_AP__59485D75] DEFAULT (getdate()),
[PHIT_VGUID] [dbo].[VGUID_identifier] NULL CONSTRAINT [DF__PH_item__PHIT_VG__5A3C81AE] DEFAULT (newid()),
[PHIT_master_ID] [dbo].[Large_name_field] NULL,
[PHIT_TS] [timestamp] NOT NULL,
[PHIT_substitution] [dbo].[Small_integer] NULL,
[PHIT_usage_limit_management] [dbo].[Small_integer] NULL,
[PHIT_economical_order_qty] [dbo].[Quantities] NULL,
[PHIT_supplying_batch_qty] [dbo].[Quantities] NULL,
[PHIT_safety_qty] [dbo].[Quantities] NULL,
[PHIT_generic_source] [dbo].[Small_alphabetical_field] NULL,
[PHIT_strict_generic] [dbo].[Small_integer] NULL,
[PHIT_GD_withdrawal_override] [dbo].[Small_integer] NULL,
[PHIT_GD_info_override] [dbo].[Small_integer] NULL,
[PHIT_GD_refund_code_override] [dbo].[Small_integer] NULL,
[PHIT_aids_and_appliances_list] [dbo].[Small_integer] NULL CONSTRAINT [DF__PH_item__PHIT_ai__2BF09CED] DEFAULT ((1)),
[PHIT_insurance_code] [dbo].[Small_integer] NULL,
[PHIT_Product_number] [dbo].[Unique_identifier] NULL,
[PHIT_AbusePotential] [dbo].[Boolean_Code] NOT NULL CONSTRAINT [DF__PH_item__PHIT_Ab__5766CF20] DEFAULT ((0)),
[PHIT_expiry] [smallint] NULL,
[PHIT_group_code] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_large_package_type] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_narcotic] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_narcotic_code] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_number_of_pieces] [int] NULL,
[PHIT_refrigeration] [int] NULL,
[PHIT_safety_data_sheet_date_english] [datetime] NULL,
[PHIT_safety_data_sheet_date_french] [datetime] NULL,
[PHIT_safety_data_sheet_date_german] [datetime] NULL,
[PHIT_safety_data_sheet_date_italian] [datetime] NULL,
[PHIT_sloplus] [int] NULL,
[PHIT_withdrawal_date] [datetime] NULL,
[PHIT_assortment_1] [dbo].[GUID_identifier] NULL,
[PHIT_assortment_2] [dbo].[GUID_identifier] NULL,
[PHIT_temperature] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_toxic] [bit] NULL,
[PHIT_toxicity_class] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_packaging] [int] NULL,
[PHIT_chemical_group] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PHIT_TariffModel] [bit] NOT NULL CONSTRAINT [DF_PHIT_TariffModel] DEFAULT ((0)),
[PHIT_XyxleInfo] [bit] NOT NULL CONSTRAINT [DF_PHIT_XyxleInfo] DEFAULT ((0)),
[PHIT_large_generic_sequence] [smallint] NULL,
[PHIT_limitation_exist] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PH_item] ADD CONSTRAINT [PK__PH_item__5577CC91] PRIMARY KEY NONCLUSTERED ([PH_item_GUID]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [XIF3030PH_item] ON [dbo].[PH_item] ([PHIT_item]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [NCIX_PH_item_COL_PHIT_Product_number] ON [dbo].[PH_item] ([PHIT_Product_number]) INCLUDE ([PH_item_GUID]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [XIE2PH_item] ON [dbo].[PH_item] ([PHIT_master_ID]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PH_item] ADD CONSTRAINT [FKPHITAssortment1] FOREIGN KEY ([PHIT_assortment_1]) REFERENCES [dbo].[PHGD_CODES] ([PHGD_CODES_GUID])
GO
ALTER TABLE [dbo].[PH_item] ADD CONSTRAINT [FKPHITAssortment2] FOREIGN KEY ([PHIT_assortment_2]) REFERENCES [dbo].[PHGD_CODES] ([PHGD_CODES_GUID])
GO
EXEC sp_addextendedproperty N'1', N'Avec Modèle tarifaire', 'SCHEMA', N'dbo', 'TABLE', N'PH_item', 'COLUMN', N'PHIT_TariffModel'
GO
*/
SELECT TOP (100) * FROM [dbo].[Item_key] [ik]
WHERE [ik].[ITK_type] = 1 --phcode

View File

@@ -0,0 +1,32 @@
/*
[PHGD_ACXI]
aucune donnée non numérique dans le champ PHGD_ACXI_PharmacodeNum dans les pharma N1 et N2
recommendation => changement du type du champ
impact en db:
dbo.aps_PHGD_ACXI_1_1
dbo.aps_PHGD_ACXI_2_1
dbo.aps_PHGD_ACXI_3
atl.BusinessCheck2
[PHGD_ACSC]
aucune donnée non numérique dans le champ PHGD_ACXI_PharmacodeNum dans les pharma N1 et N2
recommendation => changement du type du champ
impact en db:
dbo.aps_DWT_Item_Search_Generate_1_3
dbo.aps_PH_Prescription_Line_5
dbo.aps_PH_Prescription_Line_5_3
dbo.aps_PH_Search_Item_1_1
dbo.aps_PH_Search_Item_1_2
dbo.aps_PH_Search_Item_1_3
dbo.aps_PH_Search_Item_1_5
dbo.aps_PHGD_SC_3
atl.BusinessCheck2
Question:
* le mail en pièce jointe dans la us parle d'un autre spike, est-ce que c'est relevant ?
* Est-ce que l'ajout d'une FK vers item.PH_item_GUID ne serait pas plus judicieux ?
Dans le mail en pièce joint, Gilles propose:
Add column Item_id and delete column Pharmacodenum
* item_key.ITK_key est de type [dbo].[Normal_name_field], qui est un varchar(30), il n'y a donc pas de pharmacode au format entier en db
*/

View File

@@ -0,0 +1,121 @@
USE [msdb]
GO
/****** Object: Job [D00480 - ActivePos_read Snapshot] Script Date: 09.12.2022 16:30:47 ******/
EXEC msdb.dbo.sp_delete_job @job_name=N'D00480 - ActivePos_read Snapshot', @delete_unused_schedule=1
GO
/****** Object: Job [D00480 - ActivePos_read Snapshot] Script Date: 09.12.2022 16:30:48 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [REPL-Snapshot] Script Date: 09.12.2022 16:30:48 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'REPL-Snapshot' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'REPL-Snapshot'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'D00480 - ActivePos_read Snapshot',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'REPL-Snapshot',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Snapshot Agent startup message.] Script Date: 09.12.2022 16:30:48 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Snapshot Agent startup message.',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=3,
@on_success_step_id=0,
@on_fail_action=3,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'DECLARE @agentIDAPH int
select @agentIDAPH = mssag.id from master.dbo.sysservers syssrv
join MSsnapshot_agents mssag on mssag.publisher_id = syssrv.srvid
where mssag.name = ''D00480 - ActivePos_read Snapshot''
exec sp_MSadd_snapshot_history @perfmon_increment = 0, @agent_id = @agentIDAPH, @runstatus = 1,
@comments = N''Starting agent.''
',
@server=N'SAMNB707VM02\APSSQL',
@database_name=N'master',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Run agent.] Script Date: 09.12.2022 16:30:48 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Run agent.',
@step_id=2,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=3,
@on_fail_step_id=0,
@retry_attempts=2,
@retry_interval=60,
@os_run_priority=0, @subsystem=N'Snapshot',
@command=N'-Publisher [SAMNB707VM02\APSSQL] -PublisherDB [ActivePos_read] -Distributor [SAMNB707VM02\APSSQL] -Publication [ActivePosTran] -DistributorSecurityMode 1',
@server=N'SAMNB707VM02\APSSQL',
@database_name=N'distribution',
@flags=0,
@proxy_name=N'[REPL][aphsqlrepl][ActivePos_read]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Detect nonlogged agent shutdown.] Script Date: 09.12.2022 16:30:48 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Detect nonlogged agent shutdown.',
@step_id=3,
@cmdexec_success_code=0,
@on_success_action=2,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'DECLARE @agentIDAPH int
select @agentIDAPH = mssag.id from master.dbo.sysservers syssrv
join MSsnapshot_agents mssag on mssag.publisher_id = syssrv.srvid
where mssag.name = ''D00480 - ActivePos_read Snapshot''
exec sp_MSdetect_nonlogged_shutdown @subsystem = ''Snapshot'', @agent_id = @agentIDAPH
',
@server=N'SAMNB707VM02\APSSQL',
@database_name=N'distribution',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'D00480 - Daily at 06h30',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=1,
@freq_relative_interval=1,
@freq_recurrence_factor=0,
@active_start_date=20200113,
@active_end_date=99991231,
@active_start_time=63000,
@active_end_time=235959,
@schedule_uid=N'5bd29613-25c6-4206-b632-aba4bb8a2f5c'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO

View File

@@ -0,0 +1,119 @@
USE [msdb]
GO
/****** Object: Job [DR00470 - ActivePos_read Log reader] Script Date: 09.12.2022 16:30:24 ******/
EXEC msdb.dbo.sp_delete_job @job_name=N'DR00470 - ActivePos_read Log reader', @delete_unused_schedule=1
GO
/****** Object: Job [DR00470 - ActivePos_read Log reader] Script Date: 09.12.2022 16:30:24 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [REPL-LogReader] Script Date: 09.12.2022 16:30:24 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'REPL-LogReader' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'REPL-LogReader'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'DR00470 - ActivePos_read Log reader',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'REPL-LogReader',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Log Reader Agent startup message.] Script Date: 09.12.2022 16:30:25 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Log Reader Agent startup message.',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=3,
@on_success_step_id=0,
@on_fail_action=3,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'DECLARE @agentIDAPH int
select @agentIDAPH = mslrag.id from master.dbo.sysservers syssrv
join MSlogreader_agents mslrag on mslrag.publisher_id = syssrv.srvid
where mslrag.name = ''DR00470 - ActivePos_read Log reader''
exec sp_MSadd_logreader_history @perfmon_increment = 0, @agent_id = @agentIDAPH, @runstatus = 1,
@comments = N''Starting agent.''
',
@database_name=N'distribution',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Run agent.] Script Date: 09.12.2022 16:30:25 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Run agent.',
@step_id=2,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=3,
@on_fail_step_id=0,
@retry_attempts=2147483647,
@retry_interval=1,
@os_run_priority=0, @subsystem=N'LogReader',
@command=N'-Publisher [SAMNB707VM02\APSSQL] -PublisherDB [ActivePos_read] -Distributor [SAMNB707VM02\APSSQL] -DistributorSecurityMode 1 -Continuous',
@server=N'SAMNB707VM02\APSSQL',
@database_name=N'distribution',
@flags=0,
@proxy_name=N'[REPL][aphsqlrepl][ActivePos_read]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Detect nonlogged agent shutdown.] Script Date: 09.12.2022 16:30:25 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Detect nonlogged agent shutdown.',
@step_id=3,
@cmdexec_success_code=0,
@on_success_action=2,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'DECLARE @agentIDAPH int
select @agentIDAPH = mslrag.id from master.dbo.sysservers syssrv
join MSlogreader_agents mslrag on mslrag.publisher_id = syssrv.srvid
where mslrag.name = ''DR00470 - ActivePos_read Log reader''
exec sp_MSdetect_nonlogged_shutdown @subsystem = ''LogReader'', @agent_id = @agentIDAPH
',
@database_name=N'distribution',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'DR00470 - Starts automatically',
@enabled=1,
@freq_type=64,
@freq_interval=0,
@freq_subday_type=0,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20191206,
@active_end_date=99991231,
@active_start_time=0,
@active_end_time=235959,
@schedule_uid=N'f4fd19c5-67ae-4e36-8651-c63cbfde0135'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO

View File

@@ -0,0 +1,37 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# SQL Server Management Studio Solution File, Format Version 18.00
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{4F2E2C19-372F-40D8-9FA7-9D2138C6997A}") = "OCTPDBA-435 - SQL 2019 bug in Ceres Replication Maintenance tool", "OCTPDBA-435 - SQL 2019 bug in Ceres Replication Maintenance tool.ssmssqlproj", "{9371D1E3-CD2F-46E7-A742-842C8E2E61A9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2DF34B1E-99D6-4A3D-A4D6-A36E61E51C8C}"
ProjectSection(SolutionItems) = preProject
..\..\repos\tfs_DBA.Tools\Main\Scripts\DBAScripts\Bin\CeresReplMaint\FULL_reinit\30_PHARMACY_CREATE_CeresPublication.sql = ..\..\repos\tfs_DBA.Tools\Main\Scripts\DBAScripts\Bin\CeresReplMaint\FULL_reinit\30_PHARMACY_CREATE_CeresPublication.sql
create apos subscription and articles.sql = create apos subscription and articles.sql
D00480 - ActivePos_read Snapshot.sql = D00480 - ActivePos_read Snapshot.sql
DR00470 - ActivePos_read Log reader.sql = DR00470 - ActivePos_read Log reader.sql
drop apos replication.sql = drop apos replication.sql
drop apos subscription and articles.sql = drop apos subscription and articles.sql
ms procs.sql = ms procs.sql
recreate lnk server wam707a02.sql = recreate lnk server wam707a02.sql
update MSdistribution_agents.sql = update MSdistribution_agents.sql
whole query run from powershell.sql = whole query run from powershell.sql
wrong server returned.sql = wrong server returned.sql
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Default|Default = Default|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9371D1E3-CD2F-46E7-A742-842C8E2E61A9}.Default|Default.ActiveCfg = Default
{B27A542F-B116-4BF0-B64A-8A2BE044023F}.Default|Default.ActiveCfg = Default
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D3B87D57-0E93-498E-8EEC-FABF6F0B0542}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="OCTPDBA-435 - SQL 2019 bug in Ceres Replication Maintenance tool">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="ama704aps.amavita.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-12-09T10:38:31.6246823+01:00</Created>
<Type>SQL</Type>
<Server>ama704aps.amavita.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName />
</ConnectionNode>
<ConnectionNode Name="ama707aps.amavita.ch\apssql:CENTRALINFRA\ua208700">
<Created>2022-12-09T10:38:41.2798735+01:00</Created>
<Type>SQL</Type>
<Server>ama707aps.amavita.ch\apssql</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB />
<LoginTimeout>30</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName />
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items />
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
</SqlWorkbenchSqlProject>

View File

@@ -0,0 +1,387 @@
-- Enabling the replication database
use master
exec sp_replicationdboption @dbname = N'ActivePos_read', @optname = N'publish', @value = N'true'
GO
exec [ActivePos_read].sys.sp_addlogreader_agent @job_login = N'CENTRALINFRA\svc-APH-repl', @job_password = 'TWdZItCqjU!uLgws', @publisher_security_mode = 1
GO
-- Adding the transactional publication
use [ActivePos_read]
exec sp_addpublication @publication = N'ActivePosTran', @description = N'Transactional publication of database ''ActivePos_Read''', @sync_method = N'concurrent', @retention = 120, @allow_push = N'true', @allow_pull = N'false', @allow_anonymous = N'true', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21, @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'true', @allow_sync_tran = N'false', @autogen_sync_procs = N'false', @allow_queued_tran = N'false', @allow_dts = N'false', @replicate_ddl = 1, @allow_initialize_from_backup = N'true', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false'
GO
exec sp_addpublication_snapshot @publication = N'ActivePosTran', @frequency_type = 4, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 1, @frequency_subday_interval = 1, @active_start_time_of_day = 63000, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = N'CENTRALINFRA\svc-APH-repl', @job_password = 'TWdZItCqjU!uLgws', @publisher_security_mode = 1
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'sa'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'NT AUTHORITY\SYSTEM'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'AMAVITA\L-AM-AP-SQL-AMA-Pharmacy_Servers_Database_Administrator'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'AMAVITA\hcisqlrepl'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'AMAVITA\L-AM-AP-SQL-AMA-Pharmacy_Servers_Windows_Operations'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'CENTRALINFRA\svc-APH-repl'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'CENTRALINFRA\L-CI-AP-SQL-AMA-Pharmacy_Servers_Windows_Operations'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'CENTRALINFRA\L-CI-AP-SQL-AMA-Pharmacy_Servers_Database_Administrator'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'CENTRALINFRA\svc-GAIA-repl'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'CENTRALPHARMA\G-CP-RL-ORG-GX_IT_IS_WindowsEngineeringServicesI'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'NT SERVICE\SQLAgent$APSSQL'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'NT SERVICE\Winmgmt'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'NT SERVICE\SQLWriter'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'NT SERVICE\MSSQL$APSSQL'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'ittech'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'sqlAppAPHAdm'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'cslt'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'distributor_admin'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'dba'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'sup'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'sqlAppMonitoringviewerUsr'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'sqlLksrvTMPUsr'
GO
exec sp_grant_publication_access @publication = N'ActivePosTran', @login = N'dev'
GO
-- Adding the transactional articles
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Brand', @source_owner = N'dbo', @source_object = N'Brand', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Brand', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboBrand]', @del_cmd = N'CALL [sp_MSdel_dboBrand]', @upd_cmd = N'SCALL [sp_MSupd_dboBrand]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'BrevierText', @source_owner = N'dbo', @source_object = N'BrevierText', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'BrevierText', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboBrevierText]', @del_cmd = N'CALL [sp_MSdel_dboBrevierText]', @upd_cmd = N'SCALL [sp_MSupd_dboBrevierText]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ClinicalCheck', @source_owner = N'dbo', @source_object = N'ClinicalCheck', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ClinicalCheck', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboClinicalCheck]', @del_cmd = N'CALL [sp_MSdel_dboClinicalCheck]', @upd_cmd = N'SCALL [sp_MSupd_dboClinicalCheck]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ClinicalCheckToPatient', @source_owner = N'dbo', @source_object = N'ClinicalCheckToPatient', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ClinicalCheckToPatient', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboClinicalCheckToPatient]', @del_cmd = N'CALL [sp_MSdel_dboClinicalCheckToPatient]', @upd_cmd = N'SCALL [sp_MSupd_dboClinicalCheckToPatient]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ClinicalCheckType', @source_owner = N'dbo', @source_object = N'ClinicalCheckType', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ClinicalCheckType', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboClinicalCheckType]', @del_cmd = N'CALL [sp_MSdel_dboClinicalCheckType]', @upd_cmd = N'SCALL [sp_MSupd_dboClinicalCheckType]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'CommonVar', @source_owner = N'dbo', @source_object = N'CommonVar', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'CommonVar', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboCommonVar]', @del_cmd = N'CALL [sp_MSdel_dboCommonVar]', @upd_cmd = N'SCALL [sp_MSupd_dboCommonVar]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Criteria', @source_owner = N'dbo', @source_object = N'Criteria', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Criteria', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboCriteria]', @del_cmd = N'CALL [sp_MSdel_dboCriteria]', @upd_cmd = N'SCALL [sp_MSupd_dboCriteria]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'CustomerCard', @source_owner = N'dbo', @source_object = N'CustomerCard', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'CustomerCard', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboCustomerCard]', @del_cmd = N'CALL [sp_MSdel_dboCustomerCard]', @upd_cmd = N'SCALL [sp_MSupd_dboCustomerCard]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'CustomerReminder', @source_owner = N'dbo', @source_object = N'CustomerReminder', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'CustomerReminder', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboCustomerReminder]', @del_cmd = N'CALL [sp_MSdel_dboCustomerReminder]', @upd_cmd = N'SCALL [sp_MSupd_dboCustomerReminder]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DatabaseHistory', @source_owner = N'upd', @source_object = N'DatabaseHistory', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'DatabaseHistory', @destination_owner = N'upd', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_updDatabaseHistory]', @del_cmd = N'CALL [sp_MSdel_updDatabaseHistory]', @upd_cmd = N'SCALL [sp_MSupd_updDatabaseHistory]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucher', @source_owner = N'dbo', @source_object = N'DiscountVoucher', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucher', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucher]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucher]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucher]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherActionDefinition', @source_owner = N'dbo', @source_object = N'DiscountVoucherActionDefinition', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherActionDefinition', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherActionDefinition]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherActionDefinition]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherActionDefinition]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherActionDefinitionSpecificTargetItem', @source_owner = N'dbo', @source_object = N'DiscountVoucherActionDefinitionSpecificTargetItem', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherActionDefinitionSpecificTargetItem', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherActionDefinitionSpecificTargetItem]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherActionDefinitionSpecificTargetItem]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherActionDefinitionSpecificTargetItem]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCondition', @source_owner = N'dbo', @source_object = N'DiscountVoucherCondition', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherCondition', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherCondition]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherCondition]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherCondition]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinition', @source_owner = N'dbo', @source_object = N'DiscountVoucherCouponActionDefinition', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherCouponActionDefinition', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherCouponActionDefinition]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherCouponActionDefinition]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherCouponActionDefinition]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinitionPrinting', @source_owner = N'dbo', @source_object = N'DiscountVoucherCouponActionDefinitionPrinting', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherCouponActionDefinitionPrinting', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherCouponActionDefinitionPrinting]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherCouponActionDefinitionPrinting]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherCouponActionDefinitionPrinting]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinitionText', @source_owner = N'dbo', @source_object = N'DiscountVoucherCouponActionDefinitionText', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherCouponActionDefinitionText', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherCouponActionDefinitionText]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherCouponActionDefinitionText]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherCouponActionDefinitionText]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherPackageElement', @source_owner = N'dbo', @source_object = N'DiscountVoucherPackageElement', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherPackageElement', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherPackageElement]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherPackageElement]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherPackageElement]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'DiscountVoucherText', @source_owner = N'dbo', @source_object = N'DiscountVoucherText', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'DiscountVoucherText', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboDiscountVoucherText]', @del_cmd = N'CALL [sp_MSdel_dboDiscountVoucherText]', @upd_cmd = N'SCALL [sp_MSupd_dboDiscountVoucherText]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIBill_Pharmacists_Header', @source_owner = N'dbo', @source_object = N'IIIBill_Pharmacists_Header', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIBill_Pharmacists_Header', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIBill_Pharmacists_Header]', @del_cmd = N'CALL [sp_MSdel_dboIIIBill_Pharmacists_Header]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIBill_Pharmacists_Header]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICommon_Bank_PTT_Master', @source_owner = N'dbo', @source_object = N'IIICommon_Bank_PTT_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICommon_Bank_PTT_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICommon_Bank_PTT_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIICommon_Bank_PTT_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICommon_Bank_PTT_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICommunicationItem', @source_owner = N'dbo', @source_object = N'IIICommunicationItem', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICommunicationItem', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICommunicationItem]', @del_cmd = N'CALL [sp_MSdel_dboIIICommunicationItem]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICommunicationItem]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICountry_Master', @source_owner = N'dbo', @source_object = N'IIICountry_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICountry_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICountry_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIICountry_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICountry_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICoverage_Documents', @source_owner = N'dbo', @source_object = N'IIICoverage_Documents', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICoverage_Documents', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICoverage_Documents]', @del_cmd = N'CALL [sp_MSdel_dboIIICoverage_Documents]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICoverage_Documents]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICurrency_Master', @source_owner = N'dbo', @source_object = N'IIICurrency_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICurrency_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICurrency_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIICurrency_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICurrency_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICustomer', @source_owner = N'dbo', @source_object = N'IIICustomer', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICustomer', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICustomer]', @del_cmd = N'CALL [sp_MSdel_dboIIICustomer]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICustomer]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICustomerCategory', @source_owner = N'dbo', @source_object = N'IIICustomerCategory', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICustomerCategory', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICustomerCategory]', @del_cmd = N'CALL [sp_MSdel_dboIIICustomerCategory]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICustomerCategory]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICustomerGroup', @source_owner = N'dbo', @source_object = N'IIICustomerGroup', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIICustomerGroup', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICustomerGroup]', @del_cmd = N'CALL [sp_MSdel_dboIIICustomerGroup]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICustomerGroup]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIICustomerToPerson', @source_owner = N'dbo', @source_object = N'IIICustomerToPerson', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'IIICustomerToPerson', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIICustomerToPerson]', @del_cmd = N'CALL [sp_MSdel_dboIIICustomerToPerson]', @upd_cmd = N'SCALL [sp_MSupd_dboIIICustomerToPerson]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIDelivery_Note_Header', @source_owner = N'dbo', @source_object = N'IIIDelivery_Note_Header', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIDelivery_Note_Header', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIDelivery_Note_Header]', @del_cmd = N'CALL [sp_MSdel_dboIIIDelivery_Note_Header]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIDelivery_Note_Header]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIDiscountOperation', @source_owner = N'dbo', @source_object = N'IIIDiscountOperation', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIDiscountOperation', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIDiscountOperation]', @del_cmd = N'CALL [sp_MSdel_dboIIIDiscountOperation]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIDiscountOperation]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIDiscountSchemaDetail', @source_owner = N'dbo', @source_object = N'IIIDiscountSchemaDetail', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIDiscountSchemaDetail', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIDiscountSchemaDetail]', @del_cmd = N'CALL [sp_MSdel_dboIIIDiscountSchemaDetail]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIDiscountSchemaDetail]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIExchange_rate', @source_owner = N'dbo', @source_object = N'IIIExchange_rate', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIExchange_rate', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIExchange_rate]', @del_cmd = N'CALL [sp_MSdel_dboIIIExchange_rate]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIExchange_rate]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIGaldatCode11', @source_owner = N'dbo', @source_object = N'IIIGaldatCode11', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIGaldatCode11', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIGaldatCode11]', @del_cmd = N'CALL [sp_MSdel_dboIIIGaldatCode11]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIGaldatCode11]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIInsurance_Master', @source_owner = N'dbo', @source_object = N'IIIInsurance_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIInsurance_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIInsurance_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIIInsurance_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIInsurance_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIInsuranceAgreement', @source_owner = N'dbo', @source_object = N'IIIInsuranceAgreement', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIInsuranceAgreement', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIInsuranceAgreement]', @del_cmd = N'CALL [sp_MSdel_dboIIIInsuranceAgreement]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIInsuranceAgreement]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIInsuranceCodeException', @source_owner = N'dbo', @source_object = N'IIIInsuranceCodeException', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIInsuranceCodeException', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIInsuranceCodeException]', @del_cmd = N'CALL [sp_MSdel_dboIIIInsuranceCodeException]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIInsuranceCodeException]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIInsuranceGroup', @source_owner = N'dbo', @source_object = N'IIIInsuranceGroup', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIInsuranceGroup', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIInsuranceGroup]', @del_cmd = N'CALL [sp_MSdel_dboIIIInsuranceGroup]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIInsuranceGroup]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIInsuranceGroupLink', @source_owner = N'dbo', @source_object = N'IIIInsuranceGroupLink', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIInsuranceGroupLink', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIInsuranceGroupLink]', @del_cmd = N'CALL [sp_MSdel_dboIIIInsuranceGroupLink]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIInsuranceGroupLink]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIInsuranceTaxLink', @source_owner = N'dbo', @source_object = N'IIIInsuranceTaxLink', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIInsuranceTaxLink', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIInsuranceTaxLink]', @del_cmd = N'CALL [sp_MSdel_dboIIIInsuranceTaxLink]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIInsuranceTaxLink]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIItemCommercialRule', @source_owner = N'dbo', @source_object = N'IIIItemCommercialRule', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIItemCommercialRule', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIItemCommercialRule]', @del_cmd = N'CALL [sp_MSdel_dboIIIItemCommercialRule]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIItemCommercialRule]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIItemLink', @source_owner = N'dbo', @source_object = N'IIIItemLink', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIItemLink', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIItemLink]', @del_cmd = N'CALL [sp_MSdel_dboIIIItemLink]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIItemLink]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIItemRelation', @source_owner = N'dbo', @source_object = N'IIIItemRelation', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIItemRelation', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIItemRelation]', @del_cmd = N'CALL [sp_MSdel_dboIIIItemRelation]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIItemRelation]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIManufacturer', @source_owner = N'dbo', @source_object = N'IIIManufacturer', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIManufacturer', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIManufacturer]', @del_cmd = N'CALL [sp_MSdel_dboIIIManufacturer]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIManufacturer]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIINetwork_Registration_Detail', @source_owner = N'dbo', @source_object = N'IIINetwork_Registration_Detail', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIINetwork_Registration_Detail', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIINetwork_Registration_Detail]', @del_cmd = N'CALL [sp_MSdel_dboIIINetwork_Registration_Detail]', @upd_cmd = N'SCALL [sp_MSupd_dboIIINetwork_Registration_Detail]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIINetworkDiscount', @source_owner = N'dbo', @source_object = N'IIINetworkDiscount', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIINetworkDiscount', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIINetworkDiscount]', @del_cmd = N'CALL [sp_MSdel_dboIIINetworkDiscount]', @upd_cmd = N'SCALL [sp_MSupd_dboIIINetworkDiscount]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPartner_Item_Details', @source_owner = N'dbo', @source_object = N'IIIPartner_Item_Details', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPartner_Item_Details', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPartner_Item_Details]', @del_cmd = N'CALL [sp_MSdel_dboIIIPartner_Item_Details]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPartner_Item_Details]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPartner_Stock_Details', @source_owner = N'dbo', @source_object = N'IIIPartner_Stock_Details', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPartner_Stock_Details', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPartner_Stock_Details]', @del_cmd = N'CALL [sp_MSdel_dboIIIPartner_Stock_Details]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPartner_Stock_Details]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPatient_Insurance', @source_owner = N'dbo', @source_object = N'IIIPatient_Insurance', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPatient_Insurance', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPatient_Insurance]', @del_cmd = N'CALL [sp_MSdel_dboIIIPatient_Insurance]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPatient_Insurance]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPayment', @source_owner = N'dbo', @source_object = N'IIIPayment', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'IIIPayment', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPayment]', @del_cmd = N'CALL [sp_MSdel_dboIIIPayment]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPayment]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPerson', @source_owner = N'dbo', @source_object = N'IIIPerson', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPerson', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPerson]', @del_cmd = N'CALL [sp_MSdel_dboIIIPerson]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPerson]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPerson_Title', @source_owner = N'dbo', @source_object = N'IIIPerson_Title', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPerson_Title', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPerson_Title]', @del_cmd = N'CALL [sp_MSdel_dboIIIPerson_Title]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPerson_Title]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPharmaceutical_Master', @source_owner = N'dbo', @source_object = N'IIIPharmaceutical_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPharmaceutical_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPharmaceutical_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIIPharmaceutical_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPharmaceutical_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPharmacy', @source_owner = N'dbo', @source_object = N'IIIPharmacy', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPharmacy', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPharmacy]', @del_cmd = N'CALL [sp_MSdel_dboIIIPharmacy]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPharmacy]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPhysician', @source_owner = N'dbo', @source_object = N'IIIPhysician', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPhysician', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPhysician]', @del_cmd = N'CALL [sp_MSdel_dboIIIPhysician]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPhysician]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPrescription_hdr', @source_owner = N'dbo', @source_object = N'IIIPrescription_hdr', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPrescription_hdr', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPrescription_hdr]', @del_cmd = N'CALL [sp_MSdel_dboIIIPrescription_hdr]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPrescription_hdr]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPrice', @source_owner = N'dbo', @source_object = N'IIIPrice', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPrice', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPrice]', @del_cmd = N'CALL [sp_MSdel_dboIIIPrice]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPrice]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPriceCode', @source_owner = N'dbo', @source_object = N'IIIPriceCode', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPriceCode', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPriceCode]', @del_cmd = N'CALL [sp_MSdel_dboIIIPriceCode]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPriceCode]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIPriceModifier', @source_owner = N'dbo', @source_object = N'IIIPriceModifier', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIPriceModifier', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIPriceModifier]', @del_cmd = N'CALL [sp_MSdel_dboIIIPriceModifier]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIPriceModifier]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIProduct_Form', @source_owner = N'dbo', @source_object = N'IIIProduct_Form', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIProduct_Form', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIProduct_Form]', @del_cmd = N'CALL [sp_MSdel_dboIIIProduct_Form]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIProduct_Form]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIRayon_Code_Master', @source_owner = N'dbo', @source_object = N'IIIRayon_Code_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIRayon_Code_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIRayon_Code_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIIRayon_Code_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIRayon_Code_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIRefundException', @source_owner = N'dbo', @source_object = N'IIIRefundException', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIRefundException', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIRefundException]', @del_cmd = N'CALL [sp_MSdel_dboIIIRefundException]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIRefundException]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIRepetition_Info', @source_owner = N'dbo', @source_object = N'IIIRepetition_Info', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIRepetition_Info', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIRepetition_Info]', @del_cmd = N'CALL [sp_MSdel_dboIIIRepetition_Info]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIRepetition_Info]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISales_Order_Detail', @source_owner = N'dbo', @source_object = N'IIISales_Order_Detail', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISales_Order_Detail', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISales_Order_Detail]', @del_cmd = N'CALL [sp_MSdel_dboIIISales_Order_Detail]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISales_Order_Detail]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISales_Order_Detail_Additional_Info', @source_owner = N'dbo', @source_object = N'IIISales_Order_Detail_Additional_Info', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISales_Order_Detail_Additional_Info', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISales_Order_Detail_Additional_Info]', @del_cmd = N'CALL [sp_MSdel_dboIIISales_Order_Detail_Additional_Info]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISales_Order_Detail_Additional_Info]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISales_Order_Header', @source_owner = N'dbo', @source_object = N'IIISales_Order_Header', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISales_Order_Header', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISales_Order_Header]', @del_cmd = N'CALL [sp_MSdel_dboIIISales_Order_Header]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISales_Order_Header]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIService_Master', @source_owner = N'dbo', @source_object = N'IIIService_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIService_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIService_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIIService_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIService_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISmall_Expense_Master', @source_owner = N'dbo', @source_object = N'IIISmall_Expense_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISmall_Expense_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISmall_Expense_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIISmall_Expense_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISmall_Expense_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchema', @source_owner = N'dbo', @source_object = N'IIISpecialDiscountSchema', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISpecialDiscountSchema', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISpecialDiscountSchema]', @del_cmd = N'CALL [sp_MSdel_dboIIISpecialDiscountSchema]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISpecialDiscountSchema]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchemaDetail', @source_owner = N'dbo', @source_object = N'IIISpecialDiscountSchemaDetail', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISpecialDiscountSchemaDetail', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISpecialDiscountSchemaDetail]', @del_cmd = N'CALL [sp_MSdel_dboIIISpecialDiscountSchemaDetail]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISpecialDiscountSchemaDetail]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchemaDetail_old_prod_2', @source_owner = N'dbo', @source_object = N'IIISpecialDiscountSchemaDetail_old_prod_2', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIISpecialDiscountSchemaDetail_old_prod_2', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIISpecialDiscountSchemaDetail_old_prod_2]', @del_cmd = N'CALL [sp_MSdel_dboIIISpecialDiscountSchemaDetail_old_prod_2]', @upd_cmd = N'SCALL [sp_MSupd_dboIIISpecialDiscountSchemaDetail_old_prod_2]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIStorage_Area', @source_owner = N'dbo', @source_object = N'IIIStorage_Area', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIStorage_Area', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIStorage_Area]', @del_cmd = N'CALL [sp_MSdel_dboIIIStorage_Area]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIStorage_Area]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIITax', @source_owner = N'dbo', @source_object = N'IIITax', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIITax', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIITax]', @del_cmd = N'CALL [sp_MSdel_dboIIITax]', @upd_cmd = N'SCALL [sp_MSupd_dboIIITax]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIUserDetails', @source_owner = N'dbo', @source_object = N'IIIUserDetails', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIUserDetails', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIUserDetails]', @del_cmd = N'CALL [sp_MSdel_dboIIIUserDetails]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIUserDetails]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIVat_Code_Master', @source_owner = N'dbo', @source_object = N'IIIVat_Code_Master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIVat_Code_Master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIVat_Code_Master]', @del_cmd = N'CALL [sp_MSdel_dboIIIVat_Code_Master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIVat_Code_Master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'IIIZip_master', @source_owner = N'dbo', @source_object = N'IIIZip_master', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'IIIZip_master', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboIIIZip_master]', @del_cmd = N'CALL [sp_MSdel_dboIIIZip_master]', @upd_cmd = N'SCALL [sp_MSupd_dboIIIZip_master]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'InsuranceNetwork', @source_owner = N'dbo', @source_object = N'InsuranceNetwork', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'InsuranceNetwork', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboInsuranceNetwork]', @del_cmd = N'CALL [sp_MSdel_dboInsuranceNetwork]', @upd_cmd = N'SCALL [sp_MSupd_dboInsuranceNetwork]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Interaction', @source_owner = N'dbo', @source_object = N'Interaction', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Interaction', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboInteraction]', @del_cmd = N'CALL [sp_MSdel_dboInteraction]', @upd_cmd = N'SCALL [sp_MSupd_dboInteraction]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemComposition', @source_owner = N'dbo', @source_object = N'ItemComposition', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemComposition', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemComposition]', @del_cmd = N'CALL [sp_MSdel_dboItemComposition]', @upd_cmd = N'SCALL [sp_MSupd_dboItemComposition]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemInteraction', @source_owner = N'dbo', @source_object = N'ItemInteraction', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemInteraction', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemInteraction]', @del_cmd = N'CALL [sp_MSdel_dboItemInteraction]', @upd_cmd = N'SCALL [sp_MSupd_dboItemInteraction]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemLimitation', @source_owner = N'dbo', @source_object = N'ItemLimitation', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemLimitation', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemLimitation]', @del_cmd = N'CALL [sp_MSdel_dboItemLimitation]', @upd_cmd = N'SCALL [sp_MSupd_dboItemLimitation]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemLocation', @source_owner = N'dbo', @source_object = N'ItemLocation', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemLocation', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemLocation]', @del_cmd = N'CALL [sp_MSdel_dboItemLocation]', @upd_cmd = N'SCALL [sp_MSupd_dboItemLocation]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemRegulationInfo', @source_owner = N'dbo', @source_object = N'ItemRegulationInfo', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemRegulationInfo', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemRegulationInfo]', @del_cmd = N'CALL [sp_MSdel_dboItemRegulationInfo]', @upd_cmd = N'SCALL [sp_MSupd_dboItemRegulationInfo]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemSearch', @source_owner = N'dbo', @source_object = N'ItemSearch', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemSearch', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemSearch]', @del_cmd = N'CALL [sp_MSdel_dboItemSearch]', @upd_cmd = N'SCALL [sp_MSupd_dboItemSearch]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemSite', @source_owner = N'dbo', @source_object = N'ItemSite', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemSite', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemSite]', @del_cmd = N'CALL [sp_MSdel_dboItemSite]', @upd_cmd = N'SCALL [sp_MSupd_dboItemSite]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'ItemText', @source_owner = N'dbo', @source_object = N'ItemText', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'ItemText', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboItemText]', @del_cmd = N'CALL [sp_MSdel_dboItemText]', @upd_cmd = N'SCALL [sp_MSupd_dboItemText]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'MigrationScriptHistory', @source_owner = N'upd', @source_object = N'MigrationScriptHistory', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'MigrationScriptHistory', @destination_owner = N'upd', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_updMigrationScriptHistory]', @del_cmd = N'CALL [sp_MSdel_updMigrationScriptHistory]', @upd_cmd = N'SCALL [sp_MSupd_updMigrationScriptHistory]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'NumeraryValue', @source_owner = N'dbo', @source_object = N'NumeraryValue', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'NumeraryValue', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboNumeraryValue]', @del_cmd = N'CALL [sp_MSdel_dboNumeraryValue]', @upd_cmd = N'SCALL [sp_MSupd_dboNumeraryValue]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Operation', @source_owner = N'dbo', @source_object = N'Operation', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Operation', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboOperation]', @del_cmd = N'CALL [sp_MSdel_dboOperation]', @upd_cmd = N'SCALL [sp_MSupd_dboOperation]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'OperationRole', @source_owner = N'dbo', @source_object = N'OperationRole', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'OperationRole', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboOperationRole]', @del_cmd = N'CALL [sp_MSdel_dboOperationRole]', @upd_cmd = N'SCALL [sp_MSupd_dboOperationRole]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'OuManager', @source_owner = N'dbo', @source_object = N'OuManager', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'OuManager', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboOuManager]', @del_cmd = N'CALL [sp_MSdel_dboOuManager]', @upd_cmd = N'SCALL [sp_MSupd_dboOuManager]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'PatientQuickInfo', @source_owner = N'dbo', @source_object = N'PatientQuickInfo', @type = N'view schema only', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x0000000008000001, @destination_table = N'PatientQuickInfo', @destination_owner = N'dbo', @status = 16
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'PharmacyItemLink', @source_owner = N'dbo', @source_object = N'PharmacyItemLink', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'PharmacyItemLink', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboPharmacyItemLink]', @del_cmd = N'CALL [sp_MSdel_dboPharmacyItemLink]', @upd_cmd = N'SCALL [sp_MSupd_dboPharmacyItemLink]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'PointOfSale', @source_owner = N'dbo', @source_object = N'PointOfSale', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'PointOfSale', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboPointOfSale]', @del_cmd = N'CALL [sp_MSdel_dboPointOfSale]', @upd_cmd = N'SCALL [sp_MSupd_dboPointOfSale]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Posology', @source_owner = N'dbo', @source_object = N'Posology', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Posology', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboPosology]', @del_cmd = N'CALL [sp_MSdel_dboPosology]', @upd_cmd = N'SCALL [sp_MSupd_dboPosology]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'PrescriberRole', @source_owner = N'dbo', @source_object = N'PrescriberRole', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'PrescriberRole', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboPrescriberRole]', @del_cmd = N'CALL [sp_MSdel_dboPrescriberRole]', @upd_cmd = N'SCALL [sp_MSupd_dboPrescriberRole]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'QrCodes', @source_owner = N'dbo', @source_object = N'QrCodes', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'QrCodes', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboQrCodes]', @del_cmd = N'CALL [sp_MSdel_dboQrCodes]', @upd_cmd = N'SCALL [sp_MSupd_dboQrCodes]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Report', @source_owner = N'dbo', @source_object = N'Report', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Report', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboReport]', @del_cmd = N'CALL [sp_MSdel_dboReport]', @upd_cmd = N'SCALL [sp_MSupd_dboReport]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Role', @source_owner = N'dbo', @source_object = N'Role', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Role', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboRole]', @del_cmd = N'CALL [sp_MSdel_dboRole]', @upd_cmd = N'SCALL [sp_MSupd_dboRole]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'RunOnceScriptHistory', @source_owner = N'upd', @source_object = N'RunOnceScriptHistory', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'RunOnceScriptHistory', @destination_owner = N'upd', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_updRunOnceScriptHistory]', @del_cmd = N'CALL [sp_MSdel_updRunOnceScriptHistory]', @upd_cmd = N'SCALL [sp_MSupd_updRunOnceScriptHistory]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'StandardText', @source_owner = N'dbo', @source_object = N'StandardText', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'StandardText', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboStandardText]', @del_cmd = N'CALL [sp_MSdel_dboStandardText]', @upd_cmd = N'SCALL [sp_MSupd_dboStandardText]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'StandardTextText', @source_owner = N'dbo', @source_object = N'StandardTextText', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'StandardTextText', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboStandardTextText]', @del_cmd = N'CALL [sp_MSdel_dboStandardTextText]', @upd_cmd = N'SCALL [sp_MSupd_dboStandardTextText]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'Substance', @source_owner = N'dbo', @source_object = N'Substance', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'Substance', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboSubstance]', @del_cmd = N'CALL [sp_MSdel_dboSubstance]', @upd_cmd = N'SCALL [sp_MSupd_dboSubstance]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'UserRole', @source_owner = N'dbo', @source_object = N'UserRole', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'UserRole', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboUserRole]', @del_cmd = N'CALL [sp_MSdel_dboUserRole]', @upd_cmd = N'SCALL [sp_MSupd_dboUserRole]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'VestaVersion', @source_owner = N'vesta', @source_object = N'VestaVersion', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'manual', @destination_table = N'VestaVersion', @destination_owner = N'vesta', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_vestaVestaVersion]', @del_cmd = N'CALL [sp_MSdel_vestaVestaVersion]', @upd_cmd = N'SCALL [sp_MSupd_vestaVestaVersion]'
GO
use [ActivePos_read]
exec sp_addarticle @publication = N'ActivePosTran', @article = N'WebService', @source_owner = N'dbo', @source_object = N'WebService', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000000080351FF, @identityrangemanagementoption = N'none', @destination_table = N'WebService', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [sp_MSins_dboWebService]', @del_cmd = N'CALL [sp_MSdel_dboWebService]', @upd_cmd = N'SCALL [sp_MSupd_dboWebService]'
GO
-- Adding the transactional subscriptions
use [ActivePos_read]
exec sp_addsubscription @publication = N'ActivePosTran', @subscriber = N'WAM707A02', @destination_db = N'ActivePos_read', @subscription_type = N'Push', @sync_type = N'replication support only', @article = N'all', @update_mode = N'read only', @subscriber_type = 0
exec sp_addpushsubscription_agent @publication = N'ActivePosTran', @subscriber = N'WAM707A02', @subscriber_db = N'ActivePos_read', @job_login = null, @job_password = null, @subscriber_security_mode = 0, @subscriber_login = N'sqlAppAPHPosUsr', @subscriber_password = 'albKEDO!x$s4HbE%%IXq', @frequency_type = 64, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 4, @frequency_subday_interval = 5, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @dts_package_location = N'Distributor'
GO

View File

@@ -0,0 +1,66 @@
/*=============================================================================
re-create replication
Parameters
----------------------
Context
----------------------
ama707 (sql 2019)
Creation : 09.12.2022 / TSC
Modifications:
=============================================================================*/ BEGIN TRANSACTION
USE [master]
GO
BEGIN TRANSACTION
--#region drop replication subscription
EXEC [ActivePos_read].[dbo].[sp_dropsubscription] @publication = N'ActivePosTran', @article = N'all', @subscriber ='all'
EXEC [ActivePos_read].[dbo].[sp_droppublication] @publication = N'ActivePosTran'
--#endregion
--#region drop linked server
EXEC master.dbo.sp_dropserver @server=N'wam707a02', @droplogins='droplogins'
--#endregion
SELECT *
FROM sys.[servers] [s]
--#region restart ActivePosClientService'
EXEC xp_cmdshell 'net stop ActivePosClientService '
EXEC xp_cmdshell 'net start ActivePosClientService '
--#endregion
--#region start job "backup"
EXEC msdb.dbo.sp_start_job
@job_name = 'D91030 - Backup ActivePos_Read'
,@step_name = 'Purge old ActivePos_Read backups'
;
--#endregion
--#region repair replication
EXEC ActiveSystemServer.dbo.RepairReplication
--#endregion
SELECT *
FROM sys.[servers] [s]
EXEC [ActivePos_server].dbo.[ExecuteOnAllPos]
@query = 'select 1' -- varchar(max)
,@nonQuery = 1 -- bit
,@timeout = 60 -- int
ROLLBACK TRANSACTION
/*
NET
[ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START |
STATISTICS | STOP | TIME | USE | USER | VIEW ]
*/

View File

@@ -0,0 +1,648 @@
-- Dropping the transactional subscriptions
USE [ActivePos_read]
EXEC sp_dropsubscription @publication = N'ActivePosTran', @subscriber = N'WAM707A02', @destination_db = N'ActivePos_read', @article = N'all'
GO
-- Dropping the transactional articles
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Brand', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Brand', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'BrevierText', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'BrevierText', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ClinicalCheck', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ClinicalCheck', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ClinicalCheckToPatient', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ClinicalCheckToPatient', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ClinicalCheckType', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ClinicalCheckType', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'CommonVar', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'CommonVar', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Criteria', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Criteria', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'CustomerCard', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'CustomerCard', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'CustomerReminder', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'CustomerReminder', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DatabaseHistory', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DatabaseHistory', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucher', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucher', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherActionDefinition', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherActionDefinition', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherActionDefinitionSpecificTargetItem', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherActionDefinitionSpecificTargetItem', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherCondition', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCondition', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinition', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinition', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinitionPrinting', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinitionPrinting', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinitionText', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherCouponActionDefinitionText', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherPackageElement', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherPackageElement', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'DiscountVoucherText', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'DiscountVoucherText', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIBill_Pharmacists_Header', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIBill_Pharmacists_Header', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICommon_Bank_PTT_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICommon_Bank_PTT_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICommunicationItem', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICommunicationItem', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICountry_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICountry_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICoverage_Documents', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICoverage_Documents', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICurrency_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICurrency_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICustomer', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICustomer', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICustomerCategory', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICustomerCategory', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICustomerGroup', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICustomerGroup', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIICustomerToPerson', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIICustomerToPerson', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIDelivery_Note_Header', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIDelivery_Note_Header', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIDiscountOperation', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIDiscountOperation', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIDiscountSchemaDetail', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIDiscountSchemaDetail', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIExchange_rate', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIExchange_rate', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIGaldatCode11', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIGaldatCode11', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIInsurance_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIInsurance_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIInsuranceAgreement', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIInsuranceAgreement', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIInsuranceCodeException', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIInsuranceCodeException', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIInsuranceGroup', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIInsuranceGroup', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIInsuranceGroupLink', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIInsuranceGroupLink', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIInsuranceTaxLink', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIInsuranceTaxLink', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIItemCommercialRule', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIItemCommercialRule', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIItemLink', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIItemLink', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIItemRelation', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIItemRelation', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIManufacturer', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIManufacturer', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIINetwork_Registration_Detail', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIINetwork_Registration_Detail', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIINetworkDiscount', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIINetworkDiscount', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPartner_Item_Details', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPartner_Item_Details', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPartner_Stock_Details', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPartner_Stock_Details', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPatient_Insurance', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPatient_Insurance', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPayment', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPayment', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPerson', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPerson', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPerson_Title', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPerson_Title', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPharmaceutical_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPharmaceutical_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPharmacy', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPharmacy', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPhysician', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPhysician', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPrescription_hdr', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPrescription_hdr', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPrice', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPrice', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPriceCode', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPriceCode', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIPriceModifier', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIPriceModifier', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIProduct_Form', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIProduct_Form', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIRayon_Code_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIRayon_Code_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIRefundException', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIRefundException', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIRepetition_Info', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIRepetition_Info', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISales_Order_Detail', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISales_Order_Detail', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISales_Order_Detail_Additional_Info', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISales_Order_Detail_Additional_Info', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISales_Order_Header', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISales_Order_Header', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIService_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIService_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISmall_Expense_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISmall_Expense_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchema', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchema', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchemaDetail', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchemaDetail', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchemaDetail_old_prod_2', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIISpecialDiscountSchemaDetail_old_prod_2', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIStorage_Area', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIStorage_Area', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIITax', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIITax', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIUserDetails', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIUserDetails', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIVat_Code_Master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIVat_Code_Master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'IIIZip_master', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'IIIZip_master', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'InsuranceNetwork', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'InsuranceNetwork', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Interaction', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Interaction', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemComposition', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemComposition', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemInteraction', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemInteraction', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemLimitation', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemLimitation', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemLocation', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemLocation', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemRegulationInfo', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemRegulationInfo', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemSearch', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemSearch', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemSite', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemSite', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'ItemText', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'ItemText', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'MigrationScriptHistory', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'MigrationScriptHistory', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'NumeraryValue', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'NumeraryValue', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Operation', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Operation', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'OperationRole', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'OperationRole', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'OuManager', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'OuManager', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'PatientQuickInfo', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'PatientQuickInfo', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'PharmacyItemLink', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'PharmacyItemLink', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'PointOfSale', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'PointOfSale', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Posology', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Posology', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'PrescriberRole', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'PrescriberRole', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'QrCodes', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'QrCodes', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Report', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Report', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Role', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Role', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'RunOnceScriptHistory', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'RunOnceScriptHistory', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'StandardText', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'StandardText', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'StandardTextText', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'StandardTextText', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'Substance', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'Substance', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'UserRole', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'UserRole', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'VestaVersion', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'VestaVersion', @force_invalidate_snapshot = 1
GO
use [ActivePos_read]
exec sp_dropsubscription @publication = N'ActivePosTran', @article = N'WebService', @subscriber = N'all', @destination_db = N'all'
GO
use [ActivePos_read]
exec sp_droparticle @publication = N'ActivePosTran', @article = N'WebService', @force_invalidate_snapshot = 1
GO
-- Dropping the transactional publication
use [ActivePos_read]
exec sp_droppublication @publication = N'ActivePosTran'
GO

View File

@@ -0,0 +1,90 @@
WITH subscriber( [publisher] , [publication]) AS (
SELECT publisher, subscriber
FROM OPENROWSET('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','SET FMTONLY OFF; EXEC arizona.dbo.sp_helpsubscriberinfo
with result sets ((
[publisher] nvarchar(128),
[subscriber] nvarchar(128),
[type] tinyint,
[login] nvarchar(128),
[password] nvarchar(524),
[commit_batch_size] int,
[status_batch_size] int,
[flush_frequency] int,
[frequency_type] int,
[frequency_interval] int,
[frequency_relative_interval] int,
[frequency_recurrence_factor] int,
[frequency_subday] int,
[frequency_subday_interval] int,
[active_start_time_of_day] int,
[active_end_time_of_day] int,
[active_start_date] int,
[active_end_date] int,
[retryattempt] int,
[retrydelay] int,
[description] nvarchar(255),
[security_mode] int,
[frequency_type2] int,
[frequency_interval2] int,
[frequency_relative_interval2] int,
[frequency_recurrence_factor2] int,
[frequency_subday2] int,
[frequency_subday_interval2] int,
[active_start_time_of_day2] int,
[active_end_time_of_day2] int,
[active_start_date2] int,
[active_end_date2] int
));
') [or]
)
, subscription(subscriber, publication, [destination database]) AS (
SELECT subscriber, publication, [destination database]
FROM OPENROWSET('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','SET FMTONLY OFF; EXEC arizona.dbo.sp_helpsubscription
with result sets ((
[subscriber] nvarchar(128),
[publication] nvarchar(128),
[article] nvarchar(128),
[destination database] nvarchar(128),
[subscription status] int,
[synchronization type] tinyint,
[subscription type] int,
[full subscription] bit,
[subscription name] nvarchar(386),
[update mode] int,
[distribution job id] varbinary(16),
[loopback_detection] bit,
[offload_enabled] bit,
[offload_server] nvarchar(128),
[dts_package_name] nvarchar(128),
[dts_package_location] int,
[subscriber_security_mode] smallint,
[subscriber_login] nvarchar(128),
[subscriber_password] varchar(10),
[job_login] nvarchar(128),
[job_password] varchar(10),
[distrib_agent_name] nvarchar(100),
[subscriber_type] tinyint,
[subscriber_provider] nvarchar(128),
[subscriber_datasource] nvarchar(4000),
[subscriber_providerstring] nvarchar(4000),
[subscriber_location] nvarchar(4000),
[subscriber_catalog] nvarchar(128)
));
') [or]
)
SELECT DISTINCT
[ms].[publication]
,sub.[publisher]
,[ms].[publisher_db]
,pub.subscriber
,pub.[destination database]
FROM [subscription] pub
JOIN [subscriber] sub ON sub.publication = pub.subscriber
JOIN sys.servers s ON s.[data_source] = sub.publication
LEFT JOIN [distribution].dbo.[MSpublications] [ms] ON ms.publication = pub.publication
WHERE pub.[destination database] = 'gaia'
;

View File

@@ -0,0 +1,52 @@
EXEC [distribution].dbo.sp_helpsubscriberinfo;
SELECT [agents].[subscriber_id], [agents].[subscriber_db], s.[name], s.[data_source]
FROM distribution..MSdistribution_agents agents
JOIN sys.[servers] [s] ON s.[server_id] = [agents].[subscriber_id]
WHERE subscriber_db IN ( 'Gaia' )
AND anonymous_subid IS NULL
USE [Arizona]
EXEC dbo.sp_helpsubscription;
EXEC dbo.sp_helpsubscriberinfo;
EXEC dbo.sp_helppublication
SELECT *
FROM [distribution].dbo.[MSpublications] [ms]
SELECT *
FROM [distribution].dbo.[MSpublication_access] [msa]
RETURN
EXEC msdb.dbo.[sp_help_jobserver]
@job_id = 0x009CFE264DE04E428316007B0B0BD218
,@show_last_run_details = 0
;
select
db_name() PublisherDB
, sp.name as PublisherName
, sa.name as TableName
, UPPER(srv.srvname) as SubscriberServerName
from dbo.syspublications sp
join dbo.sysarticles sa on sp.pubid = sa.pubid
join dbo.syssubscriptions s on sa.artid = s.artid
join master.dbo.sysservers srv on s.srvid = srv.srvid
SELECT s.*
FROM [Arizona].[dbo].[syssubscriptions] s
JOIN [Arizona].[sys].[servers] [s2] ON s2.[server_id] = s.srvid
WHERE dest_db='gaia'
AND subscription_type = 0
SELECT *
FROM distribution..MSdistribution_agents agents
WHERE subscriber_db IN ( 'Gaia' )
RETURN
SELECT *
FROM msdb.dbo.[sysjobs] [s]
WHERE [s].[job_id] = 0x009CFE264DE04E428316007B0B0BD218

View File

@@ -0,0 +1,49 @@
USE [master]
GO
/****** Object: LinkedServer [wam707a02] Script Date: 09.12.2022 15:58:13 ******/
EXEC master.dbo.sp_addlinkedserver @server = N'wam707a02', @srvproduct=N'SQL Server'
/* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'wam707a02',@useself=N'False',@locallogin=NULL,@rmtuser=N'sqlAppAPHPosUsr',@rmtpassword='albKEDO!x$s4HbE%%IXq'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'rpc', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'rpc out', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'sub', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'connect timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'collation name', @optvalue=NULL
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'use remote collation', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'wam707a02', @optname=N'remote proc transaction promotion', @optvalue=N'true'
GO

View File

@@ -0,0 +1,92 @@
BEGIN TRANSACTION
SET XACT_ABORT ON
SELECT srv.name,*
FROM
(
SELECT
[agents].[subscriber_id]
,[agents].[subscriber_db]
,[agents].[subscriber_name]
,[agents].[publisher_id]
,[agents].[publisher_db]
,[agents].[publication]
,[agents].[subscription_type]
,[agents].[name]
FROM [distribution]..[MSdistribution_agents] [agents]
WHERE [agents].[subscriber_db] IN ( 'Gaia' )
AND [agents].[anonymous_subid] IS NULL
) sub1
INNER JOIN
(
SELECT publisher,
publisher_db,
publication,
publication_type,
agent_name,
publisher_srvid,
job_id
FROM distribution..MSreplication_monitordata
WHERE publication_id IS NOT NULL
AND agent_type = 3
) sub3
ON sub1.publisher_id = sub3.publisher_srvid
--AND CAST(sub1.job_id AS UNIQUEIDENTIFIER) = sub3.job_id
AND sub1.publisher_db = sub3.publisher_db
AND sub1.publication = sub3.publication
AND sub1.subscription_type = sub3.publication_type
AND sub1.name = sub3.agent_name
JOIN master.sys.servers AS srv
ON srv.server_id = sub1.subscriber_id;
/* update publication server id */
UPDATE a
SET [subscriber_id] = s.[server_id]
FROM [distribution].[dbo].[MSdistribution_agents] a
CROSS JOIN [sys].[servers] [s]
WHERE s.[data_source] LIKE '%GALCTP'
;
/* check after */
SELECT srv.name,*
FROM
(
SELECT
[agents].[subscriber_id]
,[agents].[subscriber_db]
,[agents].[subscriber_name]
,[agents].[publisher_id]
,[agents].[publisher_db]
,[agents].[publication]
,[agents].[subscription_type]
,[agents].[name]
FROM [distribution]..[MSdistribution_agents] [agents]
WHERE [agents].[subscriber_db] IN ( 'Gaia' )
AND [agents].[anonymous_subid] IS NULL
) sub1
INNER JOIN
(
SELECT publisher,
publisher_db,
publication,
publication_type,
agent_name,
publisher_srvid,
job_id
FROM distribution..MSreplication_monitordata
WHERE publication_id IS NOT NULL
AND agent_type = 3
) sub3
ON sub1.publisher_id = sub3.publisher_srvid
--AND CAST(sub1.job_id AS UNIQUEIDENTIFIER) = sub3.job_id
AND sub1.publisher_db = sub3.publisher_db
AND sub1.publication = sub3.publication
AND sub1.subscription_type = sub3.publication_type
AND sub1.name = sub3.agent_name
JOIN master.sys.servers AS srv
ON srv.server_id = sub1.subscriber_id;
ROLLBACK TRANSACTION
SELECT *
FROM sys.servers s

Some files were not shown because too many files have changed in this diff Show More