Sample SQL Database Creation And Population

Creating the PartyKids Database

Task 1  ER DiagramTask 2  Task 2a

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

1

PRINT ‘Creating database.’;

CREATE DATABASE PartyKids;

GO

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

PRINT ‘Creating  table Customer …’;

CREATE TABLE Customer (

  CustomerID INTEGER  NOT NULL   IDENTITY ,

  CustomerName VARCHAR(45)    ,

  CustomerAddress VARCHAR(150)      ,

PRIMARY KEY(CustomerID));

GO

2

PRINT ‘Populating the Customer table’

SET IDENTITY_INSERT [dbo].[Customer] ON

Insert Into Customer(CustomerID,CustomerName, CustomerAddress)

VALUES

(1, ‘Cristiano Ronalado’, ‘123 Porto street’),

(2, ‘Pedro Rodriguez’, ‘benson road’),

(3, ‘John Smith’, ’12/1 Flinders St, Melbourne 3000′),

(4, ‘Adil Rashid’, ‘BJ road’),

(5, ‘Michael owen’, ’32 centre street’),

(6, ‘Robie Fowler’, ’45 benton street’),

(7, ‘Lionel Messi’, ’56 avenue road’);

SET IDENTITY_INSERT [dbo].[Customer] OFF

GO

3

Select * from Customers;Print ‘Updating columns’;

UPDATE dbo.Customer 

    SET CustomerAddress = ‘ 15/1 Flinders Street’ 

    WHERE CustomerName = ‘John P Smith’     

GO

Select CustomerName, CustomerAddress From Customer;Select *

From Customer

Where CustomerName LIKE ‘J%’;6

Select *

From Customer

Where CustomerAddress LIKE ‘%3000%’;7

Delete From Customer

Where CustomerName = ‘John P Smith’;8

PRINT ‘Creating  table Booking …’;

CREATE TABLE Booking (

  BookingID INTEGER  NOT NULL   IDENTITY ,

  CustomerID INTEGER  NOT NULL    ,

  BookingDate DATE    ,

  CustomerFeedback VARCHAR(150)      ,

PRIMARY KEY(BookingID),

  FOREIGN KEY(CustomerID)

    REFERENCES Customer(CustomerID),

);

GO

CREATE INDEX Booking_FKIndex1 ON Booking(CustomerID);

GO

PRINT ‘Populating the Booking table’

SET IDENTITY_INSERT [dbo].[Booking] ON

Insert Into Booking (BookingID, CustomerID, BookingDate, CustomerFeedback)

VALUES

(8, 1, ‘2017-11-09’, ‘Excellent’),

(9, 2, ‘2017-12-24’, ‘It was okay’),

(10, 2, ‘2018-04-30’, ‘Fine’),

(11, 4, ‘2017-09-21’, ‘Excellent’),

(12, 4, ‘2018-03-28’, ‘Fine’),

(13, 4, ‘2017-09-01’, ‘It was okay’);

SET IDENTITY_INSERT [dbo].[Booking] OFF

GO

9

Delete From  Customers

Where CustomerID = 3;10

Select CustomerID, BookingID, BookingDate, CustomerFeedback

From Bookings

Group By CustomerID, BookingID, BookingDate, CustomerFeedback;11

Select Customer.CustomerName, Booking.BookingDate

From Customer inner join Booking on Customer.CustomerID = Booking.CustomerID

Order By Booking.BookingDate DESC;12

Select Customer.CustomerName

From Customer

Where Customer.CustomerID not in

( Select Customer.CustomerID

From Customer inner join Booking on Customer.CustomerID = Booking.CustomerID);Task 2b

13

PRINT ‘Creating  table Customer …’;

CREATE TABLE Customer (

  CustomerID INTEGER  NOT NULL   IDENTITY ,

  CustomerName VARCHAR(45)    ,

  CustomerAddress VARCHAR(150)      ,

PRIMARY KEY(CustomerID));

GO

PRINT ‘Creating table Items …’;

CREATE TABLE Items (

  ItemID INTEGER  NOT NULL   IDENTITY ,

  ItemName VARCHAR(150)    ,

  ItemType VARCHAR(150) ,

  Price FLOAT    ,

PRIMARY KEY(ItemID));

PRINT ‘Creating  table Rents …’;

CREATE TABLE Rents (

  RentID INTEGER  NOT NULL   IDENTITY ,

  ItemID INTEGER  NOT NULL    ,

  CustomerID INTEGER  NOT NULL ,

Populating the Customer Table

  NumberOfDays INTEGER ,

  Price FLOAT      ,

PRIMARY KEY(ItemID),

  FOREIGN KEY(ItemID)

    REFERENCES Items(ItemID),

  FOREIGN KEY(CustomerID)

    REFERENCES Customer(CustomerID)

);

GO

CREATE INDEX Booking_FKIndex2 ON Rents(ItemID);

GO

CREATE INDEX Booking_FKIndex3 ON Rents(CustomerID);

GO

PRINT ‘Creating  table Payments …’;

CREATE TABLE Payments (

  PaymentID INTEGER  NOT NULL   IDENTITY ,

  RentID INTEGER  NOT NULL    ,

  CustomerID INTEGER  NOT NULL ,

  Amount FLOAT     ,

PRIMARY KEY(PaymentID),

  FOREIGN KEY(RentID)

    REFERENCES Rents(RentID),

  FOREIGN KEY(CustomerID)

    REFERENCES Customer(CustomerID)

);

