Tải bản đầy đủ (.pdf) (46 trang)

PHYSICAL DATABASE DESIGN pps

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (332.6 KB, 46 trang )

3A.1 Relational Database Desi
g
n
L
L
E
E
S
S
S
S
O
O
N
N
:
:
3
3
A
A
P
P
H
H
Y
Y
S
S
I
I


C
C
A
A
L
L
D
D
A
A
T
T
A
A
B
B
A
A
S
S
E
E
D
D
E
E
S
S
I
I

G
G
N
N
O
O
b
b
j
j
e
e
c
c
t
t
i
i
v
v
e
e
s
s
In this lesson, you will learn to:
 Identify the following kinds of relations:
x Base tables
x
Query results
x

Views
 Create tables
 Alter tables
 Remove tables
 Query tables and work on them
 Define views
 Perform DML operations on views
 Identify the different types of views

Identify data integrity constraints
3A.2
Relational Database Desi
g
n
Physical Database Design Lesson 9 / Slide 1 of 13©NIIT
Physical Database Design
Objectives
In this section, you will learn to:

Identify the following kinds of relations:

Base tables

Query results

Views

Create tables

Alter tables


Remove tables

Query tables and work on them

Define views

Perform DML operations on views

Identify the different types of views

Identify data integrity constraints
I
I
N
N
S
S
T
T
R
R
U
U
C
C
T
T
O
O

R
R
N
N
O
O
T
T
E
E
S
S
Lesson Overview
The lesson covers the different kinds of relations. It also explains how to create, alter,
remove, and query tables. In addition, the lesson explains the different types of views,
the various DML operations that can be performed on them, and data integrity
constraints.
3A.3 Relational Database Desi
g
n
Physical Database Design©NIIT
Physical Database Design
Pre-assessment Questions
1. Functional dependencies represent _______ relationships.
2. What is the term used for the intentional introduction of redundancy in a table in
order to improve performance?
3. Each value of an attribute A in relation R is associated with precisely one value of
attribute B. What is this called?
4. A table is said to be in the _____ when each cell of the table contains precisely
one value.

5. In a relation, every determinant is a candidate key. This relation is in which
normal form?
Lesson 9 / Slide 2 of 13
3A.4
Relational Database Desi
g
n
Physical Database Design©NIIT
Physical Database Design
Solutions
Ans1. Many-to-one
Ans2. Denormalization
Ans3. Functional dependency
Ans4. First normal form
Ans5. Boyce-Codd normal form
Lesson 9 / Slide 3 of 13
3A.5 Relational Database Desi
g
n
L
L
A
A
N
N
G
G
U
U
A

A
G
G
E
E
S
S
U
U
P
P
P
P
O
O
R
R
T
T
F
F
O
O
R
R
T
T
H
H
E

E
R
R
E
E
L
L
A
A
T
T
I
I
O
O
N
N
A
A
L
L
M
M
O
O
D
D
E
E
L

L
Physical Database Design Lesson 9 / Slide 4 of 13©NIIT
Physical Database Design
Language Support for the Relational
Model

Most relational database systems support a query language named
Structured Query Language (SQL).

SQL is a combination of three subordinate languages:

Data Definition Language (DDL)

Data Manipulation Language (DML)

Data Control Language (DCL)

The three important types of relations are:

Base tables

Query results

Views
Most relational database systems support a query language named Structured Query
Language (SQL). Like any other query language, SQL is a combination of three
subordinate languages:

Data Definition Language (DDL)
Data Manipulation Language (DML)

Data Control Language (DCL)
DDL statements include operators for creation and deletion of tables and indexes. DML
statements are used to enter data into the tables created by using DDL statements.
DML statements are also used to update and delete data and perform complex queries
on the tables. DCL statements are used to control users’ access to the tables.
3A.6
Relational Database Desi
g
n
Kinds of Relations
A relational system can have different kinds of relations. However, the three important
types of relations are:
Base tables
Query results
Views
Base Tables
Physical Database Design Lesson 9 / Slide 5 of 13©NIIT
Physical Database Design
Base Tables

A base table is a named table that physically exists in a database.

The SQL statement to create a table is CREATE TABLE.

You can alter an existing table by using the ALTER TABLE
statement.

You can remove a table by using the DROP TABLE statement.
A base table is a named table that physically exists in a database. You can physically
create a table after you have mapped the entity-relationship diagram to corresponding

