You are on page 1of 7

Final Project ITSC 2409

Signature Assignment

For each statement describe in detail the output. Use correct terminology; table, field,
column, record, row, data type, constraint, etc.
Underneath each code write your answer.

1. CREATE TSCSTUDENTS
(ID INT (5).
LNAME VARCHAR(30),
GPA DECIMAL(3,2),
DOB DATE);

This statement creates a table called “TSCSTUDENTS” in a database. The table has 4
columns, each with a specific data type and size. ID: is an integer data type column with
a size of 5, it will store the studentid which is unique identifier for each student in the
table. LNAME: this is a string data type column with a maximum size of 30 characters. It
will store the last name of the student. GPA: this is decimal data type column with a 3
and a scale of 2. It will store the grade point average of the student which can range from
0.00 to 4.00. DOB: this is a data type column that will store the date of birth of the
students.

2. UPDATE Criminals
SET mail_flag = 'X'
WHERE street IS NULL;

This statement updates a table called "Criminals". Specifically, it sets the value of the
column "mail_flag" to 'X' for all rows in the table where the column "street" is NULL.
The "UPDATE" statement is used to modify data in an existing table. In this case, the
"Criminals" table is being updated. The "SET" clause is used to specify which columns
will be updated and to what value. In this case, the "mail_flag" column will be updated
with the value 'X'. The "WHERE" clause is used to specify which rows will be updated.
In this case, only the rows where the "street" column is NULL will be updated. This
means that the update will only affect rows where there is no value in the "street" column.

3. UPDATE Criminals
SET phone = '7225659032'
WHERE criminal_id = 1016;

The statement will update the table called "Criminals". It sets the value of the column
"phone" to '7225659032' for the row where the column "criminal_id" is equal to 1016.
The "UPDATE" statement is used to modify data in an existing table. In this case, the
"Criminals" table is being updated.The "SET" clause is used to specify which column(s)
will be updated and to what value. In this case, the "phone" column will be updated with
the value '7225659032'.The "WHERE" clause is used to specify which rows will be
updated. In this case, only the row where the "criminal_id" column is equal to 1016 will
be updated. This means that the update will only affect one row in the table. When this
code is executed, the row in the "Criminals" table where the "criminal_id" column is
equal to 1016 will have its "phone" column set to '7225659032'. The output will not be
displayed as this is a data manipulation language statement and it will simply update the
specified row without returning any result.

