Professional Documents
Culture Documents
DDL Worksheet
Couse CIS260L: Data Base Lab
Fall 2020
Questions
Q1) Create the following tables.
Authors
Books
BooksAuthors
DDL Worksheet
Couse CIS260L: Data Base Lab
Fall 2020
Q2) Define the primary key constraints in the Books and Authors tables at table level.
Q4) Add the following column to Books table using ALTER statement.
Q5) Add the following column to Authors table using ALTER statement.
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;