tables and normalized the tables. DDL statements are used to create tables.
3A.7 Relational Database Desi
g
n
Creating Tables
The SQL statement to create a table is CREATE TABLE. For example, the following
statement creates the customer table:
CREATE TABLE customer
(cust-no CHAR(5) NOT NULL,
name CHAR(15),
phone-number CHAR(7),
city CHAR(15),
PRIMARY KEY (cust-no))
The CREATE TABLE statement is followed by the table name, which is customer in this
example. Note that everything after the table name is enclosed in parentheses. The
information in parentheses includes the column names or attributes of the customer
table. The attributes in this example are cust-no, name, phone-number, and city.
CHAR signifies that the column cust-no will contain character type of data. The size of
the column is specified in parentheses after the name of the data type.
The primary key is also defined in the above statement by using the PRIMARY KEY
clause. The clause here signifies that the attribute cust-no is the primary key. The
primary key should not contain any null values. Therefore, the NOT NULL clause has
been specified with the attribute cust-no. The NOT NULL clause can be used to define
any attribute as not null irrespective of whether the attribute is a primary key. For
example, if you do not want any null values in the name column, the CREATE TABLE
statement can be modified as:
CREATE TABLE customer
(cust-no CHAR(5) NOT NULL,
name CHAR(15) NOT NULL,
phone-number CHAR(7),

city CHAR(15),
PRIMARY KEY (cust-no))
Now, you will look at creating a table whose attribute refers to another table. For
example, the SQL statement to create the sale table is:
CREATE TABLE sale
(cust-no CHAR(5),
prod-no CHAR(5),
qty DECIMAL(8,2),
PRIMARY KEY (cust-no, prod-no),
FOREIGN KEY (cust-no) REFERENCES customer,
FOREIGN KEY (prod-no) REFERENCES product)
If the primary key is made up of more than one attributes, then the attributes are
named after the PRIMARY KEY clause and are separated by a comma. In the above
example, the primary key is made up of two attributes, cust-no and prod-no. The
FOREIGN KEY clause is followed by the name of the attribute. The REFERENCES clause
is followed by the name of the table that the attribute references.
3A.8
Relational Database Desi
g
n
Altering Tables
You can alter an existing table by using the ALTER TABLE statement. For example, the
SQL statement to include a column address in the customer table is:
ALTER TABLE customer ADD address CHAR(20)
The above statement adds a fifth column address in the customer table and assigns
null to all values in the column. You cannot specify the NOT NULL clause with the
ALTER TABLE statement.
Removing Tables
You can remove a table by using the DROP TABLE statement. For example, the SQL
statement to remove the customer table is:

DROP TABLE customer
When a table is created, the description of the table is stored in the system catalog.
The system catalog stores the names of tables, their attributes, and the data types of
the attributes. The system catalog also stores other details like the users of the tables.
Therefore, when you issue the DROP TABLE statement, the description of the specified
table is removed from the system catalog.
3A.9 Relational Database Desi
g
n
Query Results
Physical Database Design Lesson 9 / Slide 6 of 13©NIIT
Physical Database Design
Query Results

The results of queries made on a table are also tables.

DML statements in SQL are used to query tables and work on
them.

SELECT is the most powerful DML statement of SQL. All relational
operations can be performed by using the SELECT statement.

You can remove the duplicate rows in queries by using the
DISTINCT clause.

SQL can impose an order on the result of a query through the
ORDER BY clause.

A query in which data is retrieved from more than one table is
called a join query.


There are two types of joins, equi-join and self join.

The aggregate functions in SQL are COUNT, SUM, AVG, MAX, and
MIN.
3A.10
Relational Database Desi
g
n
Physical Database Design Lesson 9 / Slide 7 of 13©NIIT
Physical Database Design
Query Results (Contd )

SQL provides a clause IS NULL (or IS NOT NULL) for finding a null
value.

A query within a query is called a subquery.

The UNION operator of relational algebra is represented by the
UNION clause in SQL.

You can enter data in a table by using the INSERT statement.

SQL provides the UPDATE statement for updating data.

SQL provides the DELETE statement to delete a row.
The results of queries made on a table are also tables. For example, a query to list the
names of all the customers in the customer table will result in the following table:
NAME
Tim

Mary
Johnson
Ray
Smith
Query Result
You will now learn about the four DML statements in SQL that are used to query tables
and work on them. These statements are: SELECT, INSERT, UPDATE, and DELETE.
3A.11 Relational Database Desi
g
n
The SELECT Statement
SELECT is the most powerful DML statement of SQL. All relational operations can be
performed by using the SELECT statement.
Simple Queries
If you require the names and phone numbers of all customers, the SQL statement for
this query would be:
SELECT name, phone-number
FROM customer
This statement will give the following table as the result:
NAME PHONE-NUMBER
Tim 7821975
Mary 6792845
Johnson 8129333
Ray 1748799
Smith 3470944
Query Result
This statement represents the project operator in relational algebra. The statement
extracts only the columns name and phone-number from the customer table. The
SELECT clause specifies the column list and the FROM clause specifies the table from
which the columns are to be extracted. The same query can be reformulated by using

qualified column names as follows:
SELECT customer.name, customer.phone-number
FROM customer
In the above statement, the column names are prefixed with the name of the table to
which they belong. Such column names are called qualified column names.
Now, if you want to see all the columns of the customer table for only those customers
who live in Boston, you can use the following SQL statement:
SELECT *
FROM customer
WHERE city = “Boston”
This statement represents the restrict operator in relational algebra. The asterisk (*)
following the SELECT clause means that all the columns of the table will be displayed.
3A.12
Relational Database Desi
g
n
However, the display of rows will be restricted to those that satisfy the condition (city
= “Boston”). The result of this statement will be:
CUST-NO NAME PHONE-
NUMBER
CITY
C7248 Ray 1748799 Boston
Query Result
Consider the following query:
SELECT prod-no
FROM sale
The result of this query is:
PROD-NO
P4171
P5999

P4179
P5982
P4171
Query Result
The above table has duplicate rows. SQL does not automatically remove the duplicate
rows in such queries. However, you can remove the duplicate rows by using the
DISTINCT clause.
SELECT DISTINCT prod-no
FROM sale
PROD-NO
P4171
P5999
P4179
P5982
Query Result
Notice that this query result does not have any duplicate rows.
3A.13 Relational Database Desi
g
n
Retrieval with Ordering
Rows in a relation do not have any order. However, SQL can impose an order on the
result of a query through the ORDER BY clause. For example, if you want to find the
model names of the products whose price is less than $200, and you want to display
the query result in ascending order of the city name, the SQL statement is:
SELECT model
FROM product
WHERE price < 200
ORDER BY city
MODEL
Supermax

Aaron
Thunder
Flash
Queen
Query Result
The default order is ascending order. However, you can also specify descending order
by using the DESC clause as follows:
SELECT model
FROM product
WHERE price < 200
ORDER BY city DESC
Join Queries
A query in which data is retrieved from more than one table is called a join query. The
ability to join two or more tables is one of the most powerful features of SQL.
Equi-join
Equi-join is also called the natural join. For example, if you require a combination of
the records of the customers who live in the same city as the one where a particular
product is manufactured, the SQL statement would be:
SELECT cust-no, name, phone-number, customer.city, prod-no,
model, desc, price, product.city
3A.14
Relational Database Desi
g
n
FROM customer, product
WHERE customer.city = product.city
Notice that the connection between the tables customer and product has been defined
by using the join condition customer.city = product.city. Also notice that the column
names are qualified to distinguish a column of one table from that of another. This
represents the join operator of relational algebra.

The result of the above query would be:
CUST
-NO
NAME PHONE-
NUMBER
CUSTOMER.
CITY
PROD-
NO
MODEL DESC PRICE PROD
UCT.C
ITY
C4171 Tim 7821975 New York P8241 Supermax Food
Process
or
1795 New
York
C5999 Mary 6792845 Washington P7439 Aaron Refriger
ator
8484 Washin
gton
C4179 Johnson 8129333 Washington P4721 Slipp Juicer 1099 Washin
gton
C5982 Ray 1748799 Boston P4900 Queen VCR 12791 Boston
Query Result
In a join operation, you can also specify only certain columns to be retrieved. For
example,
SELECT customer.name, product.model
FROM customer, product
WHERE customer.city = product.city

