0% found this document useful (0 votes)
23 views20 pages

Week 4 Practical Activity 1

Uploaded by

Andrew Light
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views20 pages

Week 4 Practical Activity 1

Uploaded by

Andrew Light
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 20

Lab 4: Creating Tables & Modifying Data in Tables

Restricting Rows and Sorting Data


Lab Overview

Goals  Extract the desired subset of data from a table and present in
a given order.
General tasks  SELECT rows using basic syntax structure, including WHERE
clause and ORDER BY clause.
 Use comparison operators with the search condition.
 Use logical operators AND, OR, and NOT to query data.
 Use LIKE for pattern matching, BETWEEN for range filtering,
and IN for list filtering.

Sometimes you will want to see only records meeting certain conditions, which is a
process known as selection. In addition if the data is displayed in a sorted order, then
the output will be easier to read. The SELECT statement includes a WHERE clause that
is used to specify a search condition and also an ORDER BY clause that is used to
display results in a specific sequence. Both the WHERE clause and the ORDER BY
clause are optional as shown in the SELECT statement syntax below:

SELECT [DISTINCT] (*, columnname [ AS alias], …)


FROM tablename
[WHERE condition]
[GROUP BY group_by_expression]
[HAVING group_condition]
[ORDER BY columnname];

A WHERE clause identifies a condition or requirement that must be met for a record to
be included in the results. For example, to display a list containing the last name of
every customer living in NSW, you use the SQL statement shown below:

SELECT lastname, state


FROM customers
WHERE state = 'NSW';

In the WHERE clause, WHERE is the keyword, state is the name of the column to be
searched, the comparison operator “equal to” (=) means the record must contain the
exact value specified, and that is NSW. Note also the single quotation marks around
NSW, which designate it as a string literal. Also the value NSW is in uppercase letters to
match the format in which data is entered in the State field.

Rules for Character Strings


When using a string literal, such as NSW, as part of a search condition, the value must
be enclosed in single quotation marks and, as a result, is interpreted exactly as listed.
However, if the field being referenced in a condition consists only of numbers, then
quotation marks are not required. For example, supposing you want to list all details for
customer 1010. The customer_Id field has a numeric data type, which means that
quotation marks are not required in the following example:
 Copyright 2010 One-To-One Computer Services Pty. Ltd 1
SELECT *
FROM customers
WHERE customer_Id = 1010;

Check the data type of the table by using the Object List browser (Alt+3). It the field is
not numeric, for example VARCHAR2, then single quotation marks will be required for
the search condition.

Rules for Dates


When you include a date as a search condition, then the date must be treated as a string
and enclosed in single quotation marks. For example:

SELECT *
FROM books
WHERE pubdate = '21-JAN-2011';

Comparison Operators

Operator Description
= Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> , != Not equal to
LIKE Used for pattern matching
BETWEEN Used for range filtering
IN Used for list filtering
IS NULL Used when testing for NULL values
Table 1: SQL Comparison Operators

SQL has a set of comparison operators shown in Table 1: SQL Comparison


OperatorsThese are usually used when specifying conditions using the WHERE clause.
A comparison operator indicates how data should relate to the search value, such as
“greater than” or “less than”. For example, to find which books meet the “more than
$55.00” requirement:

SELECT title, retail


FROM books
WHERE retail > 55;

Note that a dollar sign is not included. The dollar sign is treated as a formatting
character, so $55 is not equivalent to 55.

 Copyright 2010 One-To-One Computer Services Pty. Ltd 2


The “greater than” and “less than” comparison operators can also be used with text and
date fields, as shown by the following example that will list all books with a title occurring
alphabetically after the letters HO.

SELECT title
FROM books
WHERE title > 'HO';

You can also use arithmetic expressions in the WHERE clause as shown by the
following example that lists all books having a profit of less than 20% of the book’s cost.

SELECT title, retail-cost profit


FROM books
WHERE retail-cost < cost * 0.2;

The following example uses the “not equal to” comparison operator to list customers who
do not live in NSW:

SELECT firstname, lastname, state


FROM customers
WHERE state <> 'NSW';

The following example lists all orders place before July 2011:

SELECT order_no, order_date


FROM orders
WHERE order_date < '01-JUL-11';

BETWEEN ... AND Operator


The BETWEEN .. AND comparison operator is used when searching for a field with
values within a specified range.

