Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 6 . DO the following: Build the Persons 1 6 table with the same data fields and data records where the P _

16. DO the following: Build the Persons16 table with the same data fields and data
records where the "P_Id" column in the "Persons16" table is the PRIMARY KEY in the
"Persons16" table.
The "Persons16" table:
P_Id LastName FirstName Address City
1 Hansen Harry 12 Smith St. Edison
2 Svendson Tammy 34 Apple Way Colonia
3 Pettersen Kimmie 56 Patio Place Iselin
17. To understand SQL FOREIGN KEY Constraint on CREATE TABLE, DO the following
SQL creates a FOREIGN KEY on the "P_Id" column when the "Orders17" table is created:
CREATE TABLE Orders17
(
O_Id int NOT NULL PRIMARY KEY,
OrderNo int NOT NULL,
P_Id int,
FOREIGN KEY (P_Id) REFERENCES Persons16(P_Id)
)
18. To understand how to DROP a PRIMARY KEY constraint, DO the following SQL:
ALTER TABLE Persons16
DROP CONSTRAINT pk_PersonID
19. To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY
constraint on multiple columns, DO the following SQL syntax:
CREATE TABLE Orders19
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
PRIMARY KEY (O_Id),
CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id)
REFERENCES Persons16(P_Id)
)
20. To understand how to DROP a FOREIGN KEY constraint, DO the following SQL:
ALTER TABLE Orders19
DROP CONSTRAINT fk_PerOrders
21. DO the following SQL to create a CHECK constraint on the "P_Id" column when the
"Persons" table is created. The CHECK constraint specifies that the column "P_Id" must
only include integers greater than 0.
CREATE TABLE Persons21
(
P_Id int NOT NULL CHECK (P_Id>0),
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
22. DO the following to allow naming of a CHECK constraint, and for defining a CHECK
constraint on multiple columns, use the following SQL syntax:
CREATE TABLE Persons22
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT chk_Person CHECK (P_Id>0 AND City='Sandnes')
)
23. To understand the SQL CHECK Constraint on ALTER TABLE, DO the following
to create a CHECK constraint on the "P_Id" column when the table is already created,
use the following SQL:
ALTER TABLE Persons22
ADD CHECK (P_Id>0)
24. To understand how to DROP a CHECK constraint, DO the following SQL:
ALTER TABLE Persons22
DROP CONSTRAINT chk_Person
25. To use the SQL DEFAULT Constraint on CREATE TABLE, DO the following SQL
creates a DEFAULT constraint on the "City" column when the "Persons" table is created:
CREATE TABLE Persons25
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT 'Sandnes'
)
26. To understand how to use the DEFAULT constraint can also be used to insert system
values, by using functions like SYSDATE, DO the following:
CREATE TABLE Orders26
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
OrderDate date DEFAULT SYSDATE
)
27. To understand how to use the SQL DEFAULT constraint on ALTER TABLE, DO the following to create a DEFAULT constraint on the "City" column when the table is already created, use the following SQL:
ALTER TABLE Persons25
MODIFY City DEFAULT 'SANDNES'
28. To demonstrate the SQL ALTER TABLE, DO the following:
Build a "Persons28" table with the following columns and insert the data into the table:
P_Id LastName FirstName Address City
1 Hansen Harry 12 Smith St. Edison
2 Svendson Tammy 34 Apple Way Colonia
3 Pettersen Kimmie 56 Patio Place Iselin
28. DO: Now add a column named "DateOfBirth" in the "Persons28" table by doing the following SQL statement:
ALTER TABLE Persons28
ADD DateOfBirth date
Notice that the new column, "DateOfBirth", is of type date and is going to hold a date. The data type specifies what type of data the column can hold.
29. DO: Use a Select command to demonstrate that the "Persons28" table will now look like this:
P_Id LastName FirstName Address City DateOfBirth
1 Hansen Harry 12 Smith St. Edison
2 Svendson Tammy 34 Apple Way Colonia
3 Pettersen Kimmie 56 Patio Place Iselin
30. The "DateOfBirth" column is now of type year and is going to hold a year in a
two-digit or four-digit format. DO: Use a DESC statement on the Persons28 table to see this change.
31. To delete the column named "DateOfBirth" in the "Persons28" table, DO the following
SQL statement:
ALTER TABLE Persons28
DROP COLUMN DateOfBirth
32. DO: Use a Select command to demonstrate that the "Persons28" table will now look like this:
P_Id LastName FirstName Address City
1 Hansen Harry 12 Smith St. Edison
2 Svendson Tammy 34 Apple Way Colonia
3 Pettersen Kimmie 56 Patio Place Iselin

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

The term up in the air means undecided.

Answered: 1 week ago