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

Database Latest

The document outlines the SQL schema for a ticketing system, including tables for change tickets, problem tickets, and incident tickets, each with various fields for tracking details. It also defines supporting tables for users, notes, login history, and uploaded files, along with triggers for generating unique ticket IDs. Additionally, indexes are created for optimizing queries on notes and uploaded files based on specific attributes.

Uploaded by

shivmehtra
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 views

Database Latest

The document outlines the SQL schema for a ticketing system, including tables for change tickets, problem tickets, and incident tickets, each with various fields for tracking details. It also defines supporting tables for users, notes, login history, and uploaded files, along with triggers for generating unique ticket IDs. Additionally, indexes are created for optimizing queries on notes and uploaded files based on specific attributes.

Uploaded by

shivmehtra
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

-- Main Ticket Tables

CREATE TABLE change_tickets (


id INT AUTO_INCREMENT PRIMARY KEY,
change_ticket_id VARCHAR(10) UNIQUE,
requestor VARCHAR(255) NOT NULL,
source VARCHAR(50) NOT NULL,
impact VARCHAR(50) NOT NULL,
urgency VARCHAR(50) NOT NULL,
priority VARCHAR(20) NOT NULL,
type VARCHAR(20) NOT NULL,
slate_accepted VARCHAR(50) NOT NULL,
category VARCHAR(50) NOT NULL,
short_description TEXT NOT NULL,
detailed_description TEXT NOT NULL,
status VARCHAR(50) DEFAULT 'Unassigned',
created_by INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
assigned_to INT
);

CREATE TABLE problem_tickets (


id INT AUTO_INCREMENT PRIMARY KEY,
problem_ticket_id VARCHAR(10) UNIQUE,
requestor VARCHAR(100) NOT NULL,
source VARCHAR(50) NOT NULL,
impact VARCHAR(50) NOT NULL,
urgency VARCHAR(50) NOT NULL,
priority VARCHAR(20) NOT NULL,
type VARCHAR(20) NOT NULL,
slate_accepted VARCHAR(50) NOT NULL,
opened_date DATETIME,
category VARCHAR(50) NOT NULL,
short_description TEXT NOT NULL,
detailed_description TEXT NOT NULL,
status VARCHAR(50) DEFAULT 'Unassigned',
created_by INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
assigned_to INT
);

CREATE TABLE incident_tickets (


id INT AUTO_INCREMENT PRIMARY KEY,
incident_ticket_id VARCHAR(10) UNIQUE,
user_name VARCHAR(255) NOT NULL,
user_contact VARCHAR(10) NOT NULL,
user_email VARCHAR(255) NOT NULL,
product VARCHAR(100) NOT NULL,
version VARCHAR(50),
mobile_model VARCHAR(100),
short_description TEXT NOT NULL,
category VARCHAR(50) NOT NULL,
priority VARCHAR(20) NOT NULL,
dealer_name VARCHAR(255),
dealer_contact VARCHAR(10),
dealer_email VARCHAR(255),
status VARCHAR(50) DEFAULT 'Unassigned',
created_by INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
assigned_to INT
);

-- Supporting Tables
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(20) NOT NULL,
name VARCHAR(100) NOT NULL,
mobile VARCHAR(15) NOT NULL,
status VARCHAR(10) DEFAULT 'Active'
);

CREATE TABLE notes (


id INT AUTO_INCREMENT PRIMARY KEY,
ticket_id VARCHAR(50) NOT NULL,
ticket_type VARCHAR(20) NOT NULL,
content TEXT NOT NULL,
created_by VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
work_note VARCHAR(500),
custmor_note VARCHAR(500) -- Note: Typo preserved to match code
);

CREATE TABLE login_history (


id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
login_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Indexes
CREATE INDEX IX_notes_ticket ON notes (ticket_id, ticket_type, created_at);

-- Triggers for Ticket ID Generation


DELIMITER //

CREATE TRIGGER before_change_insert


BEFORE INSERT ON change_tickets
FOR EACH ROW
BEGIN
SET NEW.change_ticket_id = CONCAT('CHN', LPAD(COALESCE(
(SELECT MAX(CAST(SUBSTRING(change_ticket_id, 4) AS UNSIGNED)) + 1
FROM change_tickets), 1), 6, '0'));
END//

CREATE TRIGGER before_problem_insert


BEFORE INSERT ON problem_tickets
FOR EACH ROW
BEGIN
SET NEW.problem_ticket_id = CONCAT('PRB', LPAD(COALESCE(
(SELECT MAX(CAST(SUBSTRING(problem_ticket_id, 4) AS UNSIGNED)) + 1
FROM problem_tickets), 1), 6, '0'));
END//

CREATE TRIGGER before_incident_insert


BEFORE INSERT ON incident_tickets
FOR EACH ROW
BEGIN
SET NEW.incident_ticket_id = CONCAT('INC', LPAD(COALESCE(
(SELECT MAX(CAST(SUBSTRING(incident_ticket_id, 4) AS UNSIGNED)) + 1
FROM incident_tickets), 1), 6, '0'));
END//

DELIMITER ;

-- Add this to Supporting Tables section


CREATE TABLE uploadedfiles (
Id INT AUTO_INCREMENT PRIMARY KEY,
FileName VARCHAR(255) NOT NULL,
Title VARCHAR(255) NOT NULL,
Description TEXT NOT NULL,
UploadDate DATETIME DEFAULT CURRENT_TIMESTAMP,
FilePath VARCHAR(255) NOT NULL
);

-- Add this to Indexes section


CREATE INDEX IX_uploadedfiles_uploaddate ON uploadedfiles (UploadDate);

You might also like