INF121 - Introduction to Relational Databases

advertisement
1
INF121 - Introduction to Relational Databases
Part I
Q.1
Q.2
Q.3
Q.4
Q.5
Q.6 Accurate, relevant, and timely information is the key to good decision making.
Q.7
Metadata provide(s) a description of the data characteristics and the set of relationships
that link the data found within the database.
2
Q.8 The response of the DBMS to a query is the query result set .
Q.9
A(n) Transactional database is designed to support a company’s day-to-day operations.
Q.10 A workgroup database is a(n) Enterprise database.
Q.11
Most decision-support data are based on historical data obtained from workgroup databases.
Q.12 Semistructured data exist in the format in which they were collected.
Q.13
Most data you encounter is best classified as Structured .
Q.14
A database is a logically connected set of one or more fields that describes a person, place or
thing.
Q.15 A Column is a collection of related records.
Q.16 Example of un-normalized data
Q.17 If the maximums are one in one direction and
many in the other direction, we say the relationship
is One-to-many
Q.18 Data are: Raw facts
Q.19 Database is: Shared, integrated computer structure that stores a collection of end-user data
and metadata.
3
Q.20
Q.21 Primary key A candidate key selected to
uniquely identify all other attribute values in any
given row.
Q.22
Q.23 Relationship – a natural business association
that exists between one or more entities.
Q.24
Use the following table to choose the following queries in SQL:
CUSTOMER (CUST_ID, CUST_NAME, ANNUAL_REVENUE)
Q.25 Choose the correct query to create table customer in SQL:
create table customer(cust_id integer, cust_name varchar(15), annual_revenue integer);
4
Q.26 Choose the correct query to insert the first row in a table customer in SQL:
433
Maria
insert into customer (cust_id, cust_name) values (433, “Maria”);
Q.27 Choose the correct query to express ‘all rows’ of table customer in SQL:
select * from customer;
Q.28 The E-R diagram below is a part of a complete database. In this case there is a many-tomany relationship between the entities CUSTOMER and NEWSPAPER. Indicate possible fields
of entities CUSTOMER and NEWSPAPER.
Identify primary keys
Student
M
N
Is registered for
Subject
Student (StudentID, Name, Surname, Address , DateofBirth, DateEnrolled, Subject1, Subject2,
Subject3)
Subject (SubjectCode, SubjectName, HrsPerWeek, TutorID, TutorName)
Q.29 Start Microsoft Access and create a new database with name Sales in the folder described
above.
Q.30 Create the table Customers, according to the following fields.
Field Name
CustomerID
CustomerName
CompanyName
Address
Name
City
Region
PostalCode
Country
Phone
Fax
Type
Text
Text
Text
Text
Text
Text
Text
Text
Text
Text
Size
Default Value
Format
Create the table Products, according to the following fields.
Field Name
ProductID
ProductName
SupplierID
CategoryID
Type
AutoNumber
Text
Number
Number
Size
Default Value
Format
5
QuantityPerUnit
UnitPrice
UnitsInStock
UnitsOnOrder
ReorderLevel
Discontinued
Text
Currency
Number
Number
Number
Yes/No
Create the table Categories, according to the following fields.
Field Name
CategoryID
CategoryName
Description
Picture
Type
AutoNumber
Text
Memo
OLE Object
Size
Default Value
Format
Create the table Orders, according to the following fields.
Field Name
OrderID
CustomerName
OrderDate
RequiredDate
ShippedDate
Freight
ShipName
ShipAddress
ShipCity
ShipRegion
ShipPostalCode
ShipCountry
Employee
ShipVia
Type
AutoNumber
Text
Date/Time
Date/Time
Date/Time
Currency
Text
Text
Text
Text
Text
Text
Number
Number
Size
Default Value
Format
Enter the records in the Category table Categories as shown below:
Category
1
ID
2
3
4
5
6
7
8
Category Name
Beverages
Condiments
Confections
Dairy Products
Grains/Cereals
Meat/Poultry
Produce
Seafood
Description
Soft drinks, coffees, teas, beers, and ales
Sweet and savory sauces, relishes, spreads, and seasoning
Desserts, candies, and sweet breads
Cheeses
Breads, crackers, pasts, and cereal
Prepared meats
Dried fruit and bean curd
Seaweed and fish
Your table should now appear as the following:
Picture
6
Q.31 Open the table Products in the design view Q.32 Open the table Customers in the
and modify the field property UnitPrice to show design view and modify the field property
the price in red colour.
city create a lookup value to display the
following cities: Limassol, Lefcosia, Pafos,
Larnaca, Ammohostos, Kyrenia.
Q.33 Create a form with the name Categories3.
7
Query
1 Create
Query in
Design View
8
2
3
9
Q.34 Also set for the field property Country the default value to Cyprus.
Q.35 First Names should all be converted to capital letters.
Last Names should all be converted to capital letters.
Q.36 Also set for the field property Country the Q.37 First Names should all be converted to
default value to Cyprus.
capital letters.
Part II
Q.38 What are the advantages of having the DBMS between the end user’s applications and the
database?
There are some important advantages. The DBMS allows the data in the database to be shared among
multiple applications or users. Also the DBMS combines the different users’ views of the data into a
single all-containing data repository (store).
Q.39 Describe a conceptual model and its advantages. What is the most widely used conceptual
model?
The conceptual model represents a total view of the entire database. The conceptual model combines all
external views (entities, relationships, constraints, and processes) into a single global view of the entire
data in the enterprise. It is also known as a conceptual schema. It is the basis for the identification and
description of the main data objects.
10
The ER model is used more often. The ER model is illustrated with the help of the ERD. The ERD is used
to graphically represent the conceptual schema.
The conceptual model has important advantages. It provides an understandable view of the data
environment.
Also the conceptual model is independent of both software and hardware. Software independence means
that the model does not depend on the DBMS software used to implement the model. Hardware
independence means that the model does not depend on the hardware used in the implementation of the
model. Therefore, changes in either the hardware or the DBMS software will have no effect on the
database design at the conceptual level.
Q.40 What are the characteristics of a relational table?
1 A table is a two-dimensional structure composed of rows and columns.
2 Each table row (tuple) represents a single entity occurrence within the entity set.
3 Each table column represents an attribute, and each column has a distinct name.
4 Each row/column intersection represents a single data value.
5 All values in a column must conform to the same data format.
6 Each column has a specific range of values known as the attribute domain.
7 The order of the rows and columns is unimportant to the DBMS.
8 Each table must have an attribute or a combination of attributes that uniquely identifies each row.
Q.41 What is a key and why is it important in the relational model?
In the relational model, keys are important because they are used to secure that each row in a table is
uniquely identifiable. They are also used to establish relationships among tables and to ensure the
integrity of the data. That is why it important to understand the use of keys in the relational model. A key
consists of one or more attributes that determine other attributes. For example, an invoice number
identifies all of the invoice attributes, such as the invoice date and the customer name.
Q.42 Describe the five types of users identified in a database system
System administrators oversee the database system’s general operations.
Database administrators, also known as DBAs, manage the DBMS and ensure that the database is
functioning properly.
Database designers design the database structure. They are, in effect, the database architects. If the
database design is poor, even the best application programmers and the most dedicated DBAs cannot
produce a useful database environment. Because organizations strive to optimize their data resources, the
database designer’s job description has expanded to cover new dimensions and growing responsibilities.
Systems analysts and programmers design and implement the application programs. They design and
create the data entry screens, reports, and procedures through which end users access and manipulate the
database’s data.
End users are the people who use the application programs to run the organization’s daily operations. For
example, salesclerks, supervisors, managers, and directors are all classified as end users. High-level end
users employ the information obtained from the database to make tactical and strategic business
decisions.
Q.43Discuss what is a system catalog
11
Like the data dictionary, the system catalog contains metadata. The system catalog can be described as a
detailed system data dictionary that describes all objects within the database, including data about table
names, the table’s creator and creation date, the number of columns in each table, the data type
corresponding to each column, index filenames, index creators, authorized users, and access privileges.
Because the system catalog contains all required data dictionary information, the terms system catalog
and data dictionary are often used interchangeably. In fact, current relational database software generally
provides only a system catalog, from which the designer’s data dictionary information may be derived.
The system catalog is actually a system-created database whose tables store the user/designer-created
database characteristics and contents. Therefore, the system catalog tables can be queried just like any
user/designer-created table.
Use MySQL for solving these questions.
Write the SQL code for the queries following the given relational database schema:
STUDENT(StudNum, StudName, PhoneNo, Address, City, Birthdate, Sex)
REGISTRATION(StudNum,SubjectCode, Grade, Reg_Date)
SUBJECT(SubjectCode, Title, Description, Credits, InstructorNum)
INSRUCTOR(CInstructorNum, Name, PhoneNo, Annual Salary, Address City, Department)
Q.44 (A) What is the name of student 1023? Express ‘all rows’ of table student in SQL
select student.StudName from student where student.StudNum=”1023”;
Use MySQL for solving these questions.
Write the following SQL queries for the given relational database schema:
CLIENT(Client-Id, Client-Name, Client-Address, Client-Tel.)
PROJECT(Project-No, Project-Title, Total-Change, Client-Id, Invoice-No, Invoice-Date)
CHARGE(Charge-No, Project-No, Amount, description)
SERVICE(Charge-No, Project-No, Consultant)
Q.44 (B) What is the address of client “Smith”?
select client.client_Address from client where client.client_name=”Smith”;
Q.45 What is the address of client “Nikolaou”?
select client.client_Address from client where client.client_name=”Nikolaou”;
Q.46 A list of all the clients having consultant Mrs. Smith.
SELECT client_name, consultant FROM client INNER JOIN project ON client.client_id =
project.client_id INNER JOIN charge ON project.project_no = charge.project_no INNER
JOIN service ON charge.charge_no = service.charge_no WHERE consultant like "Smith";
Q.47 List the services that have charge a project with more than €3000.
12
SELECT amount, consultant FROM charge INNER JOIN service ON charge.charge_no =
service.charge_no WHERE amount >= 3000;
Q.48 What are the names of the clients who live in “Anexartisias 5”?
select client.client_name from client where client.client_Address=”Anexartisias 5”;
Q.49 Add client “Browns” with address “Palmers Green”.
Insert into client(client_id, client_name, client_Address, Client_Tel) values
(00006,”Browns”,”Palmers Green”,”25444222”);
Q.50 Add client “Ioannou” with address “Fragklinou Rousevelt 17”.
Insert into client(client_id, client_name, client_Address, Client_Tel) values
(00007,”Ioannou”,”Fragklinou rousevelt 17”,”25994442”);
Write the following SQL queries for the given relational database schema:
CITY (CITY_NAME, POPULATION)
Q.51 Create table city in SQL:
Table city
City
Population
create table city(name varchar(15), population integer);
Q.52 Insert the first row in a table city in SQL:
Table city
City
London
Population
10.000.000
insert into city (name, population) values (“London”, 10000000);
Q.53 Express ‘all rows’ of table city in SQL
select * from city;
Q.54 create table worker (workerid integer, name varchar(15), hourly_rate integer,
skill_type varchar(15), supv_id integer);
Q.55 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“1235”,
“M.Faraday”, “12”, “Electric”, “1311”);
Q.56 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“1412”,
“C.Nemo”, “13”, “Plumbing”, “1520”);
13
Q.57 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“2920”,
“R.Garret”, “10”, “Roofing”, “1411”);
Q.58 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“3231”,
“P.Mason”, “17”, “Framing”, “6713”);
Q.59 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“1520,
Rickover”, “11, “Plumbing” “1399”);
Q.60 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“1315”,
“C.Coulomb”, “15”, “Electric”, “1351”);
Q.61 insert into worker (workerid, name, hourly_rate, skill_type, supv_id) values (“3001”,
“J.Barrist”, “8, “Framing”, “3231”);
Q.62 select * from worker;
Q.63 create table building (bldg-id integer, bldg_address varchar(15), type varchar(15),
qlty_level integer, status integer);
Q.64 insert into building (bldg-id, bldg_address, type, qlty_level, status) values (“312”,
“123 Elm”, “Office”, “2”, “2”);
Q.65 select * from building;
Q.66 insert into building (bldg-id, bldg_address, type, qlty_level, status) values (“435”,
“456 Maple”, “Retail”, “1”, “1”);
Q.67 insert into building (bldg-id, bldg_address, type, qlty_level, status) values (“515”,
“789 Oak”, “Residence”, “3”, “1”);
Q.68 insert into building (bldg-id, bldg_address, type, qlty_level, status) values (“210”,
“1011 Birch”, “Office”, “3”, “2”);
Q.69 insert into building (bldg-id, bldg_address, type, qlty_level, status) values (“111”,
“1213 Aspen”, “Office”, “4”, “1”);
Q.70 insert into building (bldg-id, bldg_address, type, qlty_level, status) values (“460”,
“1415 Beech”, “Warehouse”, “3”, “3”);
Q.71 select * from building;
Q.72 select worker.name from worker where worker.worker_id=1235;
Q.73 information is the result of processing raw data to reveal its meaning.
Q.74 To reveal meaning, information requires context.
14
Q.75 Raw data must be properly formatted for storage, processing and presentation.
Q.76 A(n) request is a specific request issued to the DBMS for data manipulation.
Q.77 XML (Extensible Markup Language) is a special language used to represent and
manipulate data elements in a textual format.
Q.78 A(n) data model is a relatively simple representation of more complex real-world data
structures.
Q.79 A(n) segment in a hierarchical model is the equivalent of a record in a file system.
Q.80 Each column in a relation represents a(n)attribute.
Q.81 A(n)relational diagram is a representation of the relational database’s entities, the attributes
within those entities and the relationships between those entities.
Q.82 The term logical design is used to refer to the task of creating a conceptual data model that
could be implemented in any DBMS.
Q.83 In the relational model, keys are important because they are used to ensure that each row in
a table is uniquely identifiable.
Q.84 A(n) equijoin (another form of JOIN) links tables on the basis of an equality condition that
compares specified columns of each table.
Q.85 The index key can have multiple attributes, this is called a(n) ____________________
index.
Q.86 Codd’s rule of Guaranteed Access states that every value in a table is guaranteed to be
accessible through a combination of table name, primary key value, and column name.
Q.87 An alias is especially useful when a table must be joined to itself in reqursive queries.
Download