Sql Book

In: Computers and Technology

Submitted By yamilettebonet
Words 48772
Pages 196
A GUIDE TO SQL

Eighth Edition

This page intentionally left blank

A G U I D E TO S Q L

Eighth Edition

Philip J. Pratt Grand Valley State University Mary Z. Last University of Mary Hardin-Baylor

Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States

A Guide to SQL, Eighth Edition Philip J. Pratt, Mary Z. Last Vice President, Publisher: Jack Calhoun Editor-in-Chief: Alex von Rosenberg Senior Acquisitions Editor: Charles McCormick, Jr. Product Manager: Kate Hennessy Development Editor: Jessica Evans Editorial Assistant: Bryn Lathrop Marketing Director: Brian Joyner Marketing Manager: Bryant Chrzan Marketing Communications Manager: Libby Shipp Marketing Coordinator: Suellen Ruttkay Content Project Manager: Matt Hutchinson Art Director: Stacy Jenkins Shirley, Marissa Falco Cover Designer: Joseph Sherman Cover Image: Getty Images/Taxi/Chris Bell Manufacturing Coordinator: Denise Powers

© 2009 Course Technology, Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright hereon may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at www.cengage.com/permissions Further permission questions can be emailed to permissionrequest@cengage.com

ISBN-13: 978-0-324-59768-4 ISBN-10: 0-324-59768-1 Course Technology 25 Thomson…...

Similar Documents

Cursors in Pl/Sql

...SQL Cursor  A SQL cursor is a private Oracle SQL working area. There are two types of SQL cursor: implicit or explicit cursor. The implicit cursor is used by Oracle server to test and parse the SQL statements and the explicit cursors are declared by the programmers. Using the implicit cursor, we can test the outcome of SQL statements in PL/SQL. For example, • SQL%ROWCOUNT, return the number of rows affected; • SQL%FOUND, a BOOLEAN attribute indicating whether the recent SQL statement matches to any row; • SQL%NOTFOUND, a BOOLEAN attribute indicating whether the recent SQL statement does not match to any row; • SQL%ISOPEN, a BOOLEAN attribute and always evaluated as FALSE immediately after the SQL statement is executed. To write the explicit cursor,  please refer to the following example. Note that a cursor definition can array a number of arguments. For example,         DECLARE CURSOR csr_ac (p_name VARCHAR2) IS SELECT empno, name, sal FROM employee WHERE name LIKE '%p_name%'; BEGIN FOR rec_ac IN csr_ac ('LE') LOOP    DBMS_OUTPUT.PUT_LINE(rec_ac.empno || ' ' ||rec_ac.name || ' '||v_sal);  END LOOP ; CLOSE csr_ac; END; / Another way of writing the above code, is to use the basic loop and the SQL%NOTFOUND cursor, as shown in the following. SQL> DECLARE 2 CURSOR csr_ac (p_name VARCHAR2) IS 3 SELECT empno, ename, sal 4 FROM emp 5 6 WHERE ename LIKE '%SMITH%'; 7 8 v_a......

Words: 2868 - Pages: 12

Sql for Beginners

...An Training Guide SQL & SQL*Plus for Beginners Training Guide SQL & SQL*Plus for Beginners www.appltop.com info@appltop.com Course Introduction Copyright © 1999 – 2004 ApplTop Solutions Limited 2 Training Guide SQL & SQL*Plus for Beginners www.appltop.com info@appltop.com Course Objectives This course is designed to give each delegate a basic understanding/awareness of the following... • Oracle SQL • Oracle SQL*Plus Copyright © 1999 – 2004 ApplTop Solutions Limited 3 Training Guide SQL & SQL*Plus for Beginners www.appltop.com info@appltop.com Course Objectives This course is designed to give each delegate a basic understanding of the following topics... • Oracle SQL. You will learn how to use the industry standard tool for working with a Relational Database. You will also learn many other things, from constructing simple queries to creating your own tables. • Oracle SQL*Plus. After the course you should have a good understanding of SQL*Plus, from starting it, to creating simple reports on it. During the course there will be several exercises to complete. Copyright © 1999 – 2004 ApplTop Solutions Limited 4 Training Guide SQL & SQL*Plus for Beginners www.appltop.com info@appltop.com Note that this guide is meant only as an introduction to SQL and SQL*Plus and therefore much of the newer, more advanced features available in Oracle databases 8i, 9i and 10g are not covered. Copyright © 1999 – 2004 ApplTop......

