Posted by planetcall Wed 21st Mar 2007 21:34 - Syntax is SQL - 47 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Description:
Database design for my project
Database design for my project
-
-
USE master
-
IF EXISTS (SELECT * FROM sysdatabases WHERE name='MyShop')
-
begin
-
DROP DATABASE MyShop
-
Print 'Previous database MyShop dropped'
-
end
-
CREATE DATABASE MyShop
-
Print 'Database MyShop created'
-
USE MyShop
-
Print 'Using database MyShop'
-
go
-
-
CREATE TABLE EmpType(
-
EType int PRIMARY KEY,
-
ETypeName varchar(15),
-
--ETypeLevel int --sets the level of a Employee Type. It is for access permissions
-
)
-
print 'Table Created: EmpType'
-
INSERT INTO EmpType VALUES(001,'Administrator')
-
INSERT INTO EmpType VALUES(002,'StockManager')
-
INSERT INTO EmpType VALUES(003,'Cashier')
-
INSERT INTO EmpType VALUES(004,'Customer')
-
-
CREATE TABLE Employee (
-
EID int PRIMARY KEY,
-
EName varchar(15) NOT NULL,
-
EType int REFERENCES EmpType(EType),
-
EAddress varchar(30) NOT NULL,
-
EDOJ datetime NOT NULL
-
)
-
print 'Table Created: Employee'
-
INSERT INTO Employee VALUES(001,'Abhishek',001,'ShantiNagar,Bangalore',2/2/2006)
-
INSERT INTO Employee VALUES(002,'Anthony',002,'JPNagar 4th phase',2/3/2006)
-
INSERT INTO Employee VALUES(003,'Johny',003,'WilsonGarden',5/5/2005)
-
INSERT INTO Employee VALUES(004,'Paul',004,'VidhanSaudha',9/2/2007)
-
-
CREATE TABLE EmpLogin(
-
EID int PRIMARY KEY REFERENCES Employee(EID),
-
EPass char(8) NOT NULL
-
)
-
print 'Table Created: EmpLogin'
-
INSERT INTO EmpLogin VALUES(001,'1234')
-
INSERT INTO EmpLogin VALUES(002,'123123')
-
-
CREATE TABLE ProdType(
-
PType int PRIMARY KEY,
-
PTypeName varchar(15)
-
)
-
print 'Table Created: ProdType'
-
-
CREATE TABLE Product(
-
PID int PRIMARY KEY,
-
PName char(20) UNIQUE NOT NULL,
-
PType int REFERENCES ProdType(PType)
-
)
-
print 'Table Created: Product'
-
-
CREATE TABLE ProdPrice(
-
PID int PRIMARY KEY REFERENCES Product(PID),
-
PMRP money NOT NULL, --Maximum Retail Price
-
PDiscount money --Discount on the product in Rupee;
-
)
-
print 'Table Created: ProdPrice'
-
-
CREATE TABLE Store(
-
PID int PRIMARY KEY REFERENCES Product(PID),
-
PCount int --depletes with every item sold and could be updated as desired
-
)
-
print 'Table Created: Store'
-
-
CREATE TABLE LogCashier( -- Creates a log of the cashier's performance
-
ReceiptID int PRIMARY KEY, -- the unique number of the receipt ex. Date(6chars)-Time(6chars)-2rands.(ex. 210307094398)
-
EID int REFERENCES Employee(EID),
-
LogDate datetime, --contains the time and date of the specific log entry
-
Value money --stores the monetary value of the transaction
-
)
-
print 'Table Created: LogCashier'
-
go
-
-
CREATE VIEW V_Product AS
-
SELECT P.PID , P.PName, PP.PMRP, PP.PDiscount , PP.PMRP-PP.PDiscount AS FinalPrice FROM Product P, ProdPrice PP
-
go
-
print 'View Created: V_Product'
-
go
-
IF EXISTS(SELECT name FROM sysobjects WHERE name = 'ProdCountUpdate' AND type = 'P')
-
begin
-
DROP proc ProdCountUpdate
-
print 'Dropped: Stored Procedure ProdCountUpdate'
-
end
-
go
-
-
CREATE proc ProdCountUpdate --Product.PID,Count
-
@pid int,
-
@quantity int
-
AS
-
UPDATE store SET PCount = (PCount-@quantity) WHERE PID = @pid
-
-
print 'Stored Procedure Created: ProdCountUpdate( pid, quantity)'
-
go
-
-
--reference to datetime format conversion http://www.databasejournal.com/features/mssql/article.php/2197931
PermaLink to this entry https://pastebin.co.uk/12129
Posted by planetcall Wed 21st Mar 2007 21:34 - Syntax is SQL - 47 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0