-- =============================================
-- Database: WattsALoan
-- =============================================
USE master
GO
-- Drop the database if it already exists
IF EXISTS (
SELECT name
FROM sys.databases
WHERE name = N'WattsALoan'
)
DROP DATABASE WattsALoan
GO
CREATE DATABASE WattsALoan
GO
-- =========================================
-- Table: Employees
-- =========================================
USE WattsALoan
GO
IF OBJECT_ID('dbo.Employees', 'U') IS NOT NULL
DROP TABLE dbo.Employees
GO
CREATE TABLE dbo.Employees
(
EmployeeID int identity(1,1) NOT NULL,
EmployeeNumber nchar(10) NULL,
FirstName varchar(20) NULL,
LastName varchar(10),
FullName AS ((LastName+ ', ') + FirstName),
Title varchar(100),
HourlySalary money,
Username varchar(20),
Password varchar(20),
CONSTRAINT PK_Employees PRIMARY KEY(EmployeeID)
)
GO
INSERT INTO dbo.Employees(EmployeeNumber, FirstName, LastName, Title, HourlySalary)
VALUES('293747', 'Jeanne', 'Tryler', 'Accounts Manager', 22.24);
GO
INSERT INTO dbo.Employees(EmployeeNumber, FirstName, LastName, Title, HourlySalary)
VALUES('492947', 'Helene', 'Gustman', 'Accounts Representative', 14.55);
GO
INSERT INTO dbo.Employees(EmployeeNumber, FirstName, LastName, Title, HourlySalary)
VALUES('804685', 'Ernest', 'Thomas', 'Accounts Representative', 12.75);
GO
-- =========================================
-- Table: LoanTypes
-- =========================================
USE WattsALoan
GO
IF OBJECT_ID('dbo.LoanTypes', 'U') IS NOT NULL
DROP TABLE dbo.LoanTypes
GO
CREATE TABLE dbo.LoanTypes
(
LoanTypeID int identity(1,1) NOT NULL,
LoanType varchar(50) NOT NULL,
CONSTRAINT PK_LoanTypes PRIMARY KEY(LoanTypeID)
);
GO
INSERT INTO LoanTypes(LoanType) VALUES('Personal Loan');
GO
INSERT INTO LoanTypes(LoanType) VALUES('Car Financing');
GO
INSERT INTO LoanTypes(LoanType) VALUES('Credit Card');
GO
INSERT INTO LoanTypes(LoanType) VALUES('Furniture Loan');
GO
-- =========================================
-- Table: Customers
-- =========================================
USE WattsALoan
GO
IF OBJECT_ID('dbo.Customers', 'U') IS NOT NULL
DROP TABLE dbo.Customers
GO
CREATE TABLE dbo.Customers
(
CustomerID int identity(1,1) NOT NULL,
DateCreated datetime NULL,
FullName varchar(50) NOT NULL,
BillingAddress varchar(100),
BillingCity varchar(50),
BillingState varchar(50),
BillingZIPCide varchar(10),
EmailAddress varchar(100),
CONSTRAINT PK_Customers PRIMARY KEY(CustomerID)
)
GO
INSERT INTO Customers(DateCreated, FullName,
BillingAddress, BillingCity, BillingState,
BillingZIPCide, EmailAddress)
VALUES('2/26/2004', 'Julius Ramse',
'927 Feuler Ave', 'Silver Spring',
'MD', '20904', 'ramses1990@netscape.net');
GO
INSERT INTO Customers(DateCreated, FullName,
BillingAddress, BillingCity, BillingState,
BillingZIPCide)
VALUES('06/22/2006', 'Gertrude Vaillant',
'10055 Larsenic Rd', 'Takoma Park',
'MD', '20910');
GO
INSERT INTO Customers(DateCreated, FullName,
BillingAddress, BillingCity, BillingState,
BillingZIPCide, EmailAddress)
VALUES('12/3/2004', 'James Barrouch',
'4204 Fallon Drive', 'Silver Spring',
'MD', '20906', 'barrouchj@hotmail.com');
GO
INSERT INTO Customers(DateCreated, FullName,
BillingAddress, BillingCity, BillingState,
BillingZIPCide)
VALUES('08/02/2006', 'Christine Rougher',
'825 Manning Street', 'Alexandria',
'VA', '22231');
GO
INSERT INTO Customers(DateCreated, FullName,
BillingAddress, BillingCity, BillingState,
BillingZIPCide, EmailAddress)
VALUES('10/08/2006', 'Patrick Heller',
'2480 Clarington Drive NW', 'Washington',
'DC', '20006', 'hellerp@yahooo.com');
GO
-- =========================================
-- Table: LoanAllocation
-- =========================================
USE WattsALoan
GO
IF OBJECT_ID('dbo.LoanAllocations', 'U') IS NOT NULL
DROP TABLE dbo.LoanAllocations
GO
CREATE TABLE dbo.LoanAllocations
(
LoanAllocationID int identity(1,1) NOT NULL,
DatePrepared datetime NOT NULL,
EmployeeID int NULL
CONSTRAINT FK_LoanPreparer
FOREIGN KEY REFERENCES Employees(EmployeeID),
CustomerID int NOT NULL
CONSTRAINT FK_LoanReceiver
FOREIGN KEY REFERENCES Customers(CustomerID),
AccountNumber char(10),
LoanTypeID int NOT NULL
CONSTRAINT FK_LoanTypes
FOREIGN KEY REFERENCES LoanTypes(LoanTypeID),
LoanAmount money NOT NULL,
InterestRate decimal(6,2) NOT NULL,
Periods decimal(6,2) NOT NULL,
InterestAmount AS ((LoanAmount*(InterestRate/(100)))*(Periods/(12))),
FutureValue AS (LoanAmount+(LoanAmount*(InterestRate/(100)))*(Periods/(12))),
MonthlyPayment AS ((LoanAmount+(LoanAmount*(InterestRate/(100)))*(Periods/(12)))/Periods),
Notes Text,
CONSTRAINT PK_LoanAllocations PRIMARY KEY(LoanAllocationID)
)
GO
INSERT INTO LoanAllocations(DatePrepared, EmployeeID,
CustomerID, AccountNumber, LoanTypeID, LoanAmount,
InterestRate, Periods, Notes)
VALUES('2/26/2004', 2, 1, '9171394', 4, 6500.00, 12.65, 36,
'The loan will be delivered by our furniture business partner Helios Furnian');
GO
INSERT INTO LoanAllocations(DatePrepared, EmployeeID,
CustomerID, AccountNumber, LoanTypeID, LoanAmount,
InterestRate, Periods, Notes)
VALUES('06/22/2007', 2, 2, '8628064', 2, 16500.00, 10.20, 60,
'For this car loan, our partner Arlington Honda will process and deliver the car.');
GO
INSERT INTO LoanAllocations(DatePrepared, EmployeeID,
CustomerID, AccountNumber, LoanTypeID, LoanAmount,
InterestRate, Periods, Notes)
VALUES('12/3/2006', 1, 3, '8468364', 3, 500.00, 18.65, 48,
'This is a regular credit card.');
GO
INSERT INTO LoanAllocations(DatePrepared, EmployeeID,
CustomerID, AccountNumber, LoanTypeID, LoanAmount,
InterestRate, Periods, Notes)
VALUES('08/02/2006', 3, 4, '2483047', 1, 3500.00, 12.74, 36,
'This is personal/cash loan allocated to a customer who walked in the store and requested it.');
GO
INSERT INTO LoanAllocations(DatePrepared, EmployeeID,
CustomerID, AccountNumber, LoanTypeID, LoanAmount,
InterestRate, Periods, Notes)
VALUES('10/08/2006', 2, 5, '1311804', 4, 22748.36, 12.28, 60,
'This is a regular car financing loan');
GO
-- =========================================
-- Table: Payments
-- =========================================
USE WattsALoan
GO
IF OBJECT_ID('dbo.Payments', 'U') IS NOT NULL
DROP TABLE dbo.Payments
GO
CREATE TABLE dbo.Payments
(
PaymentID int identity(1, 1) NOT NULL,
PaymentDate datetime NOT NULL,
EmployeeID int NULL
CONSTRAINT FK_Employees
FOREIGN KEY REFERENCES Employees(EmployeeID),
LoanAllocationID int NOT NULL
CONSTRAINT FK_LoanAllocations
FOREIGN KEY REFERENCES LoanAllocations(LoanAllocationID),
PaymentAmount money NOT NULL,
Balance money,
Notes Text,
CONSTRAINT PK_Payments PRIMARY KEY(PaymentID)
)
GO
|
相关推荐
Part I: Stored Programming Fundamentals Chapter 1. Introduction to MySQL Stored Programs Section 1.1. What Is a Stored Program? Section 1.2. A Quick Tour Section 1.3. Resources for Developers...
Understand the fundamentals of relational databases, relational algebra, and data modeling Install a PostgreSQL cluster, create a database, and implement your data model Create tables and views, ...
How to write stored procedures in T–SQL and call them from C# programs How to use XML in database applications How to use LINQ to simplify C# database programming How to install SQL Server 2005 ...
The book concludes with a comprehensive set of reference appendixes for command syntax, system stored procedures, information schema views, file system commands, and system management commands. ...
4. **数据库对象**:了解并创建各种数据库对象,如表(Table)、视图(View)、索引(Index)、存储过程(Stored Procedures)和函数(Functions)。 5. **用户管理和权限**:学习如何创建和管理用户,理解角色...
##### 4.3 存储过程(Stored Procedures) - **存储过程**:预先编写的SQL代码块,可以在数据库中存储并重复调用。它们可以提高应用程序的性能和安全性。 #### 五、实践案例与练习 为了帮助考生更好地理解并掌握上述...
721 <br>Appendix D Complete List of Data Mining Stored <br>Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723 <br>Index . . . . . . . . . . . . . . . . . . . . . . . . ...