MS SQL Server Database: Watts' A Loan
MS SQL Server Database: Watts' A Loan
Introduction
A database is one or a series of lists. A list holds some values that are added and managed as necessary. Microsoft SQL Server provides a convenient way to create a database. This is a simple relational database (Watts' A Loan) created with SQL. The script contains code to create tables and their relationshipts, including primary and foreign keys.
Practical Learning: Introducing the Application
USE master; GO IF DB_ID (N'WattsALoan1') IS NOT NULL DROP DATABASE WattsALoan1; GO CREATE DATABASE WattsALoan1; GO USE WattsALoan1; GO CREATE TABLE LoansTypes ( LoanTypeId INT IDENTITY(1, 1), LoanType NVARCHAR(40), [Description] NVARCHAR(250), CONSTRAINT PK_LoansTypes PRIMARY KEY(LoanTypeId) ); GO CREATE TABLE Employees ( EmployeeId INT IDENTITY(1, 1), EmployeeNumber NVARCHAR(10), FirstName NVARCHAR(20), LastName NVARCHAR(20), Title NVARCHAR(150), CONSTRAINT PK_Employees PRIMARY KEY(EmployeeId) ); GO CREATE TABLE LoansContracts ( LoanContractId INT IDENTITY(1, 1), LoanNumber INT, DateAllocated DATE, EmployeeId INT, FirstName NVARCHAR(20), LastName NVARCHAR(20), LoanTypeId INT, LoanAmount DECIMAL(8, 2), InterestRate DECIMAL(6, 2), [Periods] INT, InterestAmount DECIMAL(10, 2), FutureValue DECIMAL(10, 2), MonthlyPayment DECIMAL(6, 2), PaymentStartDate DATE, CONSTRAINT FK_ContractsProcessors FOREIGN KEY(EmployeeId) REFERENCES Employees(EmployeeId), CONSTRAINT FK_LoansTypes FOREIGN KEY(LoanTypeId) REFERENCES LoansTypes(LoanTypeId), CONSTRAINT PK_LoansContracts PRIMARY KEY(LoanContractId) ); GO CREATE TABLE Payments ( PaymentId INT IDENTITY(1, 1), ReceiptNumber INT, LoanContractId INT, PaymentDate DATE, PaymentAmount DECIMAL(6, 2), Balance DECIMAL(10, 2), PaymentFor NVARCHAR(150), CONSTRAINT FK_LoansContracts FOREIGN KEY(LoanContractId) REFERENCES LoansContracts(LoanContractId), CONSTRAINT PK_Payments PRIMARY KEY(PaymentId) ); GO ------------------------------------------------------------------------------------------------------- CREATE PROCEDURE GetStaffMember @emplNbr NVARCHAR(10) AS BEGIN SET NOCOUNT ON; SELECT FirstName, LastName, EmployeeTitle FROM Employees WHERE EmployeeNumber = @emplNbr; END GO -- ======================================================================================================================== INSERT INTO LoansTypes(LoanType, [Description]) VALUES(N'Personal Loan', N'This is loan given as a cashier check to a customer who wants a cash loan.'), (N'Car Financing', N'This loan will be processed by our partners as car dealers.'); GO INSERT INTO LoansTypes(LoanType) VALUES(N'Boat Financing'), (N'Furniture Purchase'); GO INSERT INTO LoansTypes(LoanType, [Description]) VALUES(N'Musical Instrument', N'We have some partnerships in musical instruments stores. This is the type of loan we will make available to the customers they find for us.'); GO ----------------------------------------------------------------- INSERT INTO Employees(EmployeeNumber, FirstName, LastName, Title) VALUES(N'293-747', N'Catherine', N'Watts', N'Owner - General Manager'), (N'836-486', N'Thomas', N'Felton', N'Accounts Representative'), (N'492-947', N'Caroline', N'Werwick', N'Assistant Manager'), (N'240-750', N'Catherine', N'Donato', N'Accounts Representative'), (N'804-685', N'Melissa', N'Browns', N'Customer Accounts Representative'), (N'429-374', N'Denise', N'Leighton', N'Accounts Manager'); GO INSERT INTO LoansContracts(LoanNumber, DateAllocated, EmployeeId, FirstName, LastName, LoanTypeId, LoanAmount, InterestRate, [Periods], InterestAmount, FutureValue, MonthlyPayment, PaymentStartDate) VALUES(100001, N'06/18/2018', 6, N'Joanne', N'Kennan', 1, 2500.00, 15.63, 36, 1171.88, 3671.85, 101.95, N'08/01/2018'), (100002, N'06/22/2018', 3, N'Stephanie', N'Haller', 3, 46500.00, 4.95, 72, 13810.50, 60310.50, 837.65, N'08/01/2018'), (100003, N'08/12/2018', 6, N'Annette', N'Vargas', 4, 2258.75, 17.35, 36, 1175.70, 3434.43, 71.55, N'10/01/2018'), (100004, N'01/12/2019', 2, N'Gérard', N'Maloney', 2, 22748.00, 10.25, 60, 11658.40, 34406.40, 573.44, N'03/01/2020'); GO INSERT INTO Payments(ReceiptNumber, LoanContractId, PaymentDate, PaymentAmount, Balance, PaymentFor) VALUES(928375, 2, N'08/30/2018', 837.65, 59472.85, N'Aug-2018'), (752420, 1, N'08/31/2018', 101.95, 3569.93, N'Aug-2018'), (886069, 1, N'09/21/2018', 101.95, 3467.98, N'Sep-2018'), (868686, 2, N'09/30/2018', 837.65, 58635.20, N'Sep-2018'), (814269, 3, N'10/28/2018', 71.55, 3362.88, N'Oct-2018'), (649392, 1, N'10/30/2018', 101.95, 3366.03, N'Oct-2018'), (144074, 2, N'10/30/2018', 837.65, 57797.55, N'Oct-2018'), (313995, 2, N'11/04/2018', 837.65, 56959.90, N'Oct-2018'), (208858, 1, N'11/25/2018', 101.95, 3264.08, N'Oct-2018'), (463146, 3, N'11/30/2018', 71.55, 3291.33, N'Oct-2018'), (138417, 1, N'12/28/2018', 101.95, 3162.13, N'Dec-2018'), (481363, 2, N'01/01/2019', 837.65, 56122.25, N'Dec-2019'), (386294, 3, N'01/01/2019', 71.55, 3219.78, N'Dec-2019'), (296262, 1, N'01/31/2019', 101.95, 3060.18, N'Jan-2019'), (559605, 2, N'02/03/2019', 837.65, 55284.60, N'Jan-2019'), (157531, 3, N'02/05/2019', 71.55, 3148.23, N'Jan-2019'), (973377, 1, N'02/21/2019', 101.95, 2958.23, N'Feb-2019'), (807055, 3, N'03/01/2019', 71.55, 3076.68, N'Feb-2019'), (727153, 2, N'03/05/2019', 837.65, 54446.95, N'Feb-2019'), (949816, 1, N'03/30/2019', 101.95, 2856.28, N'Mar-2019'), (930858, 2, N'04/02/2019', 837.65, 53609.30, N'Mar-2019'), (614914, 3, N'04/02/2019', 71.55, 3005.13, N'Mar-2019'), (699942, 1, N'04/29/2019', 101.95, 2754.33, N'Apr-2019'), (773882, 2, N'05/04/2019', 837.65, 52771.65, N'Apr-2019'), (663802, 1, N'05/14/2019', 101.95, 2652.38, N'May-2019'), (683859, 3, N'05/30/2019', 143.10, 2862.03, N'Apr-May, 2019'), (773975, 2, N'06/03/2019', 837.65, 51934.00, N'May-2019'), (496937, 3, N'06/25/2019', 71.55, 2790.48, N'Jun-2019'), (827160, 1, N'06/26/2019', 102.25, 2550.13, N'Jun-2019'), (950406, 2, N'06/30/2019', 837.65, 51096.35, N'Jun-2019'), (392860, 2, N'07/20/2019', 837.65, 50258.70, N'Jul-2019'), (464820, 1, N'07/24/2019', 101.95, 2448.18, N'Jul-2019'), (300533, 3, N'08/10/2019', 143.10, 2647.38, N'Jul-Aug, 2019'), (924227, 1, N'08/26/2019', 101.95, 2346.23, N'Aug-2019'), (351516, 2, N'08/31/2019', 837.65, 49421.05, N'Aug-2019'), (770418, 2, N'09/26/2019', 837.65, 48583.40, N'Sep-2019'), (448440, 3, N'09/27/2019', 71.55, 2575.83, N'Sep-2019'), (820869, 1, N'09/30/2019', 101.95, 2244.28, N'Sep-2019'), (748694, 1, N'10/22/2019', 101.95, 2142.33, N'Oct-2019'), (527716, 3, N'10/24/2019', 71.55, 2504.28, N'Oct-2019'), (750633, 2, N'11/05/2019', 837.65, 47745.75, N'Oct-2019'), (317071, 1, N'11/30/2019', 101.95, 2040.38, N'Oct-2019'), (800864, 2, N'12/03/2019', 837.65, 46908.10, N'Oct-2019'), (492814, 1, N'12/22/2019', 102.25, 1938.13, N'Dec-2019'), (750422, 2, N'01/04/2020', 837.65, 46070.45, N'Dec-2020'), (922726, 3, N'01/05/2020', 71.55, 2361.18, N'Dec-2020'), (420802, 1, N'01/31/2020', 101.95, 1836.18, N'Jan-2020'), (461669, 3, N'02/01/2020', 71.55, 2289.63, N'Jan-2020'), (699686, 2, N'02/02/2020', 837.65, 45232.80, N'Jan-2020'), (537297, 1, N'02/21/2020', 101.95, 1734.23, N'Feb-2020'), (975548, 2, N'03/03/2020', 837.65, 44395.15, N'Feb-2020'), (585773, 1, N'03/20/2020', 101.95, 1632.28, N'Mar-2020'), (159339, 4, N'03/22/2020', 573.44, 33832.96, N'Mar-2020'), (507055, 3, N'03/31/2020', 143.10, 2146.53, N'Fev-Mar, 2020'), (227061, 2, N'04/05/2020', 837.65, 43557.50, N'Mar-2022'), (797586, 1, N'04/30/2020', 101.95, 1530.33, N'Apr-2022'), (209707, 4, N'04/30/2020', 573.44, 33259.52, N'Apr-2022'), (137244, 2, N'05/01/2020', 837.65, 42719.85, N'Apr-2022'), (588318, 3, N'05/05/2020', 71.55, 2074.98, N'Apr-2022'), (181822, 1, N'05/27/2020', 101.95, 1428.38, N'May-2022'), (622640, 4, N'05/28/2020', 573.44, 32686.08, N'May-2022'), (277229, 2, N'05/30/2020', 837.65, 41882.20, N'May-2022'), (507940, 3, N'06/02/2020', 71.55, 2003.43, N'May-2022'), (775160, 2, N'06/20/2020', 837.65, 41044.55, N'Jun-2022'), (714402, 1, N'06/21/2020', 101.95, 1326.43, N'Jun-2022'), (147517, 4, N'06/25/2020', 573.44, 32112.64, N'20-Jun'), (600796, 3, N'07/02/2020', 71.55, 1931.88, N'Jun-2022'), (114964, 2, N'07/24/2020', 837.65, 40206.90, N'Jul-2022'), (335363, 1, N'07/29/2020', 102.25, 1224.18, N'Jul-2022'), (836406, 4, N'07/30/2020', 573.44, 31539.20, N'Jul-2022'), (882008, 3, N'08/05/2020', 71.55, 1860.33, N'Jul-2022'), (837159, 4, N'08/26/2020', 573.44, 30965.76, N'Aug-2022'), (771379, 1, N'08/27/2020', 101.95, 1122.23, N'Aug-2022'), (449415, 2, N'08/31/2020', 837.65, 39369.25, N'Aug-2022'), (493117, 3, N'08/31/2020', 71.55, 1788.78, N'Aug-2022'), (296182, 1, N'09/10/2020', 101.95, 1020.28, N'Sep-2022'), (972527, 4, N'09/28/2020', 573.44, 30392.32, N'Sep-2022'), (464000, 2, N'09/30/2020', 837.65, 38531.60, N'Sep-2022'), (664295, 4, N'10/23/2020', 573.44, 29818.88, N'Oct-2022'), (779471, 1, N'10/30/2020', 101.95, 918.33, N'Oct-2022'), (858183, 3, N'10/30/2020', 143.10, 1645.68, N'Sep-Oct, 2020'), (938685, 2, N'10/31/2020', 837.65, 37693.95, N'Oct-2022'), (466486, 2, N'11/21/2020', 837.65, 36856.30, N'Oct-2022'), (724084, 1, N'11/22/2020', 101.95, 816.38, N'Oct-2022'), (942681, 4, N'11/29/2020', 573.44, 29245.44, N'Oct-2022'), (286085, 3, N'11/30/2020', 71.55, 1574.13, N'Nov, 2020'), (229350, 3, N'12/01/2020', 71.55, 2432.73, N'Oct-2022'), (226428, 4, N'12/27/2020', 573.44, 28672.00, N'Dec-2022'), (141573, 2, N'01/02/2021', 837.65, 36018.65, N'Dec-2022'), (814939, 3, N'01/04/2021', 71.55, 1502.58, N'Dec-2022'), (203725, 1, N'01/05/2021', 101.95, 714.43, N'Dec-2022'), (685227, 4, N'01/30/2021', 573.44, 28098.56, N'Jan-2022'), (792511, 2, N'01/31/2021', 837.65, 35181.00, N'Jan-2022'), (182449, 3, N'02/02/2021', 71.55, 1431.03, N'21-Jan'), (318247, 2, N'02/25/2021', 837.65, 34343.35, N'Feb-2022'), (853047, 1, N'02/27/2021', 102.25, 612.18, N'Jan-2022'), (852033, 1, N'03/03/2021', 101.95, 510.23, N'Feb-2022'), (862444, 4, N'03/03/2021', 573.44, 27525.12, N'Feb-2022'), (504249, 2, N'03/22/2021', 837.65, 33505.70, N'Mar-2022'), (203727, 3, N'03/30/2021', 143.10, 1287.93, N'Feb-Mar, 2021'), (839313, 1, N'04/04/2021', 101.95, 408.28, N'Mar-2022'), (746935, 4, N'04/04/2021', 573.44, 26951.68, N'Mar-2022'), (750716, 2, N'04/24/2021', 837.65, 32668.05, N'Apr-2022'), (305170, 3, N'04/28/2021', 71.55, 1216.38, N'Apr, 2021'), (606447, 1, N'05/01/2021', 101.95, 306.33, N'Apr-2022'), (593799, 4, N'05/05/2021', 573.44, 26378.24, N'Apr-2022'), (400420, 3, N'05/21/2021', 71.55, 1144.83, N'May-2022'), (641792, 1, N'05/31/2021', 101.95, 204.38, N'May-2022'), (486408, 2, N'05/31/2021', 837.65, 31830.40, N'May-2022'), (600024, 4, N'06/02/2021', 573.44, 25804.80, N'May-2022'), (297307, 1, N'06/25/2021', 101.95, 102.43, N'Jun-2022'), (630470, 2, N'06/29/2021', 837.65, 30992.75, N'Jun-2022'), (517442, 3, N'06/30/2021', 71.55, 1073.28, N'21-Jun'), (955865, 4, N'07/04/2021', 573.44, 25231.36, N'Jun-2022'), (792994, 3, N'07/27/2021', 71.55, 1001.73, N'21-Jul'), (967139, 2, N'07/31/2021', 837.65, 30155.10, N'Jul-2022'), (594240, 4, N'08/01/2021', 573.44, 24657.92, N'Jul-2022'), (631599, 3, N'08/20/2021', 71.55, 930.18, N'Aug-2022'), (272881, 2, N'08/31/2021', 837.65, 29317.45, N'Aug-2022'), (957955, 4, N'08/31/2021', 573.44, 24084.48, N'Aug-2022'), (881696, 4, N'09/20/2021', 573.44, 23511.04, N'Sep-2022'), (352270, 3, N'09/23/2021', 71.55, 858.63, N'Sep-2022'), (537172, 2, N'09/29/2021', 837.65, 28479.80, N'Sep-2022'), (588538, 4, N'10/18/2021', 573.44, 22937.60, N'Oct-2022'), (727184, 2, N'10/27/2021', 837.65, 27642.15, N'Oct-2022'), (499296, 3, N'11/02/2021', 71.55, 787.08, N'Oct-2022'), (135955, 4, N'11/22/2021', 573.44, 22364.16, N'Oct-2022'), (133727, 2, N'11/30/2021', 837.65, 26804.50, N'Oct-2022'), (316612, 3, N'12/27/2021', 143.10, 643.98, N'Oct-Dec, 2022'), (716803, 4, N'01/02/2022', 573.44, 21790.72, N'Dec-2022'), (528127, 2, N'01/03/2022', 837.65, 25966.85, N'Dec-2022'), (114247, 3, N'01/20/2022', 71.55, 572.43, N'Jan-2022'), (596536, 2, N'01/30/2022', 837.65, 25129.20, N'Jan-2022'), (714948, 3, N'02/05/2022', 71.55, 500.88, N'Feb-2022'), (964705, 2, N'02/20/2022', 837.65, 24291.55, N'Feb-2022'), (280170, 4, N'02/26/2022', 573.44, 21217.28, N'Jan-2022'), (559622, 4, N'03/02/2022', 573.44, 20643.84, N'Feb-2022'), (473957, 3, N'03/26/2022', 71.55, 429.33, N'22-Mar'), (220474, 2, N'03/27/2022', 837.65, 23453.90, N'Mar-2022'), (339528, 4, N'03/31/2022', 573.44, 20070.40, N'Mar-2022'), (773693, 2, N'04/29/2022', 837.65, 22616.25, N'Apr-2022'), (868300, 3, N'04/30/2022', 71.55, 357.78, N'Apr-2022'), (859698, 4, N'05/05/2022', 573.44, 19496.96, N'Apr-2022'), (966838, 3, N'05/21/2022', 71.55, 286.23, N'May-2022'), (288355, 2, N'05/26/2022', 837.65, 21778.60, N'May-2022'), (283868, 4, N'06/04/2022', 573.44, 18923.52, N'May-2022'), (208281, 2, N'06/26/2022', 837.65, 20940.95, N'Jun-2022'), (842811, 4, N'07/01/2022', 573.44, 18350.08, N'Jun-2022'), (269569, 3, N'07/31/2022', 143.10, 143.13, N'Jun-Jul, 2022'), (155796, 4, N'07/31/2022', 573.44, 17776.64, N'Jul-2022'), (528306, 2, N'08/02/2022', 837.65, 20103.30, N'Jul-2022'), (958313, 2, N'08/30/2022', 837.65, 19265.65, N'Aug-2022'), (317552, 3, N'08/30/2022', 71.55, 71.58, N'Aug-2022'), (647280, 4, N'08/31/2022', 573.44, 17203.20, N'Aug-2022'), (113060, 4, N'09/29/2022', 573.44, 16629.76, N'Sep-2022'), (279584, 2, N'10/03/2022', 837.65, 18428.00, N'Sep-2022'), (700005, 3, N'10/05/2022', 71.55, 0.03, N'Sep-2022'), (641142, 4, N'10/24/2022', 573.44, 16056.32, N'Oct-2022'), (886969, 2, N'10/31/2022', 837.65, 17590.35, N'Oct-2022'), (618318, 4, N'11/02/2022', 573.44, 15482.88, N'Oct-2022'), (626963, 2, N'11/27/2022', 837.65, 16752.70, N'Oct-2022'), (113974, 4, N'12/03/2022', 573.44, 14909.44, N'Dec-2022'), (288615, 2, N'01/05/2023', 837.65, 15915.05, N'Dec-2022'), (263836, 4, N'02/03/2023', 573.44, 14336.00, N'Jan-2022'), (755772, 2, N'02/04/2023', 837.65, 15077.40, N'Jan-2022'), (186924, 2, N'03/01/2023', 837.65, 14239.75, N'Feb-2022'), (959649, 4, N'03/03/2023', 573.44, 13762.56, N'Feb-2022'), (379596, 4, N'04/01/2023', 573.44, 13189.12, N'Mar-2022'), (735929, 2, N'04/03/2023', 837.65, 13402.10, N'Mar-2022'), (249588, 4, N'05/01/2023', 573.44, 12615.68, N'Apr-2022'), (750462, 2, N'05/02/2023', 837.65, 12564.45, N'Apr-2022'), (377974, 2, N'05/31/2023', 837.65, 11726.80, N'May-2022'), (427205, 4, N'05/31/2023', 573.44, 12042.24, N'May-2022'), (259975, 4, N'06/26/2023', 573.44, 11468.80, N'Jun-2022'), (386420, 2, N'06/27/2023', 837.65, 10889.15, N'Jun-2022'), (751148, 2, N'07/28/2023', 837.65, 10051.50, N'Jul-2022'), (696864, 4, N'07/28/2023', 573.44, 10895.36, N'Jul-2022'), (692937, 4, N'08/25/2023', 573.44, 10321.92, N'Aug-2022'), (293335, 2, N'08/30/2023', 837.65, 9213.85, N'Aug-2022'), (172869, 4, N'09/22/2023', 573.44, 9748.48, N'Sep-2022'), (588383, 2, N'09/26/2023', 837.65, 8376.20, N'Sep-2022'), (473029, 4, N'10/20/2023', 573.44, 9175.04, N'Oct-2022'), (395751, 2, N'10/25/2023', 837.65, 7538.55, N'Oct-2022'), (751386, 2, N'11/29/2023', 837.65, 6700.90, N'Oct-2022'), (380479, 2, N'01/02/2024', 837.65, 5863.25, N'Dec-2022'), (352282, 4, N'01/02/2024', 573.44, 8601.60, N'Oct-2022'), (647740, 4, N'01/27/2024', 573.44, 8028.16, N'Dec-2022'), (642604, 2, N'02/01/2024', 837.65, 5025.60, N'Jan-2022'), (608203, 4, N'02/10/2024', 573.44, 7454.72, N'Jan-2022'), (140851, 2, N'03/01/2024', 837.65, 4187.95, N'Feb-2022'), (669955, 4, N'03/02/2024', 573.44, 6881.28, N'Feb-2022'), (707316, 4, N'03/31/2024', 573.44, 6307.84, N'Mar-2022'), (850379, 2, N'04/04/2024', 837.65, 3350.30, N'Mar-2022'), (558046, 4, N'04/23/2024', 573.44, 5734.40, N'Apr-2022'), (182086, 2, N'05/05/2024', 837.65, 2512.65, N'Apr-2022'), (614847, 4, N'05/27/2024', 573.44, 5160.96, N'May-2022'), (581726, 2, N'05/31/2024', 837.65, 1675.00, N'May-2022'), (464647, 2, N'06/17/2024', 837.65, 837.35, N'Jun-2022'), (530413, 4, N'06/30/2024', 573.44, 4587.52, N'Jun-2022'), (162414, 4, N'08/04/2024', 573.44, 4014.08, N'Jul-2022'), (941596, 4, N'09/05/2024', 573.44, 3440.64, N'Aug-2022'), (708272, 4, N'10/01/2024', 573.44, 2867.20, N'Sep-2022'), (353953, 4, N'11/03/2024', 573.44, 2293.76, N'Oct-2022'), (395315, 4, N'12/05/2024', 573.44, 1720.32, N'Oct-2022'), (641186, 4, N'01/05/2025', 573.44, 1146.88, N'Dec-2022'), (206208, 4, N'01/31/2025', 573.44, 573.44, N'Jan-2022'), (170262, 4, N'02/25/2025', 573.44, 0.00, N'Feb-2022'); GO
|
|||
Home | Copyright © 2007-2022, FunctionX | Monday 23 May 2022 | Home |
|