0% found this document useful (0 votes)
4 views

QUERY-SQL

The document outlines the SQL schema for a recharge application, including tables for Users, Recharge Plans, Transactions, Feedback, Postpaid Payments, Services, User Services, and Customer Care. It also includes sample data inserts for default users, services, recharge plans, transactions, feedback, postpaid payments, activated services, and customer care contact details. The schema enforces data integrity through constraints such as primary keys, foreign keys, and check conditions.

Uploaded by

mtehseen512
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

QUERY-SQL

The document outlines the SQL schema for a recharge application, including tables for Users, Recharge Plans, Transactions, Feedback, Postpaid Payments, Services, User Services, and Customer Care. It also includes sample data inserts for default users, services, recharge plans, transactions, feedback, postpaid payments, activated services, and customer care contact details. The schema enforces data integrity through constraints such as primary keys, foreign keys, and check conditions.

Uploaded by

mtehseen512
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

-- User Table

CREATE TABLE Users (


UserID INT IDENTITY(1,1) PRIMARY KEY,
Username VARCHAR(50) UNIQUE NOT NULL,
Email VARCHAR(100) UNIQUE NOT NULL,
Password VARCHAR(100) NOT NULL,
Role VARCHAR(20) CHECK (Role IN ('Admin', 'User')) NOT NULL,
Status VARCHAR(10) CHECK (Status IN ('Active', 'Inactive')) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE()
);

-- Recharge Plans
CREATE TABLE RechargePlans (
PlanID INT IDENTITY(1,1) PRIMARY KEY,
PlanType VARCHAR(20) CHECK (PlanType IN ('TopUp', 'Special')),
Amount DECIMAL(10,2) NOT NULL,
TalkTime DECIMAL(10,2),
Validity INT CHECK (Validity > 0) NOT NULL,
Description VARCHAR(255)
);

-- Transactions
CREATE TABLE Transactions (
TransactionID INT IDENTITY(1,1) PRIMARY KEY,
UserID INT FOREIGN KEY REFERENCES Users(UserID),
MobileNumber VARCHAR(10) NOT NULL CHECK (MobileNumber LIKE '[0-9][0-9][0-9][0-
9][0-9][0-9][0-9][0-9][0-9][0-9]'),
PlanID INT FOREIGN KEY REFERENCES RechargePlans(PlanID),
PaymentStatus VARCHAR(20) CHECK (PaymentStatus IN ('Pending', 'Completed',
'Failed')),
TransactionDate DATETIME DEFAULT GETDATE()
);

-- Feedback Table
CREATE TABLE Feedback (
FeedbackID INT IDENTITY(1,1) PRIMARY KEY,
UserID INT NULL FOREIGN KEY REFERENCES Users(UserID),
Message TEXT NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE()
);

-- Postpaid Bill Payments


CREATE TABLE PostpaidPayments (
PaymentID INT IDENTITY(1,1) PRIMARY KEY,
UserID INT FOREIGN KEY REFERENCES Users(UserID),
MobileNumber VARCHAR(10) NOT NULL CHECK (MobileNumber LIKE '[0-9][0-9][0-9][0-
9][0-9][0-9][0-9][0-9][0-9][0-9]'),
Amount DECIMAL(10,2) NOT NULL,
PaymentStatus VARCHAR(20) CHECK (PaymentStatus IN ('Pending', 'Completed',
'Failed')),
PaymentDate DATETIME DEFAULT GETDATE()
);

-- Services Activation
CREATE TABLE Services (
ServiceID INT IDENTITY(1,1) PRIMARY KEY,
ServiceName VARCHAR(50) UNIQUE NOT NULL
);
-- User Services (Mapping table for activated services)
CREATE TABLE UserServices (
UserServiceID INT IDENTITY(1,1) PRIMARY KEY,
UserID INT FOREIGN KEY REFERENCES Users(UserID),
ServiceID INT FOREIGN KEY REFERENCES Services(ServiceID),
Status VARCHAR(20) CHECK (Status IN ('Active', 'Inactive')) NOT NULL,
ActivatedAt DATETIME DEFAULT GETDATE()
);

-- Customer Care
CREATE TABLE CustomerCare (
ContactID INT IDENTITY(1,1) PRIMARY KEY,
ContactNumber VARCHAR(15) NOT NULL,
Email VARCHAR(100) NOT NULL
);

