Download 2002ICT Lab Notes 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database wikipedia , lookup

Concurrency control wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Expense and cost recovery system (ECRS) wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Versant Object Database wikipedia , lookup

Data vault modeling wikipedia , lookup

Clusterpoint wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Transcript
Database Design - Lab Notes 1
Lab Objectives: 1. use of SQLplus
2. Data definition in SQL
Instructions on using Oracle in the labs:
1. Click start-->programs-->Oracle -->SQLplus, SQLPLUS log on window
appears.
2. Your user name is your student number with prefix s. Your initial password is
pDDMM where DD is your date of birth, MM is your month of birth. For
example, if your date of birth is 12/03/1985, then your password is p1203. if
your student number is 1234567, then your user name is s1234567. For host
string, type CITSTD.
3. Once logged in, type password to change your password.
4. For SQLPlus command line editing, see section 2.0 of SQLBooklet.pdf. You
can also use notepad or any plaintext editor (DO NOT USE WORD) to create
a script file (eg. c:\myfiles\test1.sql) containing your SQL commands. You can
then run the script file in SQLPlus by typing @c:\myfiles\test1. All commands
in your script file will be run one by one. The commands in your script can be
conveniently modified later. See SQLBooklet.pdf or SQL Plus Manual for
more details.
Data Definition in SQL
Once logged into SQLplus, please try to create some tables some examples. You may
want to first copy and paste the command into notepad so as to ensure there are no
hidden characters, and then copy and paste again from notepad to SQLplus. Of
course, you can type the commands directly into SQLplus. But editing is hard.
Examples:
create table Department (
Dept_no
char(4)PRIMARY KEY,
Dept_name varchar2(25));
create table Department (
dept_no
char(4),
Dept_name varchar2(25),
CONSTRAINT dept_PK PRIMARY KEY(dept_no));
Exercise 1: Basic concepts
1. Explain the following concepts:
Data, metadata, database, DBMS, schema, instance, logical data
independence, physical data independence, DDL, DML, procedural language,
declarative language. relation, relational database. superkey, candidate key,
primary key, foreign key.
2. The following relation schemas form part of a relational database schema.
Hotel (hotelNo, hotelName, city)
Room (roomNo, hotelNo, type, price)
Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
Guest (guestNo, guestName, guestAddress)
where Hotel contains hotel details, Room contains room details for each hotel,
Booking contains details of bookings, and Guest contains guest details.
(1) Use the above tables to explain the differences between superkey,
candidate key and primary key.
(2) Identify the foreign keys in this schema and draw the diagram
representing the FKs.
(3) Explain how the entity integrity and referential integrity rules apply to
these relations.
3. Consider the following tables in a simplified banking systems
Branch(bNo, bName, bStreet, bCity)
Customer(cNo, cName, cStreet, cCity, cPhone)
Account(bNo, accNo, accType, cNo, balance)
Transactions(tNo, tDatetime, bNo, accNo, place, amount)
where
bNo, bName, bStreet, and bCity are branch number, branch name, branch
street and branch city respectively;
cNo, cName, cStreet, cCity and cPhone are customer's ID number, name,
street, city (living address) and telephone number respectively;
accNo , and accType are account number and account type respectively;
tNo is the transaction number, tDatetime is the date and time of the
transaction, and amount is the amount of the transaction.
(1) Identify a primary key for each table
(2) Identify the foreign keys
(You need to make your own assumptions when identifying the PKs and FKs)