Kroenke Dbc6e PP Ch03
Kroenke Dbc6e PP Ch03
AUER
DATABASE CONCEPTS, 6th Edition
Chapter Three
Structured Query Language
All rights reserved. No part of this publication may be reproduced, stored
in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, photocopying, recording, or otherwise, without
the prior written permission of the publisher. Printed in the United States
of America.
Table 3-8:
Processing the CREATE TABLE Statements Using SQL Server 2012
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall 3-12
Process SQL CREATE TABLE Statements:
Oracle Database 11g Release 2
Figure 3-10:
Processing the CREATE TABLE Statements Using MySQL 5.5
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall 3-14
Database Diagram in the
Microsoft SQL Server Management Studio
Figure 3-11:
Database Diagram in the Microsoft SQL Server Management Studio
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall 3-15
Primary Key Constraint:
ALTER I
• Adding primary key constraints to
an existing table
– The SQL ALTER statement
SELECT *
FROM EMPLOYEE;
SELECT EmpName
FROM EMPLOYEE
WHERE DeptID = 15;
Figure 3-13:
SQL Query Results in the Microsoft SQL Server Management Studio
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall 3-25
Processing SQL Query Statements:
Oracle Database 11g Release 2
SELECT EmpName
FROM EMPLOYEE
WHERE DeptID = 9
AND SalaryCode <= 23;
SELECT EmpName
FROM EMPLOYEE
WHERE DeptID IN (4, 8, 9);
SELECT EmpName
FROM EMPLOYEE
WHERE SalaryCode BETWEEN 10 AND 45;
SELECT EmpID
FROM EMPLOYEE
WHERE EmpName LIKE 'Kr%';
SELECT EmpID
FROM EMPLOYEE
WHERE Phone LIKE '616-___-____';
SELECT *
FROM EMPLOYEE
ORDER BY EmpName;
SELECT COUNT(DeptID)
FROM EMPLOYEE;
• Subqueries
– As stated earlier, the result of a query is a
relation. As a result, a query may feed
another query. This is called a subquery.
• Joins
– Another way of combining data is by using a
join .
• Join [also called an Inner Join]
• Left Outer Join
• Right Outer Join
SELECT EmpName
FROM EMPLOYEE AS E, DEPARTMENT AS D
WHERE E.DeptID = D.DeptID
AND D.DeptName LIKE 'Account%';
UPDATE EMPLOYEE
SET DeptID = 44
WHERE EmpName LIKE 'Kr%';