-- Insert default users


INSERT INTO Users (Username, Email, Password, Role, Status, CreatedAt, UpdatedAt)
VALUES
('admin', '[email protected]', 'admin', 'Admin', 'Active', '2025-01-31
17:45:34.950', '2025-01-31 17:45:34.950'),
('ahmedkhan', '[email protected]', '123', 'User', 'Active', '2025-01-31
17:45:34.950', '2025-01-31 17:45:34.950'),
('fatimabaloch', '[email protected]', '123', 'User', 'Active', '2025-01-
31 17:45:34.950', '2025-01-31 17:45:34.950'),
('mohsinali', '[email protected]', '123', 'User', 'Active', '2025-01-31
17:45:34.950', '2025-01-31 17:45:34.950');

-- Insert default services


INSERT INTO Services (ServiceName) VALUES ('Do not Disturb'), ('Caller Tunes'),
('Online Recharge');

-- Insert Recharge Plans


INSERT INTO RechargePlans (PlanType, Amount, TalkTime, Validity, Description)
VALUES
('TopUp', 100, 90, 28, 'Basic Top-Up Plan'),
('TopUp', 200, 190, 56, 'Standard Top-Up Plan'),
('Special', 300, NULL, 30, 'Unlimited Data Plan'),
('Special', 500, NULL, 60, 'Premium Data Plan'),
('TopUp', 50, 45, 10, 'Mini Top-Up Plan');

-- Insert Transactions (Linking Users and Recharge Plans)


INSERT INTO Transactions (UserID, MobileNumber, PlanID, PaymentStatus,
TransactionDate)
VALUES
(2, '9876543210', 1, 'Completed', '2025-02-01 10:15:00'),
(3, '8765432109', 2, 'Completed', '2025-02-01 11:30:00'),
(4, '7654321098', 3, 'Completed', '2025-02-01 12:45:00'),
(2, '6543210987', 4, 'Pending', '2025-02-01 14:00:00'),
(3, '5432109876', 5, 'Completed', '2025-02-01 15:20:00');

-- Insert Feedback (Linking Users)


INSERT INTO Feedback (UserID, Message, CreatedAt)
VALUES
(2, 'Great service, fast recharge!', '2025-02-01 16:00:00'),
(3, 'Please add more data plans.', '2025-02-01 16:30:00'),
(4, 'Recharge process is smooth.', '2025-02-01 17:00:00'),
(2, 'Customer support was helpful.', '2025-02-01 17:30:00'),
(3, 'Need more offers on Top-Up.', '2025-02-01 18:00:00');

-- Insert Postpaid Bill Payments (Linking Users)


INSERT INTO PostpaidPayments (UserID, MobileNumber, Amount, PaymentStatus,
PaymentDate)
VALUES
(2, '9876543210', 500, 'Completed', '2025-02-02 10:00:00'),
(3, '8765432109', 750, 'Pending', '2025-02-02 11:15:00'),
(4, '7654321098', 1000, 'Completed', '2025-02-02 12:30:00'),
(2, '6543210987', 450, 'Completed', '2025-02-02 13:45:00'),
(3, '5432109876', 650, 'Failed', '2025-02-02 15:00:00');

-- Insert Activated Services (Linking Users with Services)


INSERT INTO UserServices (UserID, ServiceID, Status, ActivatedAt)
VALUES
(2, 1, 'Active', '2025-02-03 10:00:00'), -- Ahmed Khan activates "Do not Disturb"
(3, 2, 'Active', '2025-02-03 10:30:00'), -- Fatima Baloch activates "Caller Tunes"
(4, 3, 'Active', '2025-02-03 11:00:00'), -- Mohsin Ali activates "Online Recharge"
(2, 3, 'Inactive', '2025-02-03 11:30:00'), -- Ahmed Khan deactivates "Online
Recharge"
(3, 1, 'Active', '2025-02-03 12:00:00'); -- Fatima Baloch activates "Do not
Disturb"

-- Insert Customer Care Contact Details


INSERT INTO CustomerCare (ContactNumber, Email)
VALUES
('1800-123-4567', '[email protected]'),
('1800-987-6543', '[email protected]');

You might also like