Creation of Database Using Derby DB. Our Derby Bookstore Database Contains Tables: Authors (Authorid, Firstname, Lastname, EMAIL) 4 Attributes
Creation of Database Using Derby DB. Our Derby Bookstore Database Contains Tables: Authors (Authorid, Firstname, Lastname, EMAIL) 4 Attributes
----**Bookshop_Lab1**----
1. Creation of database using derby DB.
Our derby bookstore database contains tables:
AUTHORS (AUTHORID, FIRSTNAME, LASTNAME,
EMAIL) 4 attributes
AUTHORID: Author’s ID number in the database.
In the bookstore database, this integer column is defined as auto-
incremented, that is for each row inserted in this table the AUTHORID
value is increased by 1 automatically to ensure that each row has a unique
AUTHORID.
This column represents the table’s primary key.
[Note: The author’s NIC could also have been used as the primary key]
Auto-incremented columns are so-called identity columns.
Our SQL script for this database uses the SQL IDENTITY keyword to
mark the AUTHORID column as an identity column.
FIRSTNAME: first name of the author, a string value
LASTNAME: last name of the author, a string value
EMAIL: email of the author, a string value
1
TITLE: Name of the book, a string value.
EDITIONNUMBER: Edition number of the book, one integer value.
COPYRIGHT: Year book was published, of type DATE.
QUANTITY: Number available in stock, type integer.
PRICE: Cost of one copy of the book, type double.
BOOKAUTHOR ( , )2
attributes
The BOOKAUTHOR table consists of two columns that maintain ISBNs
for each book and their corresponding authors’ ID numbers.
This table associates authors with their books.
The AUTHORID column is a foreign key—a column in this table that
matches the primary-key column in another table (that is, AUTHORID in
the AUTHOR table).
The BOOKISBN column is also a foreign key—it matches the primary
key column (that is, BOOKISBN) in the BOOKS table.
A database might consist of many tables.
Always remember that your goal when designing a database is to minimize
the amount of duplicated data among the database’s tables.
Foreign keys, which are specified when a database table is created in the
database, link the data to multiple tables.
Together the AUTHORID and BOOKISBN columns in this table form a
composite primary key.
Every row in this table uniquely matches one author to one book ISBN.
2
DOCUMENTS (DOCUMENTID, COMMENTS,
PATH) 2 attributes
ORDERS (ORDERID, , ,
DATECREATED, PAYMENTAMOUNT,
QUANTITYPURCHASED) 6 attributes
SUPPLIERS ( , FIRSTNAME,
LASTNAME, STREETADDRESS, PHONE, EMAIL,
CITY, POSTALCODE, COMPANYNAME) 9
attributes
BOOKSUPPLIER ( , )2
attributes
SUPPLIERORDERS (ORDERID, ,
DATECREATED, QUANTITYORDERED,
TOTALAMOUNT) 5 attributes
3
EMPLOYEE (EMPNIC, EMPFIRSTNAME,
EMPLASTNAME, STREETADDRESS, CITY,
POSTALCODE, PHONE, EMAIL, DATEOFBIRTH,
PROFILEIMAGE, USERNAME, PASSWORD,
USERLEVEL) 13 attributes
For example, our Bookstore DBMS ensures that the AUTHORID value
for a particular row of the AUTHORISBN table is valid by checking that
there is a row in the AUTHORS table with that AUTHORID as the
primary key.
Foreign keys also allow related data in multiple tables to be selected from
those tables, this is known as joining the data.
This means that a foreign key can appear many times in its own table but
only once (as the primary key) in another table.
4
Every row must have a primary-key value, and that value must be
unique in the table.
Again, for the AUTHORISBN table, the primary key is the combination
of both columns, this is known as a composite primary key.
5
CREATE TABLE "AUTHORS" (
"AUTHORID" INT NOT NULL GENERATED
ALWAYS AS IDENTITY,
"FIRSTNAME" varchar (20) NOT NULL,
"LASTNAME" varchar (30) NOT NULL,
"EMAIL" varchar (50) NOT NULL,
PRIMARY KEY ("AUTHORID")
);
6
CREATE TABLE "BOOKAUTHOR" (
"AUTHORID" INT NOT NULL,
"BOOKISBN" varchar (20) NOT NULL,
FOREIGN KEY ("AUTHORID") REFERENCES
"AUTHORS" ("AUTHORID"),
FOREIGN KEY ("BOOKISBN") REFERENCES
"BOOKS" ("BOOKISBN")
);
7
INSERT INTO "BOOKS"
("BOOKISBN","TITLE","EDITIONNUMBER","COPY
RIGHT", “QUANTITY”,”PRICE”)
VALUES
('0131869000','Visual Basic 2005 How to
Program', 3, '2006-03-12', 2, 1250.5),
('0131525239','Visual C# 2005 How to
Program', 2,'2006-08-21',3,1500.0),
('0132222205','Java How to Program',7,'2007-
11-10',5,1800),
('0131857576','C++ How to Program',5,'2005-
01-30',3,1005.25),
('0132404168','C How to Program',5, '2007-02-
28',8,850.25),
('0131450913','Internet & World Wide Web
How to Program',3,'2004-12-12',7,1505.5),
('0131452715','Epidemiology',1,'2020-01-
20',20,450.55),
('0131828274','Operating Systems',3,'2004-05-
18',5,1985.25);
8
INSERT INTO "BOOKAUTHOR"
("AUTHORID","BOOKISBN") VALUES
(1,'0131869000'),
(2,'0131869000'),
(1,'0131525239'),
(2,'0131525239'),
(1,'0132222205'),
(2,'0132222205'),
(1,'0131857576'),
(2,'0131857576'),
(1,'0132404168'),
(2,'0132404168'),
(1,'0131450913'),
(2,'0131450913'),
(3,'0131450913'),
(1,'0131828274'),
(2,'0131828274'),(4,'0131828274');
9
CREATE TABLE "EMPLOYEE" (
"EMPNIC" varchar (14) NOT NULL,
"EMPFIRSTNAME" varchar (40) NOT NULL,
"EMPLASTNAME" varchar (40) NOT NULL,
"STREETADDRESS" varchar (50) NOT NULL,
"CITY" varchar (30) NOT NULL,
"POSTALCODE" INT NOT NULL,
"PHONE" INT NOT NULL,
"EMAIL" varchar (50) NOT NULL,
"DATEOFBIRTH" DATE NOT NULL,
"PROFILEIMAGE" BLOB NOT NULL,
"USERNAME" varchar (30) NOT NULL,
"PASSWORD" varchar (30) NOT NULL,
"USERLEVEL" INT NOT NULL,
PRIMARY KEY ("EMPNIC")
);
10
2. Creation of Bookshop GUI
The following installations are required:
1. Adding jCalendar and jDateChooser to
Netbeans palette window
2. Adding derby driver to package ‘Libraries’
3. Adding package rs2xml.jar to ‘Libraries’
12
Successful registration of a staff:
13
Staff Login GUI:
14
Successful Staff Login:
15
Admin Dashboard GUI:
16