Words: 19188 - Pages: 77

Database - Sql

...Final Exam Review Below are the review questions for your final exam. You MUST complete this as it is a part of your final exam equaling total of 10 points. Each question must be answered with at least 3 sentences, clearly demonstrating an understanding of the question asked. This is due on the final day in class prior to the final exam. Questions 1. What is a database? Describe the 3 main types discussed in the book. * Is a collection of related data. * Doesn’t have to be electronic; example : card catalog’s in libraries ; spiral notebook ; phone or address book * Usually mean electronic database that run on computers 2. Why is the relational database model most commonly used today? What impact does it have on data integrity? * The idea came from Edgar F Codd in 1970 he worked for IBM at the time * Advantage is the tables define the relationships among themselves by mean of repeating an attribute or column from one table in another table “called Keys” * One of the problems was data redundancy; means to store the same data in more than place in the database * Codd’s theoretical design minimized redundancy * The impact is; the complexity of the design, its easy to create a hard to use database, or hard to fine the data you entered into the database. So a well-designed database = data integrity and flexibility. 3. Distinguish between data integrity and redundancy. * Data integrity = to the accuracy and quality of the...

Words: 2656 - Pages: 11

Teach Yourself Sql

...Teach Yourself SQL in 21 Days, Second Edition Table of Contents: Introduction Week 1 at a Glance Day 1 Introduction to SQL Day 2 Introduction to the Query: The SELECT Statement Day 3 Expressions, Conditions, and Operators Day 4 Functions: Molding the Data You Retrieve Day 5 Clauses in SQL Day 6 Joining Tables Day 7 Subqueries: The Embedded SELECT Statement Week 1 in Review Week 2 at a Glance Day 8 Manipulating Data Day 9 Creating and Maintaining Tables Day 10 Creating Views and Indexes Day 11 Controlling Transactions Day 12 Database Security Day 13 Advanced SQL Topics Day 14 Dynamic Uses of SQL Week 2 in Review Week 3 at a Glance Day 15 Streamlining SQL Statements for Improved Performance Day 16 Using Views to Retrieve Useful Information from the Data Dictionary Day 17 Using SQL to Generate SQL Statements Day 18 PL/SQL: An Introduction Day 19 Transact-SQL: An Introduction Day 20 SQL*Plus Day 21 Common SQL Mistakes/Errors and Resolutions Week 3 in Review Appendixes A Glossary of Common SQL Statements B Source Code Listings for the C++ Program Used on Day 14 C Source Code Listings for the Delphi Program Used on Day 14 D Resources E ASCII Table F Answers to Quizzes and Excercises © Copyright, Macmillan Computer Publishing. All rights reserved. Teach Yourself SQL in 21 Days, Second Edition Acknowledgments A special thanks to the following individuals: foremost to my loving wife, Tina, for her tolerance and endless support, to Dan Wilson for his...

Words: 128515 - Pages: 515

Sql Homework

...Question 1 select [book_code],[title],[book].[publisher_code],[publisher].[publisher_name] from[book],[publisher] where [book].[publisher_code]=[publisher].[publisher_code] order by [PUBLISHER_NAME] ; 33 rows returned 3906 The Soul of a New Machine BY Back Bay Books 8092 Godel, Escher, Bach BA Basic Books 3350 Group: Six People in Search of a Life BP Berkley Publishing 669X A Guide to SQL CT Course Technology 2908 Electric Light FS Farrar Straus and Giroux 0189 Magic Terror FA Fawcett Books 9931 To Kill a Mockingbird HC HarperCollins Publishers 9882 Slay Ride JP Jove Publications 8720 When Rabbit Howls JP Jove Publications 0808 The Edge JP Jove Publications 3743 Nine Stories LB Lb Books 6908 Franny and Zooey LB Lb Books 9883 The Catcher in the Rye LB Lb Books 9701 The Grapes of Wrath PE Penguin USA 7405 East of Eden PE Penguin USA 2766 Of Mice and Men PE Penguin USA 5163 Travels with Charley ...