4. INSERT INTO Orders (order#, customer#, orderdate, shipdate)


VALUES (1021, 1009, '20-JUL-09', '20-JUL-09');

This code inserts a new row into a table called "Orders". It inserts a new row with values
for the columns "order#", "customer#", "orderdate", and "shipdate". The "INSERT
INTO" statement is used to add new rows to an existing table. In this case, the "Orders"
table is being modified. The table columns that will be populated are specified within the
parenthesis after the table name, with the order they appear on the table. The values to be
inserted for each column are specified within the "VALUES" keyword and separated by
commas, in the order of the columns specified earlier. The values being inserted are 1021
for the "order#" column, 1009 for the "customer#" column, '20-JUL-09' for the
"orderdate" column, and '20-JUL-09' for the "shipdate" column. After executing the code
above, a new row will be added to the "Orders" table with the specified values for each
column. The output will not be displayed as this is a data manipulation language
statement and it will simply add the new row without returning any result.

5. DELETE FROM Criminals


WHERE criminal_id != 1017;

This code is a DELETE statement that deletes records from the "Criminals" table based
on a specific condition. The condition being checked is that the value of the "criminal_id"
column is not equal to 1017. This means that all records in the "Criminals" table whose
"criminal_id" is not 1017 will be deleted. In this case, the table name is "Criminals" and
the condition is "criminal_id != 1017". After this code is executed, all records in the
"Criminals" table whose "criminal_id" is not 1017 will be permanently removed from the
table.

6. UPDATE books
SET catcode = 'COM'
WHERE category = 'COMPUTER';
This code is an UPDATE statement that modifies the "catcode" column of the "books"
table based on a specific condition. The condition being checked is that the value of the
"category" column is equal to 'COMPUTER'. This means that all records in the "books" table
whose "category" is 'COMPUTER' will have their "catcode" column updated to 'COM'. In this
case, the table name is "books", the column name is "catcode", the new value is 'COM', and the
condition is "category = 'COMPUTER'". When this code is executed, all records in the "books"
table whose "category" is 'COMPUTER' will have their "catcode" column updated to 'COM'.
This change will be permanent and will affect the data in the "books" table.

7. DELETE FROM orders


WHERE order# = 1005;

This code is a DELETE statement that deletes records from the "orders" table based on a specific
condition. The condition being checked is that the value of the "order#" column is equal to 1005.
This means that the record in the "orders" table with "order#" equal to 1005 will be deleted.
In this case, the table name is "orders" and the condition is "order# = 1005". When this code is
executed, the record in the "orders" table with "order#" equal to 1005 will be permanently
removed from the table.

8. ALTER TABLE book_stores


MODIFY rep_id NUMBER(5);

The ALTER TABLE statement is used to modify the structure of an existing table in the
database. In this case, the MODIFY keyword is used to change the data type of the "rep_id"
column in the "book_stores" table to "NUMBER(5)". When this code is executed, the data type
of the "rep_id" column in the "book_stores" table will be changed to "NUMBER(5)". This
change will be permanent and will affect the structure of the "book_stores" table. The output of
this code will not be anything that is visible to the user as the result is the successful modification
of the table structure. However the user can verify the modification by running a SELECT
statement to view the structure of the "book_stores" table and confirm that the data type of the
"rep_id" column has been changed to "NUMBER(5)".

9. CREATE TABLE project


(proj# NUMBER(4),
p_name VARCHAR2(20) NOT NULL,
p_desc VARCHAR 2(25),
p_budget VARCHAR 2(15),
PRIMARY KEY (proj#);

This code is a CREATE TABLE statement that creates a new table called "project" with
several columns and a primary key constraint. The CREATE TABLE statement is used to
create a new table in the database. In this case, the "project" table has four columns:
"proj#", "p_name", "p_desc", and "p_budget". The data types of these columns are
"NUMBER(4)", "VARCHAR2(20)", "VARCHAR2(25)", and "VARCHAR2(15)". The
"NOT NULL" constraint is applied to the "p_name" column, which means that this
column must have a value for each record. The other columns do not have this constraint,
so they can have NULL values. The "PRIMARY KEY" constraint is applied to the
"proj#" column, which means that this column is a unique identifier for each record in the
"project" table. This constraint ensures that each record in the table has a unique "proj#"
value. When executing this code, a new table called "project" will be created in the
database with the specified columns and constraints.

10. DROP TABLE crime_officers;


This SQL code is a command that drops or deletes a table called "crime_officers". When you
execute this statement, the system will search for the "crime_officers" table in the database and
delete it permanently from the database schema. All the data that was stored in the table will also
be deleted.

Code the following SQL statements. Use the tables in the JustLee database.
11. Display all the fields from the Books table.

SELECT * FROM Books;

12. Display title and calculate the profit from the Books table.

SELECT title, (price - cost) AS profit


FROM Books;

13. Display lastname, firstname, address and city from the Customers table

SELECT lastname, firstname, address, city


FROM Customers;

14. Display all fields from the Orders table for those orders that have a ShipCost over $5.00.

SELECT *
FROM Orders
WHERE ShipCost > 5.00;

15. Which customers live in New Jersey? List each customer’s last name, first name, and
state.

SELECT LastName, FirstName, State


FROM Customers
WHERE State = 'NJ';

16. Which orders shipped after April 1, 2009? List each order number and the date it shipped.

SELECT OrderNumber, ShippedDate


FROM Orders
WHERE ShippedDate > '2009-04-01'

17. Which books aren’t in the Fitness category? List each book title and category.

SELECT Title, CategoryName


FROM Books
JOIN Categories ON Books.CategoryID = Categories.CategoryID
WHERE Categories.CategoryName != 'Fitness';

18. Display the book title and category for all books in the Children and Cooking categories.

SELECT Title, Category


FROM Books
WHERE Category IN ('Children', 'Cooking');
19. Use a search pattern to find any book title with “A” for the second letter and “N” for the
fourth letter. List each book’s ISBN and title.

SELECT ISBN, Title


FROM Books
WHERE Title LIKE '_A%N%';

20. List the title and publish date of any computer book published in 2005

SELECT Title, PublishDate


FROM Books
WHERE Category = 'Computer' AND YEAR(PublishDate) = 2005;

21. Using the Books table display the books titles without repeating the names.

SELECT DISTINCT Title FROM Books;

22. Update the Books table by changing all catcode from Art to Design.

UPDATE Books
SET catcode = 'Design'
WHERE catcode = 'Art';

23. Update the Books table by changing books table by changing the catcode BUSINESS to
BUS.

UPDATE Books
SET catcode = 'BUS'
WHERE catcode = 'BUSINESS';

24. Update the Books table by adding a new field Special_code with 2 characters.

ALTER TABLE Books


ADD Special_code CHAR(2);

25. Update the Orders table by changing the ShipCost to 50 cents for those that have Null in
the ShipCost.

UPDATE Orders
SET ShipCost = 0.50
WHERE ShipCost IS NULL;

26. Create a table named SpecialProjects with the following specifications:


projNo 4 digits Primary key
pName Up to 20 characters
pDescription Up to 25 characters Not null
pBudget 10 digits with 2 decimal Cannot be less than 0
positions

CREATE TABLE SpecialProjects (


projNo CHAR(4) PRIMARY KEY,
pName VARCHAR(20),
pDescription VARCHAR(25) NOT NULL,
pBudget DECIMAL(10,2) CHECK (pBudget >= 0)
);

27. Insert two rows with data for Special Projects table.

INSERT INTO SpecialProjects (projNo, pName, pDescription, pBudget)


VALUES
('1001', 'Project A', 'protruck', 50000.00),
('1002', 'Project B', 'autodetail', 75000.00);

28. List all rows in Special Projects with a budget between $1,500,000.00 and 10,500,000.00.

SELECT *
FROM SpecialProjects
WHERE pBudget BETWEEN 1500000.00 AND 10500000.00;

29. Add a constraint called pNameCheck to the SpecialProjects table to ensure pName is
unique.

ALTER TABLE SpecialProjects


ADD CONSTRAINT pNameCheck UNIQUE (pName);

30. Delete the table SpecialProjects with all its data.

DROP TABLE SpecialProjects;

You might also like