The result of this query will have only the names of the customers and product models
that are from the same city.
You can also specify an additional condition in a join operation. For example,
SELECT customer.name, product.model
FROM customer, product
WHERE customer.city = product.city
AND price > 1500
3A.15 Relational Database Desi
g
n
Self Join
Self join is the joining of a table with itself. The self join illustrates the power of SQL to
perform complex queries. For example, if you require pairs of names of all the
customers who are located in the same city, the query would be:
SELECT first.cust-no, second.cust-no
FROM customer first, customer second
WHERE first.city = second.city
AND first.cust-no < second.cust-no
This query involves a self join. The join takes place over matching cities. To perform
the query, you need two copies of the customer table. You need to examine all
possible pairs of customers, one from the first copy of the customer table and another
from the second copy of the customer table.
To distinguish between the two copies, two variables have been introduced, first and
second. The first variable represents the first copy of the customer table and second
represents the second copy of the table. This query is carried out by examining all
possible pairs of values from first and second. In each case, the WHERE condition is
examined. The condition AND first.cust-no < second.cust-no eliminates pairs of
customer numbers of the form (x,x). It also ensures that pairs like (x,y) and (y,x) do
not appear together.
Aggregate Functions

There are some queries that cannot be answered by using the constructs of the
SELECT statement that we have seen so far. Examples of some such queries are:
How many products have been sold?
Which is the most expensive product?
What is the total quantity that has been sold?
What is the average price of the company’s products?
Which is the cheapest product?
What is the total sale transactions made?
All these queries can be answered by using the aggregate functions of SQL like SUM,
AVG, and COUNT. The answers to the above queries are as follows:
How many products have been sold?
SELECT COUNT (DISTINCT prod-no)
FROM sale
3A.16
Relational Database Desi
g
n
The result of this query is 5.
Which is the most expensive product?
SELECT prod-no, MAX (price)
FROM product
The result of this query is:
PROD-NO
P4900 12791
What is the total quantity that has been sold?
SELECT SUM (qty)
FROM sale
The result of this query is 1027.
What is the average price of the company’s products?
SELECT AVG (price)

FROM product
The result of this query is 7397.67.
Which is the cheapest product
?
SELECT prod-no, MIN (price)
FROM product
The result of this query is:
PROD-NO
P4721 1099
What is the total sale transactions made?
SELECT COUNT(*)
FROM sale
The result of this query is 7.
All aggregate functions, except COUNT(*), permit the use of the DISTINCT clause and
ignore null values.
If you want to know the total quantity sold for each product, the query would be:
SELECT prod-no, SUM (qty)
FROM sale
GROUP BY prod-no
3A.17 Relational Database Desi
g
n
The result of this query is:
PROD-NO
P5690 198
P3478 600
P7439 100
P4721 76
Query Result
The GROUP BY clause forms groups based on the column name you specify with this

clause. Within one group, all rows have the same value for the GROUP BY column. In
the above example, the sale table is grouped so that one group contains all the rows
for one product number. The SELECT clause then works on each group instead of each
row in the table. The expression in the SELECT clause must be single valued per
group. It should be the GROUP BY column itself or a function like SUM that reduces
the values of the rows in the group to a single value. The GROUP BY clause is different
from the ORDER BY clause. GROUP BY does not rearrange the output to display it in a
particular order.
If you want to display the product code for all products sold to more than one
customer, the query would be:
SELECT prod-no
FROM sale
GROUP BY prod-no
HAVING COUNT(*) > 1
Notice that a new clause HAVING is used in this query. This clause works like the
WHERE clause. The only difference is that the WHERE clause works on rows while the
HAVING clause works on groups. Expressions in the HAVING clause must be single-
valued per group.
Some Advanced Features of SQL
Treatment of NULL
NULL signifies unknown or missing information. No value can be said to be equal to
NULL. For example, the following statement is not correct.
SELECT *
FROM product
WHERE price = NULL
3A.18
Relational Database Desi
g
n
SQL provides a clause IS NULL (or IS NOT NULL) for finding a null value. Therefore,