The syntax of the BETWEEN operator is as follows:

SELECT Column1, Column2...ColumnN


FROM TableName
WHERE ColumnName BETWEEN value1 AND value2;

The following example shows use of the BETWEEN conditional operator to match items
where the salary is between 2000 and 3000:

SELECT ENAME, SAL


FROM tblEMP
WHERE SAL BETWEEN 2000 AND 3000;

The following statement lists all books published between 1-JAN-10 and 31-DEC-10:

SELECT title, pubdate


FROM books
WHERE pubdate BETWEEN '1-JAN-10' AND '31-DEC-10'

The range is inclusive of the dates specified.

 Copyright 2010 One-To-One Computer Services Pty. Ltd 3


Note that for MySQL that dates need to be specified as YYYY-MM-DD format. For
example, '2010-01-10'

The next example shows how an alphabetical list of book titles can be returned with the
BETWEEN ... operator:

SELECT title
FROM books
WHERE title BETWEEN 'A' AND 'D';

IN Operator

The IN operator returns records matching one of the values listed in the condition. The
list must be separated by commas and the entire list enclosed in parenthesis.

The syntax of the IN operator is as follows:

SELECT Column1, Column2...ColumnN


FROM TableName
WHERE ColumnName IN('value1', 'value2', 'value3'...);

The following example shows use of the IN conditional operator to match items within a
given list:

SELECT ename, sal, comm


FROM tblEMP
WHERE ename IN('ALLEN', 'WARD', 'MARTIN', 'TURNER');

The next example returns books published by Publisher 1, 2 or 5.

SELECT title, pub_Id


FROM books
WHERE pub_Id IN(1, 2, 5);

The following example lists all customers located in NSW or VIC. State names are
delimited in single quotation marks because they are string literals.

SELECT firstname, lastname, state


FROM customers
WHERE state IN('NSW', 'VIC');

The logic can be reversed by using NOT operator with the comparison operators. For
example, if you want all customers in states other than NSW or VIC, then add NOT to
the query as shown below:

SELECT firstname, lastname, state


FROM customers
WHERE state NOT IN('NSW', 'VIC');

 Copyright 2010 One-To-One Computer Services Pty. Ltd 4


LIKE Operator
The LIKE operator is unique, in that it is used with wildcard characters to search for
patterns. Wildcard characters are used to represent one or more alphanumeric
characters. The wildcard characters available for pattern searches in Oracle are the
percent sign (%) and the underscore symbol (_). The percent sign represents any
number of characters (zero, one, or more), and the underscore character exactly one
character at a specified position in the string. The following example lists customers
where the name begins with the letter p:

Like only works with character strings, not numeric values or datetimes.

SELECT lastname
FROM customers
WHERE lastname LIKE 'P%';

A like condition can be negated by using NOT LIKE as shown by the following example:

SELECT lastname
FROM customers
WHERE lastname NOT LIKE 'P%';

The following example lists customers with a four character lastname ending in RD:

SELECT lastname, firstname


FROM customers
WHERE lastname LIKE '__RD';

This query could return FORD, WARD, etc.

The following example searches with the LIKE operator and a combination of wildcard
characters to return as list of books where the ISBN starts with any character, the
second character is the number 4, followed by any characters, and ending with a zero.

SELECT isbn, title


FROM books
WHERE isbn LIKE '_4%0';

 Copyright 2010 One-To-One Computer Services Pty. Ltd 5


More Examples Using Wildcards and the Like Comparison
Operator
The following examples in Table 2: Examples of wildcard operator patterns illustrate use
of the wildcard operators.

Wildcard Operator Pattern Description


'A%' Matches a string value that begins with A. Returns could
include for example, A, AC/DC, Aardvark
'%S' Matches a string value that ends with an S. Returns
could include for example, S, The Birds, SOS
'%LE%' Matches a string value that contains LE anywhere in the
string. Returns could include for example, LEADER,
RELEASED, SALE
'____ ' Matches any four character string value. Examples of
returns could include: ABCD, ABBA, SOLD
'FR__ ' Matches any four character string beginning with the
letters FR. Examples may include: FRMP, FRED, FREE
'_re%' Matches a string value that begins with any character
and has re as the second and third characters. Returns
may include, for example, Area, Free, Press
Table 2: Examples of wildcard operator patterns

For example, using LIKE in conjunction with wildcards and OR:

SELECT ENAME, JOB


FROM tblEMP
WHERE ENAME LIKE '__ RD' OR ENAME LIKE '%LL%';

Returns the following:


ENAME JOB
ALLEN SALESMAN
WARD SALESMAN
FORD ANALYST
MILLER CLERK

Searching for Strings that Contain the Percent Sign (%)


If you want to search for text that includes a % sign, then it is necessary to use the
ESCAPE keyword to specify an escape character. By immediately preceding a wildcard
character with an escape character, you can strip the wildcard of its special meaning.
The exclamation mark (!) is often designated as an escape character in SQL statements.

For example: the following SQL statement returns incidents of 50% from the named
column:

SELECT Column1, Column2…ColumnN


FROM TableName
WHERE ColumnName LIKE '50!%%' ESCAPE '!';

 Copyright 2010 One-To-One Computer Services Pty. Ltd 6


Logical Operators

Logical operators are used when you need to search for records based on two or more
conditions. The logical operators AND and OR are used to combine search conditions.
The NOT operator is used to reverse the logic of the search conditions.

When more than one operator is used in a statement, the order of precedence is:
NOT
AND
OR

The syntax when using AND, OR, & NOT is as follows:

SELECT Column1, Column2…ColumnN


FROM TableName
WHERE ColumnName = SomeValue
AND / OR ColumnName = SomeValue;

An example using OR to include an additional second condition in the SQL statement:

SELECT ENAME, JOB


FROM tblEMP
WHERE JOB = 'MANAGER' OR JOB = 'PRESIDENT';

An example using NOT to negate a condition:

SELECT ename, job


FROM tblEMP
WHERE NOT ename = 'KING';

The following example lists books published by Publisher Id = 3 and books in the
COMPUTER Category (Only books matching both conditions will be listed):

SELECT title, pub_Id, category


FROM books
WHERE pub_Id = 3 AND category = 'COMPUTER'

Whereas, the following example lists all books that are published by Publisher Id = 3 or
books in the COMPUTER Category (Books matching one or the other search condition
will be listed):

SELECT title, pub_Id, category


FROM books
WHERE pub_Id = 3 OR category = 'COMPUTER'

The following example uses both AND and OR in the WHERE clause:

SELECT *
FROM books
WHERE category = 'COMPUTER' OR pub_Id = 4
AND cost > 15;

 Copyright 2010 One-To-One Computer Services Pty. Ltd 7


In the example on the previous page, Oracle first evaluates the pub_Id and cost
conditions combined with the AND operator. After this operation is complete, then
category condition preceding the OR logical operator is evaluated.

If you want to find any book costing more than $15.00 that is published by Publisher 4 or
is in the COMPUTER category, then you must use parenthesis to identify any books
published by Publisher 4 or COMPUTER category first. After books meeting the
Category or Publisher condition are found, then the cost condition is evaluated, and only
those records with a cost higher than $15.00 are displayed. The following query will
return different results to the example shown previously:

SELECT *
FROM books
WHERE (category = 'COMPUTER' OR pub_Id = 4)
AND cost > 15;

Note that it is best not to rely on the evaluation order when mixing AND and OR. It
is recommended that you use parentheses to control the order and to make it
more explicit.

Treatment of NULL Values

When you are performing arithmetic operations or search conditions, NULL values can
cause unexpected results. A NULL value means no value has been stored, that is, a
NULL is the absence of data in a field. Consequently, when searching for NULL values,
you cannot use the equal sign (=) because there is no value to use for comparison in the
search condition. When checking for NULL values, you are actually checking the status
of the column; does data exist or not? If you need to identify records that have NULL
value, you must use the IS NULL comparison operator.

For example, when an order is shipped to a customer, the shipping date is entered in the
Orders table. If a date does not appear in the ship_date field, then the order has not
been shipped yet. The following example will display all orders that do not have a
ship_date:

SELECT order_no, ship_date


FROM orders
WHERE ship_date IS NULL;

When searching for orders that have shipped (that is, the ship_date column contains an
entry), then simply add the logical operator NOT. The following example returns orders
which have a ship_date:

SELECT order_no, ship_date


FROM orders
WHERE ship_date IS NOT NULL;

 Copyright 2010 One-To-One Computer Services Pty. Ltd 8


ORDER BY Clause Syntax