Words: 408 - Pages: 2

Sql Tutorial

...SQL Tutorial SQL TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL SQL Tutorial SQL is a database computer language designed for the retrieval and management of data in relational database. SQL stands for Structured Query Language. This tutorial will give you quick start with SQL. Audience This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to SQL languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is database, especially RDBMS and what is a computer programming language. Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at webmaster@tutorialspoint.com TUTORIALS POINT Simply Easy Learning Table of Content SQL Tutorial .................................................................

Words: 39505 - Pages: 159

What Is Sql

...C H A P T E R 3 SQL Chapter 3 covers the relational language SQL. The discussion is based on SQL:1999. Integrity constraint and authorization features of SQL being a large language, many of its features are not covered here, and are not appropriate for an introductory course on databases. Standard books on SQL, such as Date and Darwen [1993] and Melton and Simon [1993], or the system manuals of the database system you use can be used as supplements for students who want to delve deeper into the intricacies of SQL. Although it is possible to cover this chapter using only handwritten exercises, we strongly recommend providing access to an actual database system that supports SQL. A style of exercise we have used is to create a moderately large database and give students a list of queries in English to write and run using SQL. We publish the actual answers (that is the result relations they should get, not the SQL they must enter). By using a moderately large database, the probability that a “wrong” SQL query will just happen to return the “right” result relation can be made very small. This approach allows students to check their own answers for correctness immediately rather than wait for grading and thereby it speeds up the learning process. A few such example databases are available on the Web home page of this book. Exercises that pertain to database design are best deferred until after Chapter 7. Exercises 3.8 Consider the insurance database of Figure 3.11,......

Words: 762 - Pages: 4

Sql Server

...SQL Server 2012 Proposal for ABC Inc Name Institution Table of contents Cover page 1 Table of contents 2 Introduction 3 Statement of the problem 3 Solution 4 Conclusion 5 References 6 SQL Server 2012 Proposal for ABC Inc Introduction For an organization to carry out its processes effectively, it is important to have a database. Database management is essential in every organization. There are several methods that have existed over the years. They include excel spreadsheet and Access. These are good database, but I would like to propose a more advanced method. The SQL 2012 is a database system that will enable the organization to utilize technology (Mistry & Misner, 2012). The Microsoft SQL server 2012 consists of several editions that can help ABC Inc to meet its database requirements. Investing in this database system will be of many benefits to the company. Statement of the Problem In the world of changing technology, it is important to adopt change and advanced methods of running a company. Over the years, ABC Inc has been using excel spreadsheets and access; it is time to move to SQL 2012 server. It is not easy to store a lot of data in Excel and access compared to the SQL. The company has been able to use Excel over time, but it has not been possible to get high quality data.......

Words: 943 - Pages: 4

Sql Fundamentals

...SQL Fundamentals The Structured Query Language (SQL) comprises one of the fundamental building blocks of modern database architecture. SQL defines the methods used to create and manipulate relational databases on all major platforms. At first glance, the language may seem intimidating and complex but it's really not all that bad. In a series of articles over the next few weeks we'll explore the inner workings of SQL together. By the time we're through, you'll have the fundamental knowledge you need to go out there and start working with databases! This week, our first article in the SQL series provides an introduction to the basic concepts behind SQL and we'll take a brief look at some of the main commands used to create and modify databases. Throughout this article, please keep our goal in mind: we're trying to get the "big picture" of SQL -- not a mastery of the individual commands. We'll provide a few examples for illustrative purposes and explain the theory behind them, but don't feel frustrated if you can't write your own SQL commands after reading this article. We'll cover each of the major commands in detail in future weekly installments. If you'd like a reminder in your e-mail inbox each week when the next article is posted, please take a moment and subscribe to our newsletter. By the way, the correct pronunciation of SQL is a contentious issue within the database community. In their SQL standard, the American National Standards Institute declared that the......

Words: 1859 - Pages: 8

Sql Quiz

...Chapter 15 Quiz * Due Mar 26 at 6pm * Points 10 * Questions 10 * Available Mar 19 at 12am - Mar 26 at 6pm 8 days * Time Limit None Attempt History   | Attempt | Time | Score | LATEST | Attempt 1 | 36 minutes | 7 out of 10 | Score for this quiz: 7 out of 10 Submitted Mar 19 at 11:58pm This attempt took 36 minutes.   Question 1 1 / 1 pts Parameters for stored procedures and functions can be of any valid SQL Server data type except Parameters for stored procedures and functions can be of any valid SQL Server data type except   date/time Correct!   table   xml   numeric   Question 2 0 / 1 pts Skip to question text. Code a statement that calls the following stored procedure and passes the values ‘2011-12-01’ and 122 to its input parameters. Pass the parameters by name in the reverse order that they’re declared in the procedure. CREATE PROC spInvoiceTotal1        @DateVar smalldatetime,        @VendorID int AS SELECT SUM(InvoiceTotal) FROM Invoices WHERE VendorID = @VendorID AND InvoiceDate >= @DateVar; ______________________________________________________________________________ You Answered Correct Answers EXEC spInvoiceTotal1 @VendorID = 122, @DateVar = '2011-12-01'; EXEC spInvoiceTotal1 @VendorID = 122, @DateVar = '2011-12-01'   Question 3 0 / 1 pts Before you can pass a table to a stored procedure or a function as a parameter, you must use the ______________________ statement to...

Words: 645 - Pages: 3

Joins in Sql

...Join in SQL SQL Join is used to fetch data from two or more tables, which is joined to appear as single set of data. SQL Join is used for combining column from two or more tables by using values common to both tables. JoinKeyword is used in SQL queries for joining two or more tables. Minimum required condition for joining table, is(n-1) where n, is number of tables. A table can also join to itself known as, Self Join. Types of Join The following are the types of JOIN that we can use in SQL. * Inner * Outer * Left * Right Cross JOIN or Cartesian Product This type of JOIN returns the cartesian product of rows from the tables in Join. It will return a table which consists of records which combines each row from the first table with each row of the second table. Cross JOIN Syntax is, SELECT column-name-list from table-name1 CROSS JOIN table-name2; Example of Cross JOIN The class table, ID | NAME | 1 | abhi | 2 | adam | 4 | alex | The class_info table, ID | Address | 1 | DELHI | 2 | MUMBAI | 3 | CHENNAI | Cross JOIN query will be, SELECT * from class, cross JOIN class_info; The result table will look like, ID | NAME | ID | Address | 1 | abhi | 1 | DELHI | 2 | adam | 1 | DELHI | 4 | alex | 1 | DELHI | 1 | abhi | 2 | MUMBAI | 2 | adam | 2 | MUMBAI | 4 | alex | 2 | MUMBAI | 1 | abhi | 3 | CHENNAI | ...

Words: 1005 - Pages: 5

Sql Assignment

...SQL> select bdate,address 2 from employee 3 where fname='John' and minit='B' and lname='Smith'; BDATE ADDRESS -------- ------------------------------ 65/01/09 731 Fondren, Houston, TX SQL> select fname,lname,address 2 from employee,department 3 where dname='Research' and 4 dnumber=dno; FNAME LNAME ADDRESS ------------------------------ ------------------------------ ------------------------------ John Smith 731 Fondren, Houston, TX Franklin Wong 638 Voss, Houton, TX Ramesh Narayan 975 Fire Oak, Humble, TX Joyco English 5631 Rice, Houston, TX SQL> select pnumber,dnum,lname,address,bdate 2 from project,department,employee 3 where dnum=dnumber and Mgr_ssn=ssn and plocation='Stafford'; PNUMBER DNUM LNAME ADDRESS BDATE ---------- ---------- ------------------------------ ------------------------------ -------- 10 4 Wallace 291 Berry, Bellaire, TX 41/06/20 30 4 Wallace 291 Berry, Bellaire, TX 41/06/20 SQL> select fname, employee.lname, address 2 from employee, department 3 where department.dname='research' and......