the above statement can be changed as:
SELECT *
FROM product
WHERE price IS NULL
The result of this query is:
PROD-NO MODEL DESC PRICE CITY
P8925 BlackT Television NULL Dallas
Query Result
Subqueries
A query within a query is called a subquery. For example, if you want the names of
the customers who buy the product P5690, the query would be:
SELECT name
FROM customer
WHERE cust-no IN
(SELECT cust-no
FROM sale
WHERE prod-no = “P5690”)
First, the subquery that is given in parentheses is evaluated. All the values of the cust-
no for which the prod-no is P5690 are retrieved from the sale table. A subset is
returned. Then, the higher level query is evaluated. All the names of the customers
are retrieved from the customer table for the values in the subset.
The IN clause works on a set of values. If the set has only one value, then IN will be
equivalent to “=”.
The result of the above query is the same as the result of the following join:
SELECT name
FROM customer, sale
WHERE customer.cust-no = sale.cust-no
AND sale.prod-no = “P5690”
Thus, there are two forms for the same query. One form involves a subquery and the
other involves a join. This is true for most of the queries.

You can nest subqueries to any depth. For example, if you want the names of the
customers who have bought a television of any model, the query would be:
SELECT name
FROM customer
WHERE cust-no IN
3A.19 Relational Database Desi
g
n
(SELECT cust-no
FROM sale
WHERE prod-no IN
(SELECT prod-no
FROM product
WHERE desc = “television”))
Query Involving UNION
The UNION operator of relational algebra is represented by the UNION clause in SQL.
For example, if you want the codes of all products that are refrigerators or have been
bought by customer C4171, the query would be:
SELECT prod-no
FROM product
WHERE desc = “refrigerator”
UNION
SELECT prod-no
FROM sale
WHERE cust-no = “C4171”
The result of the above query is a union of the two sets that have been defined. One
set is the set of refrigerators and the other set is the set of products bought by
customer C4171.
You have looked at all the clauses used with the SELECT statement. The complete
syntax of the SELECT statement is:

SELECT [DISTINCT] item(s)
FROM table(s)
[WHERE condition]
[GROUP BY field(s)]
[HAVING condition]
[ORDER BY field(s)]
The INSERT Statement
After creating a table, you can enter data in it by using the INSERT statement. The
INSERT statement can also be used to insert a new row in an existing table. For
example, if you want to insert a row in the product table, the SQL statement would
be:
INSERT INTO product (prod-no, name, desc, price)
VALUES (“P9980”, “Armstrong”, “VCR”, 12900)
This statement adds a new row in the product table with the values P9980, Armstrong,
VCR, and 12990 in the prod-no, name, desc, and price columns respectively.
3A.20
Relational Database Desi
g
n
The UPDATE Statement
SQL provides the UPDATE statement for updating data. For example, if you want to
change the price of product number P4721 to $900, the SQL statement is:
UPDATE product
SET price = 900
WHERE prod-no = “P4721”
If more than one row satisfies the WHERE clause, the price is set to $900 in all those
rows. If you omit the WHERE clause, all the rows in the product table will be updated
with $900 as the new price.
The DELETE Statement
SQL provides the DELETE statement to delete a row. For example, if you want to

delete the rows of all customers who are based in New York, the SQL statement is:
DELETE
FROM customer
WHERE city = “New York”
3A.21 Relational Database Desi
g
n
Views
Physical Database Design Lesson 9 / Slide 8 of 13©NIIT
Physical Database Design
Views

A view is a named, derived, virtual table that does not exist
physically.

The tables that are the source of the data visible through the view
are referred to as source tables.

Views are defined by using the SQL statement CREATE VIEW.

When a user makes a reference to a view, the DBMS finds the
definition of the view stored in the database. The DBMS then
translates the user’s request into an equivalent request against the
source tables of the view. In this way, the DBMS maintains the
illusion of the view.

Views can be theoretically updatable or non-updatable.
A view is a named, derived, virtual table that does not exist physically. This is unlike a
base table that is a real table and exists in physical storage. You can consider a view
as a SQL query that is permanently stored in the database and assigned a name.

However, for the user, accessing a view is like accessing a base table. The DBMS
creates an illusion of a table by assigning a name to the view and storing its definition
in the database. The tables that are the source of the data visible through the view
are referred to as source tables. The following figure shows two source tables and a
view created by using these tables.
Employee Table
EMP-CODE NAME DEPT BASIC AGE
1001 Ronald
Billing
T1008 1500 23
1004 Nancy Jones T1019 2000 24
1079 Mary
Pt
T1042 5000 29
3A.22
Relational Database Desi
g
n
EMP-CODE NAME DEPT BASIC AGE
Peterson
1088 Mike
Womack
T1042 2900 25
1172 Larry
Williams
T1008 1900 22
Department Table
DEPT-CD DEPT-NAME DEPT-HEAD BUDGET
T1008 Personnel Steve
Irving