When you enter a SELECT statement the order of rows is not defined. You may want to
see the rows in a specific order based on a column or columns. It is not necessary to
display a sort column in the result of the SELECT statement.

The ORDER BY clause, used to display query results in a sorted order, is listed at the
end of the SELECT statement, as shown below:

SELECT [DISTINCT] (*, columnname [ AS alias], …)


FROM tablename
[WHERE condition]
[GROUP BY group_by_expression]
[HAVING group_condition]
[ORDER BY columnname [ASC/DESC]];
.
The rows can be sorted in ascending or descending order. The rows can be sorted on
one or more columns. For example, to list all publishers sorted by the Name field:

SELECT *
FROM publisher
ORDER BY name;

In the syntax ASC stands for ascending order. The default order is ascending, so there
is no need to type ASC for ascending order. The keyword DESC stands for descending
or reverse order.

When sorting in ascending order, numeric values are displayed from the smallest to the
largest value, character values are displayed in alphabetical order, and date values are
displayed with the earliest date first. The NULL values are displayed last in ascending
order. In descending order, the effect is reversed for all data types and NULL values are
displayed at the top in descending order.

The following example sorts the list of publishers in descending order by the publisher
name:

SELECT *
FROM publisher
ORDER BY name DESC;

If a column alias is given to a field in the SELECT statement, you can reference the field
in the ORDER BY clause with the column alias, as shown by the following example:

SELECT pub_Id, name "Publisher Name", phone


FROM publisher
ORDER BY "Publisher Name";

You can also use the ORDER BY clause with the optional NULLS FIRST or NULLS
LAST keywords to change the order for listing NULL values. By default NULL values are
listed last when results are sorted in ascending order and first when sorted in
descending order. The following example lists the last and first name of each customer
from NSW and the customer number of the person who referred the customer. The

 Copyright 2010 One-To-One Computer Services Pty. Ltd 9


results are sorted in ascending order by the Referred column. Records without a value
in the referred column will appear first.

SELECT lastname, firstname, state, referred


FROM customers
WHERE state = 'NSW '
ORDER BY referred NULLS FIRST;

Secondary Sort

Secondary sort allows you to specify a second field to sort by if an exact match occurs
between two or more rows in the primary sort. For example, when listing customers the
following example sorts first by the state and then sub sorts by the city name:

SELECT lastname, firstname, state, city


FROM customers
ORDER BY state, city;

The following example sorts orders by shipping date in descending order so that the
most recent will appear first and a secondary sort by order number:

SELECT order_no, ship_date


FROM orders
WHERE ship_date IS NOT NULL
ORDER by ship_date DESC, order_no;

Oracle also provides an abbreviated method for referencing the sort column if the
column name is used in the SELECT clause. The following example will produce the
same result as the previous one above.

SELECT order_no, ship_date


FROM orders
WHERE ship_date IS NOT NULL
ORDER by 1 DESC, 2;

The following is another example of the abbreviated sort method:

SELECT lastname, firstname, state, city


FROM customers
WHERE state IN('NSW ', 'VIC ')
ORDER BY 3 DESC, 4;

This will sort first by the state name in descending order and then by the city name. It is
generally better to specify the column names used with the ORDER BY clause.

See PSOUG.org http://psoug.org/reference/orderby.html for more detail on using


ORDER BY.

Exercise Overview

 Copyright 2010 One-To-One Computer Services Pty. Ltd 10


Goals  Create a table.
 Insert, update, and delete data in database tables.
General tasks  Create a table.
 Insert data into tables.
 Update data in tables.
 Delete data from tables.

Detailed Instructions

You are going to use MySQL to create a new database called books for this lab.

1. Start MySQL.exe from the command prompt.


a. Start, Program Files, Accessories, Command Prompt.
b. Change to USB drive (e.g. Type e: and press Enter).
c. Type cd\xampp\mysql\bin and press Enter.
d. Type mysql –u root and press Enter
2. Type create database books; and press [Enter].
3. Type use books; to your new books database.
4. Save the script books.sql onto your USB flash drive.
5. Type source e:\lab4\books.sql; to run the script books.sql
Change the path to match the folder where books.sql is located.
6. Start phpMyAdmin, select the books database and examine the tables in the
database.
7. Go back to MySQL and then type help create table; to view the syntax for the
create table command.
8. Create a table:
a. Name the table publishers.
b. Create columns that match the following descriptions:

