0% found this document useful (0 votes)
137 views3 pages

Questions: DDL Worksheet

This document contains questions for a database lab assignment. It asks students to create tables for authors, books, and a joining table. It also asks students to define primary and foreign keys, add columns, and add constraints like check and default values.

Uploaded by

khaled al omari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views3 pages

Questions: DDL Worksheet

This document contains questions for a database lab assignment. It asks students to create tables for authors, books, and a joining table. It also asks students to define primary and foreign keys, add columns, and add constraints like check and default values.

Uploaded by

khaled al omari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy