You are on page 1of 4

5 Structured Query Language (I): Manipulation of Database

Tables

ICT Focus
 Creating a database
 Creating a database table
 Setting constraints on a database table
 Creating an index for a database table
 Inserting data into a database table
 Changing the structure of a database table
 Removing a database
 Removing a database table
 Setting the access rights of database users

 SQL is only for carrying out database operations while general-purpose computer
languages are for building applications.

Activity 3
CREATE TABLE Equipment
(equipID CHAR(5) NOT NULL UNIQUE, equipName CHAR(30) NOT
NULL, equipPrice INTEGER);

CREATE TABLE BorrowRecord


(borrowID CHAR(5) NOT NULL UNIQUE, employeeID CHAR(4) NOT
NULL, equipID CHAR(5) NOT NULL, dateOfBorrow DATE NOT
NULL, dateOfReturn DATE NOT NULL);

Activity 4
(a) ‘fileName’, ‘releaseYear’ and ‘directorName’. In the same year, a director
usually does not produce two films of the same name.

(b) CREATE TABLE Films


(filmName CHAR(50), releaseYear INTEGER, category
CHAR(5), directorName CHAR(40), PRIMARY KEY (filmName,
releaseYear, directorName));

Activity 5
1. CREATE DATABASE Business;
© Pearson Education Asia Limited 2010 1 NSS ICT Elective A1 Textbook Answers
2. CREATE TABLE Salesman (salesID CHAR(6) PRIMARY KEY,
salesName CHAR(20));

3. CREATE TABLE Customer


(custID CHAR(6) PRIMARY KEY, custName CHAR(20),
salesBranch CHAR(3), salesID CHAR(6), FOREIGN KEY
(salesID) REFERENCES salesman(salesID));

Concept Map
1. B
2. A
3. C
4. D

Concept Checker
1. T
2. T
3. T
4. F
5. F
6. T
7. F
8. T

Multiple Choice Questions


1. D
2. C
3. C
4. B
5. D
6. A
7. B
8. D
9. A
10. A

© Pearson Education Asia Limited 2010 2 NSS ICT Elective A1 Textbook Answers
Short Questions
1. Functions of a DDL:
 Create database objects.
 Define the structures of the database objects and the integrity constraints of
the database.
 Modify the structures of the database objects.
 Remove the database objects.
(any three × 1)

Functions of a DML:
 Insert new records.
 Modify existing records.
 Delete existing records.
 Retrieve data from the database.
(any three × 1)

2. Table name / field names / data types of the fields / ‘NOT NULL’ constraint /
‘Default’ constraint / ‘Unique’ constraint / primary key / foreign key
(any five × 1)

3. (a) CREATE TABLE Friend (name CHAR(25), gender CHAR(1),


dateOfBirth DATE); (2)

(b) The field names of the table in sequence (1) and the data types of the fields
(1)

(c) INSERT INTO Friend


VALUES ('Wise Ho', 'M', '1988/04/18'), ('Benny
Kwan'. 'M', '1999/02/19'); (2)

Long Questions
1. (a) CREATE TABLE Book
(bookID INTEGER PRIMARY KEY, title CHAR(40), price
DECIMAL(5, 1)); (2)

(b) ALTER TABLE Book ADD COLUMN


(weight DECIMAL(4, 1), publishDate DATE, numOfPage
SMALLINT, quantity SMALLINT); (2)
© Pearson Education Asia Limited 2010 3 NSS ICT Elective A1 Textbook Answers
(c) ALTER TABLE Book MODIFY COLUMN bookID CHAR(6); (1)

(d) INSERT INTO Book


VALUES ('091101', 'The Big Zoo', 80.1, 800.0,
'10/01/2010', 320, 10), ('091102', 'The Ocean',
25.5, 341.0, '21/06/2010', 140, 20); (4)

(e) CREATE TABLE Publisher


(pID CHAR(6) PRIMARY KEY, pName CHAR(50), pPhoneNo
CHAR(8), pFaxNo CHAR(8), pAddress CHAR(100),
pContactPerson CHAR(25)); (2)

(f) ALTER TABLE Book ADD COLUMN publisherID CHAR(6); (2)


ALTER TABLE Book ADD FOREIGN KEY (publisherID)
REFERENCES Publisher(pID); (2)

© Pearson Education Asia Limited 2010 4 NSS ICT Elective A1 Textbook Answers

You might also like