Name Datatype Properties Sample Data


n_pub_id Integer - disallow NULLs 1
- auto-increment
- primary key
pub_id Char(4) -disallow nulls 1389
pub_name Strings of up to 40 Allow NULLs AllGoData
characters InfoSystems
city Strings of up to 20 Allow NULLs Sydney
characters
state Strings of up to 3 Allow NULLs NSW
characters
Hint:
CREATE TABLE publishers(
n_pub_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
pub_id CHAR(4) NULL ,
pub_name VARCHAR(40) NULL,
city VARCHAR(20) NULL ,
state VARCHAR(3) NULL
)Engine= InnoDB;
9. Enter the sample data shown above as the first record in the publishers table.
10. Type Insert into publishers values(NULL, '1756', 'Kroton Printings',
'Sydney', 'NSW');
to insert the following publisher (Note you need to use two single quotes or
NULL where there is no value to be inserted.):
 Copyright 2010 One-To-One Computer Services Pty. Ltd 11
 Kroton Printings
 ID: 1756
 City: Sydney
 State: NSW

11. Type Insert into publishers values(NULL,'9993', 'Land of Fiction',


'Melbourne', 'Vic');
to insert the following publisher:
 Land of Fiction
 ID: 9993
 City: Melbourne
 State: Vic
12. Type Insert into publishers (pub_id, pub_name)
VALUES(1000, 'Cengage');
to insert the following publisher:
 Cengage
 ID: 1000
Note that the insert statement specifies the fields that you are inserting values
into. This is a preferred way of inserting records.
13. Type select * from publishers;
to select all data from publishers to verify the inserts.
14. Type CREATE TABLE publishers_bak LIKE publishers;
to create a copy of your publishers table.
15. Type INSERT INTO publishers_bak SELECT * FROM publishers;
to copy the data from the original table into the copy
16. Type RENAME TABLE publishers_bak TO publishers_copy;
to rename the publishers_bak table as publishers_copy
17. Type
delete from publishers
where city = 'Sydney'
to delete all rows from publishers in Sydney.
18. Select all data from publishers to verify the deletes.
19. Type TRUNCATE publishers_copy;
to delete all rows from publishers_copy
20. Select all data from publishers_copy to verify the deletes.
21. Type DROP TABLE publishers_copy;
to delete the table publishers_copy
22. List the title and price of all Oracle Server books greater than $50.
SELECT title, price
FROM books
WHERE category = 'Oracle Server'
AND price >50;
23. Update the price by 12% of all Oracle Server books that are more than 1000
pages in length (Hint: Multiply by 1.12)
UPDATE books
SET price = price * 1.12
WHERE category = 'Oracle Server'
AND num_pages >1000;

24. List the type and price of all Oracle Server books over 1000 pages to verify the
update.
SELECT title, price
FROM books
WHERE category = 'Oracle Server'
 Copyright 2010 One-To-One Computer Services Pty. Ltd 12
AND num_pages >1000;

 Copyright 2010 One-To-One Computer Services Pty. Ltd 13


 Copyright 2010 One-To-One Computer Services Pty. Ltd 14
25. Switch to your DreamHome database.
Use dreamhouse;
26. List all registration records where the client joined on or before 7-Mar-2003..
SELECT * FROM Registration WHERE dateJoined <= '2003-03-07';
27. List all properties for rent where the property type is Flat.
SELECT * FROM PropertyForRent WHERE type = 'flat';
28. List all properties for rent where the property type is not Flat.
SELECT * FROM PropertyForRent WHERE type <> 'flat';
29. List all properties for rent where the rent is between 300 and 500 dollars.
SELECT * FROM PropertyForRent WHERE rent between 300 AND 500;
30. List all properties for rent where the property is in Aberdeen or London.
SELECT * FROM PropertyForRent WHERE city = 'Aberdeen' or city =
'London';

- or-

SELECT * FROM PropertyForRent WHERE city IN( 'Aberdeen' , 'London');

The IN operator is easier to use when you need to match a number of values in a
list.
31. List all properties for rent where the property is not in Aberdeen or London.
SELECT * FROM PropertyForRent WHERE city NOT IN( 'Aberdeen' ,
'London');
 Copyright 2010 One-To-One Computer Services Pty. Ltd 15
