-- Step 1
USE master;
GO
CREATE DATABASE AmarPOS ON
(NAME = AmarPOS_data,
    FILENAME = 'D:\MajorSoft\AmarPOS.mdf',
    SIZE = 10,
    MAXSIZE = 50,
    FILEGROWTH = 5)
LOG ON
(NAME = AmarPOS_log,
    FILENAME = 'D:\MajorSoft\AmarPOS.ldf',
    SIZE = 5 MB,
    MAXSIZE = 25 MB,
    FILEGROWTH = 5 MB);

-- Step 2
USE SmartStore
DECLARE @WorkDate NVARCHAR(30) = '2023.06.01'
,@SendedDate NVARCHAR(30) = '2023-06-01 00:00:00'
SELECT * INTO AmarPOS..BarCode FROM BarCode
SELECT * INTO AmarPOS..Item FROM Item
SELECT * INTO AmarPOS..Class FROM Class
SELECT * INTO AmarPOS..Sales FROM Sales WHERE WorkDate < @WorkDate
SELECT * INTO AmarPOS..SalesItem FROM SalesItem WHERE WorkDate < @WorkDate
SELECT * INTO AmarPOS..Txn FROM Txn WHERE WorkDate < @WorkDate
SELECT * INTO AmarPOS..Sended FROM Sended WHERE [date] < @SendedDate

-- Step 2
USE SmartStore
DELETE FROM Sales WHERE WorkDate < @WorkDate
DELETE FROM SalesItem WHERE WorkDate < @WorkDate
DELETE FROM Txn WHERE WorkDate < @WorkDate
TRUNCATE TABLE DeletedSalesItem
DELETE FROM Sended WHERE [date] < @SendedDate

--Step 3
USE master
DBCC SHRINKDATABASE (SmartStore);