GO

CREATE INDEX Booking_FKIndex2 ON Payments(RentID);

GO

CREATE INDEX Booking_FKIndex3 ON Payments(CustomerID);

GO

14

PRINT ‘Populating the Customers table’

SET IDENTITY_INSERT [dbo].[Customers] ON

Insert Into Customers(CustomerID,CustomerName, CustomerAddress)

VALUES

(1, ‘Cristiano Ronalado’, ‘123 Porto street’),

(2, ‘Pedro Rodriguez’, ‘benson road’),

(3, ‘John Smith’, ’12/1 Flinders St, Melbourne 3000′),

(4, ‘Adil Rashid’, ‘BJ road’),

(5, ‘Michael owen’, ’32 centre street’),

(6, ‘Robie Fowler’, ’45 benton street’),

(7, ‘Lionel Messi’, ’56 avenue road’);

SET IDENTITY_INSERT [dbo].[Customers] OFF

GO 

PRINT ‘Populating the Booking table’

SET IDENTITY_INSERT [dbo].[Bookings] ON

Insert Into Bookings (BookingID, CustomerID, BookingDate, CustomerFeedback)

VALUES

(8, 1, ‘2017-11-09’, ‘Excellent’),

(9, 2, ‘2017-12-24’, ‘It was okay’),

(10, 2, ‘2018-04-30’, ‘Fine’),

(11, 4, ‘2017-09-21’, ‘Excellent’),

(12, 4, ‘2018-03-28’, ‘Fine’),

(13, 4, ‘2017-09-01’, ‘It was okay’);

SET IDENTITY_INSERT [dbo].[Bookings] OFF

GO

PRINT ‘Populating the Items table’

SET IDENTITY_INSERT [dbo].[Items] ON

Insert Into Items (ItemID, ItemName, ItemType, Price)

VALUES

(1, ‘cushion’, ‘inflatable’, 10),

(2, ‘small plastic’, ‘chairs’, 2),

(3, ‘flexible’, ‘others’, 23);

SET IDENTITY_INSERT [dbo].[Items] OFF

GO 

PRINT ‘Populating the Rents table’

SET IDENTITY_INSERT [dbo].[Rents] ON

Insert Into Rents (RentID, ItemID, CustomerID, NumberOfDays, Price)

VALUES

(1, 1, 1, 79, 12),

(2, 1, 2, 87, 11),

(3, 2, 4, 56, 13);

SET IDENTITY_INSERT [dbo].[Rents] OFF

GO

PRINT ‘Populating the Payments table’

SET IDENTITY_INSERT [dbo].[Payment] ON

Insert Into Payment (PaymentID, RentID, CustomerID, Amount)

VALUES

(1, 1, 1, 28),

(2, 2, 2, 34),

(3, 3, 4, 43);

SET IDENTITY_INSERT [dbo].[Payment] OFF

GO

15

Select Customers.CustomerName

From Customers Inner Join Rents on Customers.CustomerID = Rents.CustomerID

Inner Join Items On Items.ItemID = Rents.ItemID

Where Items.ItemType = ‘inflatable’;

16

Select Customers.CustomerName

From Customers Inner Join Rents on Customers.CustomerID = Rents.CustomerID

Inner Join Items On Items.ItemID = Rents.ItemID

Where Items.ItemType = ‘inflatable’ Or Items.ItemType =’Chairs’;Select Customers.CustomerName, COUNT (Bookings.BookingDate)

From Customers Inner Join Bookings on Customers.CustomerID = Bookings.CustomerID

Group by Customers.CustomerName;Select Customers.CustomerName, SUM (Payment.Amount) As TotalAmount

From Customers Inner Join Payment on Customers.CustomerID = Payment.CustomerID

Group by Customers.CustomerName;Task 3

19

            It is very important that the ER diagram is developed before the development of the database. It provides an idea to the developer who is developing the database. In addition to this, the ER diagram also helps in the maintaining the business rules of the organization.

20

            There is various type of legal issues that are to be faced if the records of the card details of the customers are organized in the system. In addition to tis, the storage of the details of the address might not bring about any legal issues, but the details of the card might have some legal issues with it.

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Course Scholars
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Political science
Thank you!
Customer 452701, February 12th, 2023
Business Studies
Great paper thanks!
Customer 452543, January 23rd, 2023
Psychology
Thank you. I will forward critique once I receive it.
Customer 452467, July 25th, 2020
Political science
I like the way it is organized, summarizes the main point, and compare the two articles. Thank you!
Customer 452701, February 12th, 2023
Education
Thank you so much, Reaserch writer. you are so helpfull. I appreciate all the hard works. See you.
Customer 452701, February 12th, 2023
Technology
Thank you for your work
Customer 452551, October 22nd, 2021
Accounting
Thank you for your help. I made a few minor adjustments to the paper but overall it was good.
Customer 452591, November 11th, 2021
Psychology
I requested a revision and it was returned in less than 24 hours. Great job!
Customer 452467, November 15th, 2020
Finance
Thank you very much!! I should definitely pass my class now. I appreciate you!!
Customer 452591, June 18th, 2022
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat

Order your essay today and save 15% with the discount code GINGER