32. List all properties for rent where the property is not in Aberdeen or London and
the type is not a flat.
SELECT * FROM PropertyForRent WHERE city NOT IN( 'Aberdeen' ,
'London') AND type NOT IN( 'Flat');
33. List all properties for rent where the property is situated in a road.
SELECT * FROM PropertyForRent WHERE street LIKE '%rd%' ;
34. List all properties for rent where the property is is situated in a road or a street.
SELECT * FROM PropertyForRent WHERE street LIKE '%rd%' OR street
LIKE '%st%';
35. List all staff where the position is either Manager or Supervisor.
SELECT * FROM staff WHERE position ='manager' OR position =
'supervisor';
36. List all staff where the position is NOT Manager.
SELECT * FROM staff WHERE NOT position ='manager';
37. List all properties for staff where the sex is male and the branch is B003.
SELECT * FROM staff WHERE sex ='m' AND branchNo = 'B003';

38. List all staff where the sex is male and the position is manager or the sex is male
and the position is supervisor.
SELECT * FROM staff WHERE sex ='m' AND position = 'manager' OR sex
='m' AND position = 'supervisor';
39. List all staff where the salary is greater than or equal to 18000 and the branchNo
is B003, or staff located at branchNo B005 irrespective of salary.
SELECT * FROM staff WHERE salary >= 18000 AND branchNo = 'B003' OR
branchNo = 'B005';
40. List all staff where the branchNo is B003 or branchNo is B005 and the salary is
greater than or equal to 18000. Note how the parenthesis changes the result.
SELECT * FROM staff WHERE salary >= 18000 AND (branchNo = 'B003' OR
branchNo = 'B005');
41. List all records from the viewing table where no comment has been entered.
SELECT * FROM viewing WHERE comments IS NULL;
42. List all records from the viewing table where a comment has been entered.
SELECT * FROM viewing WHERE comments IS NOT NULL;
43. List all staff located at branchNo B003 and records ordered by last name and
then first name.
SELECT * FROM staff WHERE branchNo = 'B003' ORDER BY lName, fName;
44. List all staff located at branchNo B003 and records ordered by salary in
descending (highest to lowest) sort order.
SELECT * FROM staff WHERE branchNo = 'B003' ORDER BY salary DESC;
45. List all staff located records ordered by branchNo in ascending order (a to z) and
sub sorted in order of salary in descending (highest to lowest) sort order.
SELECT * FROM staff ORDER BY branchNo, salary DESC;
46. List all staff located records ordered by the second column specified (lName) and
sub sorted in order of the first column specified (fName).
SELECT fName, lName FROM staff ORDER BY 2, 1;

Try these on your own:


 Copyright 2010 One-To-One Computer Services Pty. Ltd 16
47. Write the SQL to produce a list of salaries for staff, showing only the staff
number, the first and last names, and the salary details. Sort the output in order
of the staff last name, and then first name.
48. Write the SQL to list the name of each manager at each branch, ordered by
salary in descending order.

 Copyright 2010 One-To-One Computer Services Pty. Ltd 17


 Copyright 2010 One-To-One Computer Services Pty. Ltd 18
 Copyright 2010 One-To-One Computer Services Pty. Ltd 19
49. Write the SQL to create a Rental table for your Dream House database which
has the following design:
clientNo CHAR(4)
propertyNo CHAR(4)
rentStart DATE
rentFinish DATE
rent DOUBLE(12,4)
comment VARCHAR(255)
FOREIGN KEY (propertyNo) REFERENCES PropertyForRent(propertyNo)
FOREIGN KEY (clientNo) REFERENCES Client(clientNo)
50. Add the following data to the Rental table:

clientNo propertyNo rentStart rentFinish rent comment


CR76 PG4 1-Jul-03 31-Aug-04 350
CR76 PG16 1-Sep-04 1-Sep-05 455
CR56 PG4 10-Sep-02 10-Jun-03 325 Owner
agreed to
reduce rent
by $25
CR56 PG36 10-Oct-03 1-Dec-04 375
CR56 PG16 1-Nov-03 10-Aug-06 450
CR74 PG36 21-Dec-04 21-Dec-06 400

Note that you should get an error when you try to insert records with
propertyNo PG16. Try to work out why the error occurs or why the record
is not inserted. You will have to modify something in order to insert the
record. Hint: Check the propertyNo values in the PropertyForRent table.

 Copyright 2010 One-To-One Computer Services Pty. Ltd 20

You might also like