Words: 2277 - Pages: 10

Sql Injection.

...due to a SQL injection flaw in a web application that communicate with a database. Over ten years have passed since a famous hacker coined the term “SQL injection” and it is still considered one of the major application threats. A lot has been said on this vulnerability, but not all of the aspects and implications have been uncovered, yet. This paper aim is to collate some of the existing knowledge, introduce new techniques and demonstrate how to get complete control over the database management system's underlying operating system, file system and internal network through SQL injection vulnerability in over-looked and theoretically not exploitable scenarios. This paper also discuss about the prevention from the SQL Injection, not only in ORACLE but also in PHP, C#, JAVA and other languages. INDEX ABSTRACT………………………………………………………………………………….....02 INTRODUCTION……………….…………………………….…….………………………….04 BLIND SQL INJECTION…………………………………….………………………………..05 SQL INJECTION OVERVIEW…………………………….………………………………....06 CATEGORIES OF SQL INJECTION ATTACKS…………………………………………..07 WHAT’S VULNERABLE…………………………………………………………..…………08 WHAT’S NOT VULNERABLE…………………………………………………….………….08 SQL INJECTION METHODS……………………………………….……………….……….09 SQL MANIPULATION………………………………………………………..……………….09 CODE INJECTION……………………………………………………….……………………10 FUNCTION CALL INJECTION……………………………………………………………….11 BUFFER OVERFLOWS………………………………………………………………………13 SQL INJECTION TESTING METHODOLOGY………………………………………….....14 PREVENTING SQL......

Words: 3449 - Pages: 14

Sql Plus

...Introduction to Oracle9i: SQL Instructor Guide • Volume 1 40049GC11 Production 1.1 October 2001 D33993 Authors Copyright © Oracle Corporation, 2000, 2001. All rights reserved. Nancy Greenberg Priya Nathan This documentation contains proprietary information of Oracle Corporation. It is provided under a license agreement containing restrictions on use and disclosure and is also protected by copyright law. Reverse engineering of the software is prohibited. If this documentation is delivered to a U.S. Government Agency of the Department of Defense, then it is delivered with Restricted Rights and the following legend is applicable: Technical Contributors and Reviewers Josephine Turner Martin Alvarez Anna Atkinson Don Bates Marco Berbeek Andrew Brannigan Restricted Rights Legend Use, duplication or disclosure by the Government is subject to restrictions for commercial computer software and shall be deemed to be Restricted Rights software under Federal law, as set forth in subparagraph (c)(1)(ii) of DFARS 252.227-7013, Rights in Technical Data and Computer Software (October 1988). This material or any portion of it may not be copied in any form or by any means without the express prior written permission of Oracle Corporation. Any other copying is a violation of copyright law and may result in civil and/or criminal penalties. Laszlo Czinkoczki Michael Gerlach Sharon Gray Rosita Hanoman Mozhe Jalali Sarah Jones Charbel......

Words: 33197 - Pages: 133

Sql Defrag

...WHITEPAPER By Juan Rogers With an Introduction to SQL defrag manager SQL SERVER FRAGMENTATION EXPLAINED TM SUMMARY approach to identifying and resolving index fragmentation in SQL Server Warning: This white paper will get a bit technical as it is intended for DBAs who want to truly understand the details and key components of fragmentation in SQL Server. » How to judge the improvements gained by defragmenting your server » » The pros and cons of various approaches to managing fragmentation » The mechanics behind performance robbing data voids » How fragmentation affects performance » The difference between disk and SQL Server internal and external fragmentation The following is a summary of the key topics covered in this paper: monitoring and managing index fragmentation. This technical white paper will help you understand SQL Server fragmentation OVERVIEW As the data in Microsoft SQL Server tables changes their indexes change. Over time these indexes become fragmented. This fragmentation will adversely affect performance. This technical white paper provides information to help you understand the detailed mechanics behind fragmentation. It will also help you understand the methods and approaches for performing defragmentation so you can improve your SQL Server’s......

Words: 3053 - Pages: 13