Tutorial 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Question 1

Assume that part of a database contained the following details:

Customer (cust-no, cust-name, address, postal-area)

Order (order-no, order-date, cust-no, order-total)

Order-line (order-no, prod-no, ord-qty, line-total)

Product (prod-no, prod-desc, unit-price)

For each of the following queries, write a separate solution:

(a) Display all the values from the Order table.


SELECT *
FROM Order;

(b) Display a list of products, including the description and unit price.
SELECT description, unit_price
FROM product;

(c) Display the unique customer number in the Order table.

SELECT UNIQUE cust_no

FROM customer;

(c) Create a query to display the product number, Product description, unit price and
unit price after a raise of 13% VAT. Name the last column (unit price after a
raise) heading as “Including VAT” (Product table).
SELECT prod_no, prod_desc, unit_price, unit_price + (0.13 * unit_price)
AS “Including VAT”
FROM products;
(d) Create a query to display the customer’s number and customer’s name in the
same field and name the column heading as “Customer Details” also place literal

characters to look more descriptive. The Output should be like this :

Customer Details

The Customer number of “cust_name” is “cust_no”

SELECT 'The Customer number of' ||' '|| cust_name ||' is '|| cust_no
AS "Customer Details"
FROM customer;
Question 2

Explain the terms Data Definition Language, Data Manipulation Language and Data
Control Language. As part of your explanation you should provide knowledge of the
use of at least 3 commands for each language using SQL notation.

Date Definition Language: DDL is the abbreviation for Data Defining Language.
The set of SQL commands that are create and manipulate the structures of the
database are called data defining language. It is a language that is used for creating
and modifying structure of the database objects, such as tables, indexes, etc. DDL
helps to specify the logical design of each relation.

The three DDL commands used are:

CREATE: It is used to create new table in a database.

ALTER: It is used to add, delete and modify columns in an existing table.

DROP: It is used to drop and existing table in the database.

Data Manipulation Language: DML is the abbreviation for Data Manipulation


Language. The set of SQL commands that allows users to access and manipulate
the data in the database. Using DML statements user can retrieve, insert, delete or
modify the information in the database.

The three DDL commands used are:

SELECT: This command helps to select data or records from a database.

INSERT: This command adds new records to the database.

DELETE: This command deletes the records in the database.


Data Control Language: DCL is the abbreviation for Data Control Language. Data
Control Language includes commands such as GRANT, and is concerned with
rights, permissions, and other controls of the database system. DCL is used to
grant/revoke permissions on databases and their contents. DCL statements allow
you to control who has access to a specific object in your database.

The DCL commands used are listed below:

GRANT: It provides the user's access privileges to the database.


(b) What is Data Modeling?

Data Modeling refers to the process of creating a data model for the data to be
stored in a database. This data model is a logical representation of data objects, the
associations between different data objects. Data modeling helps in the visual
representation of data and establishes rules and regulations on the data. Data
Models ensure consistency in naming conventions, default values, semantics, and
security while ensuring quality of the data. Data Model is an abstract of conceptual
design process.

The data model consists of three types which are listed below:

 Conceptual Data Model


This model focuses on identifying the data. The Entity-Relationship (ER)
model is a high level data model that is used to define the data elements and
the relationship for a system. ER model helps to develop a conceptual design
for the database. With the help of data modeling
 Logical Data Model
The main objective of this data model is to define the data structures and
establish relationships between them. The logical data model adds further
information to the conceptual data model elements. This data model also
forms the foundation to create the base of the physical model.
 Physical Data Model
A Physical Data Model describes how physical data model represents how
the model will be built in the database. It offers database abstraction and
helps generate the description of the system. This is because of the richness
of meta-data offered by a Physical Data Model. The physical data model also
helps in visualizing database structure by replicating database column keys,
constraints, indexes, triggers, and other unique features.
(c) Differentiate between Conceptual, Logical and Physical database design.

 The logical and the physical database design consists entities, relationships,
primary keys and foreign key while the conceptual design consists of entities
and relationships between the entities.
 The conceptual design doesn’t represent any attributes while the logical and
physical model represents attributes.
 The conceptual design is the basis to develop the logical design while the
logical design is the basis to develop the physical design.
 The conceptual design is simpler in terms of both logical and physical
database design.
 Physical and logical design implements normalization while the conceptual
design does not.

(d) Describe:

 Levels of Abstraction: Database systems comprise of complex data structures.


Thus, to make the system efficient for retrieval of data and reduce the complexity
of the users, developers use the method of Data Abstraction.

There are mainly three levels of data abstraction:

Internal Schema: The internal schema is the lowest level of data abstraction. It
tells what data are stored in the database. It contains multiple types of records. It
helps you to keeps information about the actual representation of the entire
database. Like the actual storage of the data on the disk in the form of records.

Logical Schema: This schema defines all database entities, their attributes, and
their relationships. This level of the abstraction also deals with the security and
the integrity of the information. This logical level comes between the user level
and physical storage view.
External Schema: This is the level of abstraction in which the end-users interact
with the information. Each external view is defined using an external schema,
which consists of definitions of various types of external record of that specific
view. External schema level is nearest to the user.

You might also like