160000
T1019 Marketing Chris
Donaldson
700000
T1042 Finance Christine
Jones
414000
Name-Dept View
NAME DEPARTMENT AGE
Ronald
Billing
Personnel 23
Nancy
Jones
Marketing 24
Mary
Peterson
Finance 29
Mike
Womack
Finance 25
View with Two Source Tables
Defining a View
Views are defined by using the SQL statement CREATE VIEW. For example, the
following statement creates the name-dept view shown in the above figure.
3A.23 Relational Database Desi
g
n
CREATE VIEW name-dept (name, department, age)
AS SELECT name, dept-name, age

FROM employee, department
WHERE employee.dept = department.dept-cd
The data in the name-dept view comes from the employee and department tables.
Hence, these two tables are the source tables for the view.
When the CREATE VIEW statement is executed, the query following the AS clause is
not executed. Instead, it is simply saved in the catalog. To the user it appears as
though there is a real table called name-dept with rows and columns. In fact, name-
dept is a “window” into the real tables, employee and department. Any changes you
make to these tables will be visible through the name-dept view.
If the names of the columns are not specified while defining a view, the view inherits
the columns of its source tables. However, sometimes, it is necessary to specify the
column names. For example, in the following statement, there can be no name
inherited for the second column. This is because the column is derived from a
function. Therefore, the column name must be explicitly specified.
CREATE VIEW db (dept, avgbasic)
AS SELECT dept, AVG (basic)
FROM employee
GROUP BY dept
Once you define a view, you can use it in a SELECT statement like a real table. For
example,
SELECT name
FROM name-dept
WHERE age > 24
The result of this query is:
NAME DEPARTMENT AGE
Mary
Peterson
Finance 29
Mike
Womack

Finance 25
Query Result
The name of the view comes with the FROM clause like a table name. The columns of
the view are also referenced like the columns of a table.
3A.24
Relational Database Desi
g
n
How Does the DBMS Handle Views?
When a user makes a reference to a view, the DBMS finds the definition of the view
stored in the database. The DBMS then translates the user’s request into an
equivalent request against the source tables of the view. In this way, the DBMS
maintains the illusion of the view. For example, the query:
SELECT name
FROM name-dept
WHERE age > 24
is translated by the DBMS into:
SELECT name
FROM employee
WHERE age > 24
The DBMS translates the query against the view name-dept into one against the
source table employee.
For more complex views, the DBMS has to actually materialize the view. This means
that the DBMS executes the query and stores its result in a temporary table. Then, the
DBMS carries out the user’s request for view access from this temporary table. This
temporary table is removed when it is no longer needed. However, all this is the
internal working of the DBMS and is
transparent to the user. One disadvantage is that
it slows down the processing.
I

I
N
N
S
S
T
T
R
R
U
U
C
C
T
T
O
O
R
R
N
N
O
O
T
T
E
E
S
S
Language Support for the Relational Model

You can ask the following question to test whether the students understand the DDL
statements used to manage tables:
1. What will be the statement to add a column, designation, to a table,
employee?
2. What will be the statement to delete a table named product?
Solutions:
1. ALTER TABLE employee ADD designation CHAR(20)
3A.25 Relational Database Desi
g
n
2. DROP TABLE product
You can give the following additional information while explaining the SELECT
statement:
SQL includes a string-matching operator using which you can compare character
strings. Two special characters are used to describe different character patterns.
Percent (%) – This character matches a substring.
Underscore (_) – This character matches any character.
For example,
“Main%” matches any string that starts with “Main”.
“%ig%” matches any string that contains “ig” as a substring. For example,
“Highway”.

“_ _ _” matches any string containing exactly 3 characters.

“_ _ _%” matches any string of 3 or more characters.
You can express patterns in SQL by using the LIKE comparison operator. For example,
the following SQL statement finds the names of all employees whose location includes
the substring “or”.
SELECT emp-name
FROM employee

WHERE city LIKE “%or%”
You can ask the following questions to the students to check their understanding of
the SELECT statement:
1. What will be the SQL statement to find the number of rows in the employee
table?
2. What will be the SQL statement to display the names of customers from the
customer table after eliminating duplicate names?
Solutions:
1. SELECT COUNT (*)
FROM employee
2. SELECT DISTINCT cust-name
FROM customer

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×