You are on page 1of 3

Yarmouk University

Faculty of Information Technology and Computer


Sciences Department of Information Systems

DDL Worksheet
Couse CIS260L: Data Base Lab
Fall 2020

Questions
Q1) Create the following tables.

Authors

Field Name Constraints Data Type

Author_ID Number (10)

Author_Name Not Null Varchar2 (20)

Country Varchar2 (10)

Books

Field Name Constraints Data Type

Book_ID Unique Number (10)

Title Not Null Varchar2 (20)

BooksAuthors

Field Name Constraints Data Type

Book_ID Not Null Number (10)

Author_ID Not Null Number (10)

Prepared by: Dr. Enas Khashashneh


Yarmouk University
Faculty of Information Technology and Computer
Sciences Department of Information Systems

DDL Worksheet
Couse CIS260L: Data Base Lab
Fall 2020

Q2) Define the primary key constraints in the Books and Authors tables at table level.

Q3) Define foreign key constraints in BooksAuthors table at table level.

Q4) Add the following column to Books table using ALTER statement.

Field Name Constraints Data Type

Release_Date Not Null DATE

Q5) Add the following column to Authors table using ALTER statement.

Field Name Constraints Data Type

AGE NUMBER (10)

Q6) Add check constraint for Authors that restrict the values for AGE field to be larger than 18.

Q7) Change the definition of Release_Date field in Books, so the default value for this field will
be the current date or sysdate?
Solution:

Q1)
create table authors
(
author_id number(10),
author_name varchar2(20) NOT NULL,
Country Varchar2(10)
)
create table books
(
Book_ID number(10) unique,
Title varchar2(20) NOT NULL
)
create table BooksAuthors
(
Book_ID number(10) NOT NULL,
Author_ID number(10) NOT NULL
)
Q2)
ALTER TABLE authors
ADD CONSTRAINT authors_author_ID_PK PRIMARY KEY (author_ID);
ALTER TABLE books
ADD CONSTRAINT books_book_ID_PK PRIMARY KEY (book_ID);
Q3)
ALTER TABLE BooksAuthors
ADD CONSTRAINT BooksAuthors_author_id_fk
FOREIGN KEY (author_id) REFERENCES authors(author_id);
ALTER TABLE BooksAuthors
ADD CONSTRAINT BooksAuthors_book_id_fk
FOREIGN KEY (book_id) REFERENCES books(book_id)
Q4)
ALTER TABLE Books
add Release_Date DATE constraint books_rd_nn Not Null;
Q5)
ALTER TABLE authors
add AGE number(10);
Q6)
ALTER TABLE authors
ADD CONSTRAINT authors_age_check check (age >=18);
Q7)
ALTER TABLE books
MODIFY Release_Date date DEFAULT sysdate;

Prepared by: Dr. Enas Khashashneh

You might also like