Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 7

By Mohammad Tayyab Ali and Muhammad Irfan Amin

Roll no : COSC19111032,COSC19111080
DATA BASE SYSTEM
DOCUMENTATION
For Auto Work Shop
DATA BASE SYSTEM DOCUMENTATION

Table of Contents
Query...........................................................................................................................................................2
Inventory:................................................................................................................................................2
Master Invoice:........................................................................................................................................2
Invoice Details:........................................................................................................................................2
Customer Table:.......................................................................................................................................3
Balance Deducted:...................................................................................................................................3
View (For Showing All Information on Printed Invoice):..........................................................................3
Normalized Form:........................................................................................................................................3
For Table Inventory:.................................................................................................................................3
1NF:.....................................................................................................................................................3
2NF:.....................................................................................................................................................3
3NF......................................................................................................................................................4
For MasterInvoice , InvoiceDetails, Customer & BalanceDeducted :.......................................................4
ER Diagram:.................................................................................................................................................4

2|Page
DATA BASE SYSTEM DOCUMENTATION

Query
Inventory:
CREATE TABLE [dbo].[Products] (
[ID] INT Primary key IDENTITY (1, 1) NOT NULL,
[Name] VARCHAR (50) NOT NULL,
[Price] INT NOT NULL,
[Quantity] INT NULL,
[Profit] INT NULL,
[Model] VARCHAR (20) NULL,
[RegNo] VARCHAR (20) NULL,
[Total] INT NOT NULL,
[Catagory] VARCHAR (10) NULL,
[Details] VARCHAR (200) NULL,
[Image] IMAGE NULL,
[Status] VARCHAR (MAX) NULL
);

Master Invoice:
CREATE TABLE [dbo].[MasterInvoice] (
[ID] INT Primary key IDENTITY (1, 1) NOT NULL,
[InvoiceDate] DATETIME NOT NULL,
[CustomerID] VARCHAR (MAX) FOREIGN KEY REFERENCES
customer(CustomerCNIC) NOT NULL,
[SubTotal] INT NOT NULL,
[Discount] INT NOT NULL,
[Balance] INT NULL,
[Paid] INT NOT NULL,
[CustomerName] VARCHAR (MAX) NULL,
[GrandTotal] INT NULL
);

Invoice Details:
CREATE TABLE [dbo].[InvoiceDetails] (
[DetailID] INT Primary Key IDENTITY (1, 1) NOT NULL,
[MasterID] INT FOREIGN KEY REFERENCES MasterInvoice(ID)
NOT NULL,

3|Page
DATA BASE SYSTEM DOCUMENTATION

[itemID] int INT FOREIGN KEY REFERENCS Products(ID) NOT


NULL,
[itemName] VARCHAR (MAX) NOT NULL,
[itemPrice] INT NOT NULL,
[itemQtty] INT NULL,
[itemTotal] INT NULL
);

Customer Table:
CREATE TABLE [dbo]. [customer] (
[CustomerPhone] VARCHAR (MAX) NULL,
[CustomerName] VARCHAR (MAX) NOT NULL,
[CustomerLastName] VARCHAR (MAX) NULL,
[CustomerCNIC] VARCHAR Primary Key (50) NOT NULL,
[CustomerBalance] INT NULL,
[CustomerAddress] VARCHAR (MAX) NULL
);

Balance Deducted:
CREATE TABLE [dbo].[BalanceDeducted] (
[id] INT Primary Key IDENTITY (1, 1) NOT
NULL,
[CustomerID] VARCHAR (MAX) FOREIGN KEY REFERENCES
customer(CustomerCNIC) NOT NULL,
[Dated] DATETIME NULL,
[CustomerName] VARCHAR (MAX) NULL,
[CustomerPrevBalance] INT NULL,
[BalanceDeducted] INT NULL,
[NewBalance] INT NULL
);

View (For Showing All Information on Printed Invoice):


create view [dbo].[ViewAllBill]
AS
select m.*,d.* from MasterInvoice m inner join InvoiceDetails d
ON m.ID=d.MasterID

4|Page
DATA BASE SYSTEM DOCUMENTATION

Normalized Form:
For Table Inventory:

1NF:
Table is already in 1NF as it does not contains any columns with multiple values and each record has a
unique key variable as known as Primary Key which is in this case ProductID.

2NF:
2nd NF first condition is satisfied as the table is already in 1st NF. Secondly all the quantities in the depend
are not partially dependent on composite keys.

3NF
Table is already in 2NF so the first condition is satisfied meanwhile to make the table transitive
dependent the final table in 3rd NF will be:

 Inventory Table:

ID, Name, Price, Qtty, Profit, Model, RegNo, Total, CatagoryID, Details, Image, Status.

 Category Table:

CatagoryID ,CategoryName

For MasterInvoice , InvoiceDetails, Customer & BalanceDeducted :

Tables are already in 2nd Normal Form. And to Convert MasterInvoice, InvoiceDetails & Balance Deducted
to 3rd NF we will Subtract CustomerName From the 3 tables because it is transitive dependent on
CustomerID so we will call this property from Customer Table and Make CustomerID a foreign Key in all
these tables.

5|Page
DATA BASE SYSTEM DOCUMENTATION

Relational Diagram:

ER Diagram:

6|Page
DATA BASE SYSTEM DOCUMENTATION

7|Page

You might also like