Presentation is loading. Please wait.

Presentation is loading. Please wait.

April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 1 Database Design SQL (2) John Wordsworth Department of Computer Science The University.

Similar presentations


Presentation on theme: "April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 1 Database Design SQL (2) John Wordsworth Department of Computer Science The University."— Presentation transcript:

1 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 1 Database Design SQL (2) John Wordsworth Department of Computer Science The University of Reading J.B.Wordsworth@rdg.ac.uk Room 129, Ext 6544

2 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 2 Lecture objectives Use SQL with nested queries. Use SQL to create joins, unions, intersections, and differences. Use SQL to add new rows to a table, delete existing rows from a table, and update existing rows in a table.

3 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 3 Book A new Book table

4 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 4 Borrower The Borrower table

5 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 5 SELECT with a nested query SELECT BTitle, BAuthor FROM Book WHERE WNum IN (SELECT WNum FROM Borrower WHERE WNum > “40” AND WNum < “60” )

6 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 6 SELECT for an outer join SELECT BTitle, WName FROM Book LEFT JOIN Borrower ON Book.WNum = Borrower.WNum

7 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 7 SELECT with UNION (SELECT BTitle, BAuthor FROM Book WHERE BDewey IS NULL ) UNION (SELECT BTitle, BAuthor FROM Book WHERE WNum IS NULL)

8 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 8 SELECT with INTERSECTION (SELECT BTitle, BAuthor FROM Book WHERE BDewey IS NULL ) INTERSECTION (SELECT BTitle, BAuthor FROM Book WHERE WNum IS NULL)

9 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 9 SELECT with EXCEPT (SELECT BTitle, BAuthor FROM Book WHERE BDewey IS NULL ) EXCEPT (SELECT BTitle, BAuthor FROM Book WHERE WNum IS NULL)

10 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 10 INSERT Syntax INSERT INTO table_name | (column_list) { VALUES (data_value_list) | select-expression } ;

11 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 11 Adding a row to the Book table INSERT INTO Book VALUES (’23’, ‘The Sorrows of Satan’, NULL, NULL, ‘Corelli’) ; Beware of: key violations data conversion errors

12 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 12 UPDATE Syntax UPDATE Book SET WNum = ’33’ WHERE BNum = ’23’ ; UPDATE table_name SET column_name = data_value [WHERE search_condition] ;

13 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 13 DELETE Syntax DELETE FROM Book ; DELETE FROM table_name [WHERE search_condition] ; DELETE FROM Book WHERE BNum = ’23’ ;

14 April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 14 Key points The SELECT statement can be used to form joins, unions, intersections, and differences. The INSERT statement adds new rows to a table. The DELETE statement removes existing rows from a table. The UPDATE statement updates existing rows in a table.


Download ppt "April 2002Information Systems Design John Ogden & John Wordsworth SQL2: 1 Database Design SQL (2) John Wordsworth Department of Computer Science The University."

Similar presentations


Ads by Google