0% found this document useful (0 votes)
4 views3 pages

App User Notification Details-Table

The document outlines SQL commands for creating and managing tables in an archive and notification database. It includes the creation of the 'app_user_notification_details_archive' and 'Temp_app_user_notification_details' tables, as well as inserting, deleting, and rebuilding records based on specific conditions. The operations focus on archiving notifications older than January 1, 2022, and cleaning up the notification database accordingly.

Uploaded by

mak.ronaldo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

App User Notification Details-Table

The document outlines SQL commands for creating and managing tables in an archive and notification database. It includes the creation of the 'app_user_notification_details_archive' and 'Temp_app_user_notification_details' tables, as well as inserting, deleting, and rebuilding records based on specific conditions. The operations focus on archiving notifications older than January 1, 2022, and cleaning up the notification database accordingly.

Uploaded by

mak.ronaldo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

----------------------------------------------------------------------------------

--Create Table in Archive Database


----------------------------------------------------------------------------------

CREATE TABLE [dbo].[app_user_notification_details_archive](


[TempAppUserNotifyId] [int] IDENTITY(1,1) NOT NULL,
[AppUserNotifyId] [int] NULL,
[Company_Id] [int] NULL,
[Center_Id] [int] NULL,
[Family_Id] [int] NULL,
[created_by] [int] NULL,
[Sponsor_Id] [int] NULL,
[Notification_Id] [int] NULL,
[NotificationType] [smallint] NULL,
[NotificationText] [varchar](500) NULL,
[NotificationDate] [datetime] NULL,
[created_dttm] [datetime] NULL,
[updated_dttm] [datetime] NULL,
[appJobHistId] [int] NULL,
[NotificationStatus] [int] NULL,
[PickedupDate] [datetime] NULL,
[NotificationTitle] [varchar](250) NULL,
[OriginId] [int] NULL,
[ChildId] [int] NULL,
[MedicineType] [tinyint] NULL,
PRIMARY KEY CLUSTERED
(
[TempAppUserNotifyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON
[PRIMARY]
) ON [PRIMARY]
GO

----------------------------------------------------------------------------------
--Create Table in Notification Database
----------------------------------------------------------------------------------

CREATE TABLE [dbo].[Temp_app_user_notification_details](


[TempAppUserNotifyId] [int] IDENTITY(1,1) NOT NULL,
[AppUserNotifyId] [int] NULL,
[jobId] [int] NULL,
[NotificationDate] [datetime] NULL)

insert into
Temp_app_user_notification_details(jobId,AppUserNotifyId,NotificationDate)
SELECT 83,AppUserNotifyId,NotificationDate FROM app_user_notification_details where

NotificationDate < '2022-01-01'


----------------------------------------------------------------------------------
--Insert Record in Archive Database
----------------------------------------------------------------------------------

select count(1) from app_user_notification_details_archive (nolock)

INSERT INTO [dbo].[app_user_notification_details_archive]


([AppUserNotifyId]
,[Company_Id]
,[Center_Id]
,[Family_Id]
,[created_by]
,[Sponsor_Id]
,[Notification_Id]
,[NotificationType]
,[NotificationText]
,[NotificationDate]
,[created_dttm]
,[updated_dttm]
,[appJobHistId]
,[NotificationStatus]
,[PickedupDate]
,[NotificationTitle]
,[OriginId]
,[ChildId]
,[MedicineType])
SELECT
tcc.[AppUserNotifyId]
,tcc.[Company_Id]
,tcc.[Center_Id]
,tcc.[Family_Id]
,tcc.[created_by]
,tcc.[Sponsor_Id]
,tcc.[Notification_Id]
,tcc.[NotificationType]
,tcc.[NotificationText]
,tcc.[NotificationDate]
,tcc.[created_dttm]
,tcc.[updated_dttm]
,tcc.[appJobHistId]
,tcc.[NotificationStatus]
,tcc.[PickedupDate]
,tcc.[NotificationTitle]
,tcc.[OriginId]
,tcc.[ChildId]
,tcc.[MedicineType]
FROM Test_oncare_notification.dbo.[app_user_notification_details] tcc
inner join Test_oncare_notification.dbo.Temp_app_user_notification_details tmp on
tmp.AppUserNotifyId = tcc.AppUserNotifyId
where tmp.jobId = 83
----------------------------------------------------------------------------------
--Delete Record in Notification Database
----------------------------------------------------------------------------------

select count(1)
from app_user_notification_details
where AppUserNotifyId in (select AppUserNotifyId from
Temp_app_user_notification_details
where jobId = 83)

delete from app_user_notification_details where AppUserNotifyId in


(select AppUserNotifyId from Temp_app_user_notification_details where jobId = 83)

delete from Temp_app_user_notification_details where jobId = 83

----------------------------------------------------------------------------------
--Rebuild Record in Notification Database
----------------------------------------------------------------------------------

ALTER TABLE app_user_notification_details REBUILD;

-----------------------------------------------------------------------------------
----------------

You might also like