Ryan Stephens Arie D. Jones Ron Plew SQL SIXTH EDITION

Size: px
Start display at page:

Download "Ryan Stephens Arie D. Jones Ron Plew SQL SIXTH EDITION"

Transcription

1

2 Ryan Stephens Arie D. Jones Ron Plew SQL SIXTH EDITION

3 Sams Teach Yourself SQL in 24 Hours, Sixth Edition Copyright 2016 by Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. Microsoft and Microsoft SQL Server are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. ISBN-13: ISBN-10: Library of Congress Control Number: Printed in the United States of America First Printing December 2015 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Special Sales For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned. com or (800) For government sales inquiries, please contact governmentsales@pearsoned.com. For questions about sales outside the U.S., please contact international@pearsoned.com. Editor-in-Chief Mark Taub Executive Editor Laura Lewin Development Editor Michael Thurston Managing Editor Kristy Hart Senior Project Editor Lori Lyons Copy Editor Apostrophe Editing Services Indexer Lisa Stumpf Proofreader Debbie Williams Technical Editors Marshall Pyle Jacinda Simmerman Editorial Assistant Olivia Basegio Cover Designer Mark Shirar Compositor Nonie Ratcliff

4 Contents at a Glance Part I: An SQL Concepts Overview HOUR 1 Welcome to the World of SQL... 1 Part II: Building Your Database HOUR 2 Defining Data Structures Managing Database Objects The Normalization Process Manipulating Data Managing Database Transactions Part III: Getting Effective Results from Queries HOUR 7 Introduction to Database Queries Using Operators to Categorize Data Summarizing Data Results from a Query Sorting and Grouping Data Restructuring the Appearance of Data Understanding Dates and Times Part IV: Building Sophisticated Database Queries HOUR 13 Joining Tables in Queries Using Subqueries to Define Unknown Data Combining Multiple Queries into One Part V: SQL Performance Tuning HOUR 16 Using Indexes to Improve Performance Improving Database Performance

5 iv Sams Teach Yourself SQL in 24 Hours Part VI: Using SQL to Manage Users and Security HOUR 18 Managing Database Users Managing Database Security Part VII: Summarized Data Structures HOUR 20 Creating and Using Views and Synonyms Working with the System Catalog Part VIII: Applying SQL Fundamentals in Today s World HOUR 22 Advanced SQL Topics Extending SQL to the Enterprise, the Internet, and the Intranet Extensions to Standard SQL Part IX: Appendixes APPENDIX A Common SQL Commands B Installing Oracle and Microsoft SQL C Answers to Quizzes and Exercises D Bonus Exercises E Glossary Index

6 Table of Contents Part I: An SQL Concepts Overview HOUR 1: Welcome to the World of SQL SQL Definition and History SQL Sessions Types of SQL Commands Canary Airlines: The Database Used in This Book Summary Q&A Workshop Part II: Building Your Database HOUR 2: Defining Data Structures What Is Data? Basic Data Types Summary Q&A Workshop HOUR 3: Managing Database Objects Database Objects and Schema Tables: The Primary Storage for Data Integrity Constraints Summary Q&A Workshop

7 vi Sams Teach Yourself SQL in 24 Hours HOUR 4: The Normalization Process Normalizing a Database Denormalizing a Database Summary Q&A Workshop HOUR 5: Manipulating Data Overview of Data Manipulation Populating Tables with New Data Updating Existing Data Deleting Data from Tables Summary Q&A Workshop HOUR 6: Managing Database Transactions What Is a Transaction? Controlling Transactions Poor Transactional Control Summary Q&A Workshop Part III: Getting Effective Results from Queries HOUR 7: Introduction to Database Queries The SELECT Statement Case-Sensitivity Fundamentals of Query Writing Summary Q&A Workshop

8 Contents vii HOUR 8: Using Operators to Categorize Data What Is an Operator in SQL? Comparison Operators Logical Operators Conjunctive Operators Negative Operators Arithmetic Operators Summary Q&A Workshop HOUR 9: Summarizing Data Results from a Query Aggregate Functions Summary Q&A Workshop HOUR 10: Sorting and Grouping Data Why Group Data? The GROUP BY Clause GROUP BY Versus ORDER BY CUBE and ROLLUP Expressions The HAVING Clause Summary Q&A Workshop HOUR 11: Restructuring the Appearance of Data ANSI Character Functions Common Character Functions Miscellaneous Character Functions Mathematical Functions Conversion Functions Combining Character Functions

9 viii Sams Teach Yourself SQL in 24 Hours Summary Q&A Workshop HOUR 12: Understanding Dates and Times How Is a Date Stored? Date Functions Date Conversions Summary Q&A Workshop Part IV: Building Sophisticated Database Queries HOUR 13: Joining Tables in Queries Selecting Data from Multiple Tables Understanding Joins Join Considerations Summary Q&A Workshop HOUR 14: Using Subqueries to Define Unknown Data What Is a Subquery? Embedded Subqueries Correlated Subqueries Subquery Performance Summary Q&A Workshop HOUR 15: Combining Multiple Queries into One Single Queries Versus Compound Queries Compound Query Operators Using ORDER BY with a Compound Query Using GROUP BY with a Compound Query

10 Contents ix Retrieving Accurate Data Summary Q&A Workshop Part V: SQL Performance Tuning HOUR 16: Using Indexes to Improve Performance What Is an Index? How Do Indexes Work? The CREATE INDEX Command Types of Indexes When Should Indexes Be Considered? When Should Indexes Be Avoided? Altering an Index Dropping an Index Summary Q&A Workshop HOUR 17: Improving Database Performance What Is SQL Statement Tuning? Database Tuning Versus SQL Statement Tuning Formatting Your SQL Statement Full Table Scans Other Performance Considerations Cost-Based Optimization Summary Q&A Workshop Part VI: Using SQL to Manage Users and Security HOUR 18: Managing Database Users User Management in the Database The Management Process

11 x Sams Teach Yourself SQL in 24 Hours Tools Utilized by Database Users Summary Q&A Workshop HOUR 19: Managing Database Security What Is Database Security? What Are Privileges? Controlling User Access Controlling Privileges Through Roles Summary Q&A Workshop Part VII: Summarized Data Structures HOUR 20: Creating and Using Views and Synonyms What Is a View? Creating Views Updating Data Through a View Dropping a View Performance Impact of Nested Views What Is a Synonym? Summary Q&A Workshop HOUR 21: Working with the System Catalog What Is the System Catalog? How Is the System Catalog Created? What Is Contained in the System Catalog? System Catalog Tables by Implementation Querying the System Catalog Updating System Catalog Objects

12 Contents xi Summary Q&A Workshop Part VIII: Applying SQL Fundamentals in Today s World HOUR 22: Advanced SQL Topics Cursors Stored Procedures and Functions Triggers Dynamic SQL Call-Level Interface Using SQL to Generate SQL Direct Versus Embedded SQL Windowed Table Functions Working with XML Summary Q&A Workshop HOUR 23: Extending SQL to the Enterprise, the Internet, and the Intranet SQL and the Enterprise Accessing a Remote Database SQL and the Internet SQL and the Intranet Summary Q&A Workshop HOUR 24: Extensions to Standard SQL Various Implementations Example Extensions Interactive SQL Statements Summary Q&A Workshop

13 xii Sams Teach Yourself SQL in 24 Hours Part IX: Appendixes APPENDIX A: Common SQL Commands SQL Statements SQL Clauses APPENDIX B: Installing Oracle and Microsoft SQL Windows Installation Instructions for Oracle Windows Installation Instructions for Microsoft SQL Server APPENDIX C: Answers to Quizzes and Exercises Hour 1, Welcome to the World of SQL Hour 2, Defining Data Structures Hour 3, Managing Database Objects Hour 4, The Normalization Process Hour 5, Manipulating Data Hour 6, Managing Database Transactions Hour 7, Introduction to the Database Queries Hour 8, Using Operators to Categorize Data Hour 9, Summarizing Data Results from a Query Hour 10, Sorting and Grouping Data Hour 11, Restructuring the Appearance of Data Hour 12, Understanding Dates and Times Hour 13, Joining Tables in Queries Hour 14, Using Subqueries to Define Unknown Data Hour 15, Combining Multiple Queries into One Hour 16, Using Indexes to Improve Performance Hour 17, Improving Database Performance Hour 18, Managing Database Users Hour 19, Managing Database Security Hour 20, Creating and Using Views and Synonyms Hour 21, Working with the System Catalog Hour 22, Advanced SQL Topics Hour 23, Extending SQL to the Enterprise, the Internet, and the Intranet

14 Contents xiii Hour 24, Extensions to Standard SQL APPENDIX D: Bonus Exercises APPENDIX E: Glossary Index

15 About the Authors For more than 20 years each, the authors have studied, applied, and documented the SQL standard and its application to critical database systems in this book. The authors are experts in data management, specializing in Oracle, Microsoft, and other leading technologies. Ryan Stephens is the co-founder and CEO of Perpetual Technologies, Inc. and Indy Data Partners in Indianapolis. Ryan has studied and consulted in the IT field for more than 20 years, specializing in data management, SQL, and Oracle. Ryan authored and taught database and SQL classes for Indiana University-Purdue University in Indianapolis for 5 years, and was a programmer analyst for the Indiana Army National Guard for 12 years. Ryan has written a variety of database and SQL books for Sams Publishing. Arie D. Jones is the Vice President for Emerging Technologies for Indy Data Partners, Inc. (IDP) in Indianapolis. Arie leads IDP s team of experts in planning, design, development, deployment, and management of database environments and applications to achieve the best combination of tools and services for each client. He is a regular speaker at technical events and has authored several books and articles pertaining to database-related topics. Ronald Plew is retired as co-founder and vice president of Perpetual Technologies, Inc. Ron studied and consulted in the field of relational database technology for more than 20 years and has co-authored several books for Sams Publishing. Ron taught SQL and database classes for Indiana University-Purdue University in Indianapolis for 5 years. He is a retired programmer analyst from the Indiana Army National Guard.

16 Dedication This book is dedicated to my strong and driven wife, Jill, and to my three children by whom I m equally smitten and amazed Daniel, Autumn, and Alivia. Ryan I would like to dedicate this book to my wife, Jackie, for being understanding and supportive during the long hours that it took to complete this book. Arie

17 Acknowledgments Thank you to all who have been supportive and patient during the writing of the six editions of this book. This includes, but is probably not limited to, our family, friends, employees, partners, and random people in public who might sense our preoccupied minds. Thank you especially to Ron Plew, my original co-author of this book and business partner. Neither the first edition of this book, nor our company, would exist without your contributions; and to Arie Jones for spearheading this edition and taking on the bulk of the work, while providing leadership during the day at Indy Data Partners. Thanks also to Marshall Pyle and Jacinda Simmerman for technical edits and your perspectives to improve the quality of this text for our readers. And as always, thanks to the staff at Sams Publishing for your attention to detail and patience. It is always a pleasure working with you. Ryan

18 xvii We Want to Hear from You! As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what we re doing right, what we could do better, what areas you d like to see us publish in, and any other words of wisdom you re willing to pass our way. We welcome your comments. You can or write to let us know what you did or didn t like about this book as well as what we can do to make our books better. Please note that we cannot help you with technical problems related to the topic of this book. When you write, please be sure to include this book s title and author as well as your name and address. We will carefully review your comments and share them with the authors and editors who worked on the book. Mail: consumer@samspublishing.com Sams Publishing ATTN: Reader Feedback 800 East 96th Street Indianapolis, IN USA Reader Services Register your copy of Sams Teach Yourself SQL in 24 Hours, Sixth Edition, at informit.com for convenient access to downloads, updates, and corrections as they become available. To start the registration process, go to informit.com/register and log in or create an account*. Enter the product ISBN, , and click Submit. Once the process is complete, you will find any available bonus content under Registered Products. *Be sure to check the box that you would like to hear from us in order to receive exclusive discounts on future editions of this product.

19 This page intentionally left blank

20 HOUR 9 Summarizing Data Results from a Query What You ll Learn in This Hour: Definition of functions Using aggregate functions Summarizing data with aggregate functions Results from using functions In this hour, you learn about SQL s aggregate functions. You can perform a variety of useful functions with aggregate functions, such as getting the highest total of a sale or counting the number of orders processed on a given day. The real power of aggregate functions will be discussed in the next hour when you tackle the GROUP BY clause. Aggregate Functions Functions are keywords in SQL used to manipulate values within columns for output purposes. A function is a command normally used with a column name or expression that processes the incoming data to produce a result. SQL contains several types of functions. This hour covers aggregate functions. An aggregate function provides summarization information for a SQL statement, such as counts, totals, and averages. The basic set of aggregate functions discussed in this hour are COUNT SUM MAX MIN AVG

21 134 HOUR 9: Summarizing Data Results from a Query The following query lists the employee information from the EMPLOYEES table. Note that some of the employees do not have data assigned in some of the columns. We use this data for most of this hour s examples. SELECT TOP 10 EMPLOYEEID,LASTNAME, CITY,STATE,PAYRATE,SALARY FROM EMPLOYEES; EMPLOYEEID LASTNAME CITY STATE PAYRATE SALARY Iner Red Dog NULL Denty Errol NH NULL 3 Sabbah Errol NH NULL 4 Loock Errol NH NULL 5 Sacks Errol NH NULL 6 Arcoraci Alexandria LA NULL 7 Astin Espanola NM NULL 8 Contreraz Espanola NM NULL Capito Espanola NM NULL Ellamar Espanola NM NULL (10 row(s) affected) COUNT You use the COUNT function to count rows or values of a column that do not contain a NULL value. When used within a query, the COUNT function returns a numeric value. You can also use the COUNT function with the DISTINCT command to only count the distinct rows of a dataset. ALL (opposite of DISTINCT ) is the default; it is not necessary to include ALL in the syntax. Duplicate rows are counted if DISTINCT is not specified. One other option with the COUNT function is to use it with an asterisk. COUNT(*) counts all the rows of a table including duplicates, regardless of whether a NULL value is contained in a column. NOTE DISTINCT Can Be Used Only in Certain Circumstances You cannot use the DISTINCT command with COUNT(*), only with COUNT ( column_name ). The syntax for the COUNT function follows: COUNT [ (*) (DISTINCT ALL) ] ( COLUMN NAME ) This example counts all employee IDs: SELECT COUNT(EMPLOYEEID) FROM EMPLOYEES

22 Aggregate Functions 135 This example counts only the distinct rows: SELECT COUNT(DISTINCT SALARY)FROM EMPLOYEES This example counts all rows for SALARY : SELECT COUNT(ALL SALARY)FROM EMPLOYEES This final example counts all rows of the EMPLOYEES table: SELECT COUNT(*) FROM EMPLOYEES COUNT(*) is used in the following example to get a count of all records in the EMPLOYEES table. There are 5,611 employees. SELECT COUNT(*) FROM EMPLOYEES; (1 row(s) affected) CAUTION COUNT(*) Is Different from Other Count Variations COUNT(*) produces slightly different calculations than other count variations. This is because when the COUNT function is used with the asterisk, it counts the rows in the returned result set without regard to duplicates and NULL values. This is an important distinction. If you need your query to return a count of a particular field and include NULLs, you need to use a function such as ISNULL to replace the NULL values. COUNT(EMPLOYEEID) is used in the next example to get a count of all the employee identification IDs that exist in the table. The returned count is the same as the last query because all employees have an identification number. SELECT COUNT(EMPLOYEEID) FROM EMPLOYEES; (1 row(s) affected) COUNT([STATE]) is used in the following example to get a count of all the employee records that have a state assigned. Look at the difference between the two counts. The difference is the number of employees who have NULL in the STATE column.

23 136 HOUR 9: Summarizing Data Results from a Query SELECT COUNT([STATE]) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) The following examples obtain a count of all salary amounts and then all the distinct salary amounts in the EMPLOYEES table. SELECT COUNT(SALARY ) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) SELECT COUNT(DISTINCT SALARY ) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) The SALARY column had a lot of matching amounts, so the DISTINCT values make the counts drop dramatically. NOTE Data Types Do Not Use COUNT Because the COUNT function counts the rows, data types do not play a part. The rows can contain columns with any data type. The only thing that actually counts is whether the value is NULL. SUM The SUM function returns a total on the values of a column for a group of rows. You can also use the SUM function with DISTINCT. When you use SUM with DISTINCT, only the distinct rows are totaled, which might not have much purpose. Your total is not accurate in that case because rows of data are omitted. The syntax for the SUM function follows: SUM ([ DISTINCT ] COLUMN NAME )

24 Aggregate Functions 137 CAUTION SUM Must Be Numeric The value of an argument must be numeric to use the SUM function. You cannot use the SUM function on columns that have a data type other than numeric, such as character or date. This example totals the salaries: SELECT SUM(SALARY) FROM EMPLOYEES This example totals the distinct salaries: SELECT SUM(DISTINCT SALARY) FROM EMPLOYEES In the following query, the sum, or total amount, of all salary values is retrieved from the EMPLOYEES table: SELECT SUM(SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) Observe the way the DISTINCT command in the following example skews the previous results by 68 million dollars. This is why it is rarely useful. SELECT SUM(DISTINCT COST) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) The following query demonstrates that although some aggregate functions require numeric data, this is only limited to the type of data. Here the ZIP column of the EMPLOYEES table shows that the implicit conversion of the VARCHAR data to a numeric type is supported in Oracle: SELECT SUM(ZIP) FROM EMPLOYEES; SUM(ZIP)

25 138 HOUR 9: Summarizing Data Results from a Query Some aggregate functions require numeric data; this is only limited to the type of data. If the data can be converted implicitly, for example, the string '12345' to an integer, then you can use the aggregate function. When you use a type of data that cannot be implicitly converted to a numeric type, such as the POSITION column, it results in an error, as in the following example: SELECT SUM(POSITION) FROM EMPLOYEES; Msg 8117, Level 16, State 1, Line 1 Operand data type varchar is invalid for sum operator. AVG The AVG function finds the average value for a given group of rows. When used with the DISTINCT command, the AVG function returns the average of the distinct rows. The syntax for the AVG function follows: AVG ([ DISTINCT ] COLUMN NAME ) NOTE AVG Must Be Numeric The value of the argument must be numeric for the AVG function to work. The average value for all values in the EMPLOYEES table s SALARY column is retrieved in the following example: SELECT AVG(SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) This example returns the distinct average salary: SELECT AVG(DISTINCT SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected)

26 Aggregate Functions 139 CAUTION Sometimes Your Data Is Truncated In some implementations, the results of your query might be truncated to the precision of the data type. You need to review your database system s documentation to ensure you understand what the normal precision for the various data types is. This will prevent you from unnecessarily truncating data and possibly getting an unexpected result due to the data not being of the proper precision. The next example uses two aggregate functions in the same query. Because some employees are paid hourly and others are on salary, you want to retrieve the average value for both PAYRATE and SALARY. SELECT AVG(PAYRATE) AS AVG_PAYRATE, AVG(SALARY) AS AVG_SALARY FROM EMPLOYEES; AVG_PAYRATE AVG_SALARY Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) Notice how the use of aliases makes the output more readable with multiple aggregate values. Also remember that the aggregate function can work on any numeric data. So you can perform calculations within the parentheses of the function as well. So if you need to get the average hourly rate of salaried employees to compare to the average rate of hourly employees, you could write the following: SELECT AVG(PAYRATE) AS AVG_PAYRATE, AVG(SALARY/2040) AS AVG_SALARY_RATE FROM EMPLOYEES; AVG_PAYRATE AVG_SALARY_RATE Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) MAX The MAX function returns the maximum value from the values of a column in a group of rows. NULL values are ignored when using the MAX function. Using MAX with the DISTINCT command is an option. However, because the maximum value for all the rows is the same as the distinct maximum value, DISTINCT is useless. The syntax for the MAX function is MAX([ DISTINCT ] COLUMN NAME )

27 140 HOUR 9: Summarizing Data Results from a Query The following example returns the highest SALARY in the EMPLOYEES table: SELECT MAX(SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) This example returns the highest distinct salary: SELECT MAX(DISTINCT SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) You can also use aggregate functions such as MAX and MIN (covered in the next section) on character data. In the case of these values, collation of your database comes into play again. Most commonly your database collation is set to a dictionary order, so the results are ranked according to that. For example, say you perform a MAX on the CITY column of the employees table: SELECT MAX(CITY) AS MAX_CITY FROM EMPLOYEES; MAX_CITY Zwara (1 row(s) affected) In this instance, the function returned the largest value according to a dictionary ordering of the data in the column. MIN The MIN function returns the minimum value of a column for a group of rows. NULL values are ignored when using the MIN function. Using MIN with the DISTINCT command is an option. However, because the minimum value for all rows is the same as the minimum value for distinct rows, DISTINCT is useless. The syntax for the MIN function is MIN([ DISTINCT ] COLUMN NAME )

28 Summary 141 The following example returns the lowest SALARY in the EMPLOYEES table: SELECT MIN(SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) This example returns the lowest distinct salary: SELECT MIN(DISTINCT SALARY) FROM EMPLOYEES; Warning: Null value is eliminated by an aggregate or other SET operation. (1 row(s) affected) NOTE DISTINCT and Aggregate Functions Don t Always Mix One important thing to keep in mind when using aggregate functions with the DISTINCT command is that your query might not return the wanted results. The purpose of aggregate functions is to return summarized data based on all rows of data in a table. When DISTINCT is used it is applied first to the results and then those results are passed on to the aggregate function, which can dramatically alter the results. You need to ensure that when you work with DISTINCT with aggregate functions that you understand this. As with the MAX function, the MIN function can work against character data and returns the minimum value according to the dictionary ordering of the data. SELECT MIN(CITY) AS MIN_CITY FROM EMPLOYEES; MIN_CITY AFB MunicipalCharleston SC (1 row(s) affected) Summary Aggregate functions can be useful and are quite simple to use. In this hour you learned how to count values in columns, count rows of data in a table, get the maximum and minimum values

29 142 HOUR 9: Summarizing Data Results from a Query for a column, figure the sum of the values in a column, and figure the average value for values in a column. Remember that NULL values are not considered when using aggregate functions, except when using the COUNT function in the format COUNT(*). Aggregate functions are the first functions in SQL that you have learned in this book, but more follow in the coming hours. You can also use aggregate functions for group values, which are discussed during the next hour. As you learn about other functions, you see that the syntaxes of most functions are similar to one another and that their concepts of use are relatively easy to understand. Q&A Q. Why are NULL values ignored when using the MAX or MIN function? A. A NULL value means that nothing is there, so there would be no maximum or minimum value. Q. Why don t data types matter when using the COUNT function? A. The COUNT function counts only rows. Q. Does the data type matter when using the SUM or AVG function? A. Not exactly. If the data can be implicitly converted to numeric data, then it will still work. It s less a function of what the data type is and more about what data is stored in it. Q. Are you limited to using only column names inside of aggregate functions? A. No, you can use any type of calculation or formula as long as the output corresponds to the proper type of data that the function is expecting to use. Workshop The following workshop is composed of a series of quiz questions and practical exercises. The quiz questions are designed to test your overall understanding of the current material. The practical exercises are intended to afford you the opportunity to apply the concepts discussed during the current hour, as well as build upon the knowledge acquired in previous hours of study. Please take time to complete the quiz questions and exercises before continuing. Refer to Appendix C, Answers to Quizzes and Exercises, for answers.

30 Workshop 143 Quiz 1. True or false: The AVG function returns an average of all rows from a SELECT column, including any NULL values. 2. True or false: The SUM function adds column totals. 3. True or false: The COUNT(*) function counts all rows in a table. 4. True or false: The COUNT([column name]) function counts NULL values. 5. Will the following SELECT statements work? If not, what fixes the statements? Exercises a. SELECT COUNT * FROM EMPLOYEES; b. SELECT COUNT(EMPLOYEEID), SALARY FROM EMPLOYEES; c. SELECT MIN(PAYRATE), MAX(SALARY) FROM EMPLOYEES WHERE SALARY > 50000; d. SELECT COUNT(DISTINCT EMPLOYEEID) FROM EMPLOYEES; e. SELECT AVG(LASTNAME) FROM EMPLOYEES; f. SELECT AVG(CAST(ZIP AS INT)) FROM EMPLOYEES; 1. Use the EMPLOYEES table to construct SQL statements to solve the following exercises: a. What is the average salary? b. What is the maximum pay rate for hourly employees? c. What are the total salaries? d. What is the minimum pay rate? e. How many rows are in the table? 2. Write a query to determine how many employees are in the company whose last names begin with a G. 3. Write a query to determine the minimum and maximum salary and pay rates per city for employees. 4. Write two sets of queries to find the first employee name and last employee name when they are listed in alphabetical order. 5. Write a query to perform an AVG function on the employee names. Does the statement work? Determine why it is that you got that result. 6. Write a query to display the average value of employees salaries that takes NULL values into account. Hint: You won t be using the AVG function.

31 This page intentionally left blank

32 Index A accessing remote databases, adding JDBC (Java Database Connectivity), 340 ODBC (Open Database Connectivity), OLE DB, 340 vendor connectivity product, Web interfaces, columns auto-incrementing columns, to tables, 40 time to dates, addition, 128 ADMIN OPTION, 288 aggregate functions, , 334 AVG, COUNT, creating groups and, DISTINCT, 141 MAX, MIN, SUM, aliases, table aliases, 200 ALL, ALTER ANY TABLE, 285 ALTER DATABASE, 285 ALTER TABLE, 39, 47, 357 ALTER USER, 285 ALTER VIEW, 300 altering indexes, 250 users, American National Standards Institute (ANSI), 2, 159 AND, ANSI (American National Standards Institute), 2, 159 ANSI SQL, 2, 349 ANSI standard, SELECT, 348 ANY, arguments, 94 arithmetic operators, 128 addition, 128 combinations, 130 division, 129 multiplication, 129 subtraction, arranging tables, FROM clause, 257 ASCII function, 172 asterisks, auto-incrementing columns, adding to tables, AVG, avoiding full table scans, 260 HAVING clause, 263 large sort operations, 263 OR, performance, B back-end applications, BACKUP ANY TABLE, 285 BACKUP DATABASE, 285 base tables, joins, basic data types, BOOLEAN values, date and time data types, decimal types, domains, 28 fixed-length strings, 21 floating-point decimals, 24 integers, 24 large object types, 22 literal strings, NULL data types, 26 numeric types, user-defined data types, 27 varying-length strings, batch loads, disabling indexes during, 264 benefits of normalization, BETWEEN, 115 BLOB, 22 bonus exercises, BOOLEAN values, 26-27

33 430 call-level interface (CLI) C call-level interface (CLI), Canary Airlines, cardinality, columns, 250 Cartesian product, joins, CASCADE, 289, 305 case-sensitivity, data, 68 CAST operator, 188 character functions, ASCII function, 172 COALESCE, combining, CONCAT, ISNULL, LENGTH, 169 LOWER, LPAD, 171 LTRIM, REPLACE, 166 RPAD, RTRIM, 168 SUBSTR, TRANSLATE, UPPER, character strings converting dates to, converting numbers to, converting to dates, converting to numbers, check constraints, CLI (call-level interface), client/server model, 5-6 closing cursors, 326 COALESCE, Codd, Dr. E.F., 2 coding standards, 257 collation, 101 column aliases, queries, column lists, ordering, 70 columns, 14 adding auto-incrementing columns, adding mandatory columns to tables, 40 cardinality, 250 controlling user access on individual columns, inserting data into limited columns, modifying, qualifying in queries, 199 restricting access with views, 299 tables, part of, updating combining multiple columns, value of single column, 74 arithmetic operators, 130 character functions, commands, 8-11 data administration commands, DCL (Data Control Language), 10 DDL (Data Definition Language), 9 DML (Data Manipulation Language), 9-10 DQL (Data Query Language), 10 transactional control commands, 11 COMMIT, 11, 357 controlling transactions, comparing GROUP BY clause versus ORDER BY clause, single queries versus compound queries, comparison operators, 110 combinations of, 113 equality, 110 less than and greater than, non-equality, 111 compliance, ANSI SQL, 349 composite indexes, 247 compound queries GROUP BY clause, ORDER BY clause, retrieving accurate data, versus single queries, compound query operators, 230 EXCEPT, INTERSECT, UNION, UNION ALL, CONCAT, concatenation, 160 conjunctive operators, 120 AND, OR, CONNECT, 8 constraints, dropping, 49. See also integrity constraints controlling privileges through roles, 291 CREATE ROLE, 292 DROP ROLE, 292 SET ROLE,

34 data types 431 transactions, COMMIT, RELEASE SAVEPOINT, 89 ROLLBACK, ROLLBACK TO SAVEPOINT, SAVEPOINT, 86 SET TRANSACTION, 89 user access, 287 GRANT, on individual columns, 289 privileges, PUBLIC database account, REVOKE, 289 conversion functions, 173 converting numbers to character strings, converting character strings to numbers, conversions, date conversions, 188 date pictures, converting character strings to dates, character strings to numbers, dates to character strings, numbers to character strings, correlated subqueries, cost-based optimization, performance, COUNT, 104, c ounting records in tables, CREATE ANY TABLE, 285 CREATE DATABASE, 285 CREATE INDEX, 245, 357 CREATE PROCEDURE, 285 CREATE ROLE, 292, 357 CREATE SCHEMA, CREATE SYNONYM, 309 CREATE TABLE AS, 358 CREATE TABLE, 37-39, 245, 285, 358 CREATE TRIGGER, 285, CREATE TYPE, 358 CREATE USER, 273, 285, 358 CREATE VIEW, 285, 300, 358 cross joins, CUBE expression, grouping data, current date, cursors, closing, 326 fetching data, grouping, 145 CUBE expression, GROUP BY clause. See GROUP BY clause HAVING clause, ROLLUP expression, inserting in limited columns of tables, from other tables, in tables, opening, 324 populating tables, 68 redundancy denormalization, logical database design, D retrieving accurate data, compound query operators, selecting from multiple tables, 197 summarized data, views, 299 tables. See tables updating, 73 multiple columns, through views, 307 value of single column, 74 Data access, simplifying with views, Data Control Language (DCL), 10 Data Definition Language (DDL), 9 data dictionary. See system catalog data manipulation, overview, 67 Data Manipulation Language. See DML (Data Manipulation Language) Data Query Language. See DQL (Data Query Language) data types, 19 basic data types, BOOLEAN values, date and time data types, 24-25, 182 decimal types, fixed-length strings, 21 floating-point decimals, 24 integers, 24 large object types, 22 NULL data types, 26 numeric types, 22-23

35 432 data types user-defined data types, 27 varying-length strings, database administrator (DBA), 19 database design information, system catalog, 316 database management system (DBMS), 1 database objects, schemas, database queries, 93 case-sensitivity, constraints, 103 SELECT, FROM clause, 97 ORDER BY clause, SELECT clause, WHERE clause, writing, column aliases, counting records in tables, selecting data from another table, 105 database security, controlling privileges through roles, CREATE ROLE, 292 DROP ROLE, 292 SET ROLE, controlling user access, 287 GRANT, on individual columns, 289 PUBLIC database account, REVOKE, 289 database tuning, 254 versus SQL statement tuning, 254 database vendors, 7-8 databases defined, 4-5 denormalization, relational, 5 web-based database systems, 6-7 DATE, 182 date and time, 182 adding time to dates, current date, leap years, 182 time zones, date and time data types, 24-25, 182 implementation-specific data types, 183 date and time storage, 181 date conversions, 188 date pictures, 189 date functions, 183, converting dates to character strings, current date, time zones, date pictures, 189 dates adding time to, converting character strings to, converting to character strings, DATETIME, basic data types, literal strings, converting character strings to dates, converting dates to character strings, data types, 182 date parts by platform, DATETIME elements, 182 DB_DATAREADER, 291 DB_DATAWRITER, 291 DB_DDLADMIN, 290 DBA (database administrator), 19 DBMS (database management system), 1 DCL (Data Control Language), 10 DDL (Data Definition Language), 9 decimal types, DELETE statement, 75-76, 358 subqueries, deleting data from tables, denormalization, differences between implementation, Direct SQL, 333 disabling indexes during batch loads, 264 DISCONNECT, 8 DISTINCT, 96 aggregate functions, 141 MIN, division, 129 DML (Data Manipulation Language), 9-10 INSERT statement, subqueries, 217 overview, 67 domains, data types, 28 DQL (Data Query Language), 10 SELECT, 93-94

Ryan Stephens. Ron Plew Arie D. Jones. Sams Teach Yourself FIFTH EDITION. 800 East 96th Street, Indianapolis, Indiana, 46240

Ryan Stephens. Ron Plew Arie D. Jones. Sams Teach Yourself FIFTH EDITION. 800 East 96th Street, Indianapolis, Indiana, 46240 Ryan Stephens Ron Plew Arie D. Jones Sams Teach Yourself FIFTH EDITION 800 East 96th Street, Indianapolis, Indiana, 46240 Table of Contents Part I: An SQL Concepts Overview HOUR 1: Welcome to the World

More information

Oracle Syllabus Course code-r10605 SQL

Oracle Syllabus Course code-r10605 SQL Oracle Syllabus Course code-r10605 SQL Writing Basic SQL SELECT Statements Basic SELECT Statement Selecting All Columns Selecting Specific Columns Writing SQL Statements Column Heading Defaults Arithmetic

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business This is the second portion of the Database Design and Programming with SQL course. In this portion, students implement their database design by creating a

More information

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data 1 Writing Basic SQL SELECT Statements Objectives 1-2 Capabilities of SQL SELECT Statements 1-3 Basic SELECT Statement 1-4 Selecting All Columns 1-5 Selecting Specific Columns 1-6 Writing SQL Statements

More information

Course Outline and Objectives: Database Programming with SQL

Course Outline and Objectives: Database Programming with SQL Introduction to Computer Science and Business Course Outline and Objectives: Database Programming with SQL This is the second portion of the Database Design and Programming with SQL course. In this portion,

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL ORACLE UNIVERSITY CONTACT US: 00 9714 390 9000 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database

More information

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model Database Design Section1 - Introduction 1-1 Introduction to the Oracle Academy o Give examples of jobs, salaries, and opportunities that are possible by participating in the Academy. o Explain how your

More information

The SQL Guide to Pervasive PSQL. Rick F. van der Lans

The SQL Guide to Pervasive PSQL. Rick F. van der Lans The SQL Guide to Pervasive PSQL Rick F. van der Lans Copyright 2009 by R20/Consultancy All rights reserved; no part of this publication may be reproduced, stored in a retrieval system, or transmitted in

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the fundamentals of SQL and PL/SQL along with the

More information

Oracle Database 11g: SQL and PL/SQL Fundamentals

Oracle Database 11g: SQL and PL/SQL Fundamentals Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL

More information

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Oracle Database: SQL and PL/SQL Fundamentals Ed 2 Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and

More information

Sql Server Syllabus. Overview

Sql Server Syllabus. Overview Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers

More information

T-SQL Training: T-SQL for SQL Server for Developers

T-SQL Training: T-SQL for SQL Server for Developers Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL

More information

Teradata SQL Features Overview Version

Teradata SQL Features Overview Version Table of Contents Teradata SQL Features Overview Version 14.10.0 Module 0 - Introduction Course Objectives... 0-4 Course Description... 0-6 Course Content... 0-8 Module 1 - Teradata Studio Features Optimize

More information

Oracle Database: Introduction to SQL Ed 2

Oracle Database: Introduction to SQL Ed 2 Oracle University Contact Us: +40 21 3678820 Oracle Database: Introduction to SQL Ed 2 Duration: 5 Days What you will learn This Oracle Database 12c: Introduction to SQL training helps you write subqueries,

More information

"Charting the Course... MOC C: Querying Data with Transact-SQL. Course Summary

Charting the Course... MOC C: Querying Data with Transact-SQL. Course Summary Course Summary Description This course is designed to introduce students to Transact-SQL. It is designed in such a way that the first three days can be taught as a course to students requiring the knowledge

More information

Introduction to the Structured Query Language [ SQL ] (Significant Concepts)

Introduction to the Structured Query Language [ SQL ] (Significant Concepts) Introduction to the Structured Query Language [ SQL ] (Significant Concepts) Learning Objectives This topic is intended to introduce the Structured Query Language (SQL). At the end of the topic it is desired

More information

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands

More information

Table of Contents. Oracle SQL PL/SQL Training Courses

Table of Contents. Oracle SQL PL/SQL Training Courses Table of Contents Overview... 7 About DBA University, Inc.... 7 Eligibility... 8 Pricing... 8 Course Topics... 8 Relational database design... 8 1.1. Computer Database Concepts... 9 1.2. Relational Database

More information

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1 SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier

More information

Oracle Database 11g: SQL Fundamentals I

Oracle Database 11g: SQL Fundamentals I Oracle Database 11g: SQL Fundamentals I Volume I Student Guide D49996GC11 Edition 1.1 April 2009 D59980 Authors Puja Singh Brian Pottle Technical Contributors and Reviewers Claire Bennett Tom Best Purjanti

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-9 7 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training

More information

SQL functions fit into two broad categories: Data definition language Data manipulation language

SQL functions fit into two broad categories: Data definition language Data manipulation language Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my

More information

Oracle Database 12c SQL Fundamentals

Oracle Database 12c SQL Fundamentals Course Overview This course takes a unique approach to SQL training in that it incorporates data modeling theory, relational database theory, graphical depictions of theoretical concepts and numerous examples

More information

UNIT-IV (Relational Database Language, PL/SQL)

UNIT-IV (Relational Database Language, PL/SQL) UNIT-IV (Relational Database Language, PL/SQL) Section-A (2 Marks) Important questions 1. Define (i) Primary Key (ii) Foreign Key (iii) unique key. (i)primary key:a primary key can consist of one or more

More information

Introduction to Computer Science and Business

Introduction to Computer Science and Business Introduction to Computer Science and Business The Database Programming with PL/SQL course introduces students to the procedural language used to extend SQL in a programatic manner. This course outline

More information

GridDB Advanced Edition SQL reference

GridDB Advanced Edition SQL reference GMA022C1 GridDB Advanced Edition SQL reference Toshiba Solutions Corporation 2016 All Rights Reserved. Introduction This manual describes how to write a SQL command in the GridDB Advanced Edition. Please

More information

"Charting the Course to Your Success!" MOC D Querying Microsoft SQL Server Course Summary

Charting the Course to Your Success! MOC D Querying Microsoft SQL Server Course Summary Course Summary Description This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server 2014. This course is the foundation

More information

DB2 SQL Class Outline

DB2 SQL Class Outline DB2 SQL Class Outline The Basics of SQL Introduction Finding Your Current Schema Setting Your Default SCHEMA SELECT * (All Columns) in a Table SELECT Specific Columns in a Table Commas in the Front or

More information

SAS. Information Map Studio 3.1: Creating Your First Information Map

SAS. Information Map Studio 3.1: Creating Your First Information Map SAS Information Map Studio 3.1: Creating Your First Information Map The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2006. SAS Information Map Studio 3.1: Creating Your

More information

5. Single-row function

5. Single-row function 1. 2. Introduction Oracle 11g Oracle 11g Application Server Oracle database Relational and Object Relational Database Management system Oracle internet platform System Development Life cycle 3. Writing

More information

COPYRIGHTED MATERIAL. Contents. Chapter 1: Introducing T-SQL and Data Management Systems 1. Chapter 2: SQL Server Fundamentals 23.

COPYRIGHTED MATERIAL. Contents. Chapter 1: Introducing T-SQL and Data Management Systems 1. Chapter 2: SQL Server Fundamentals 23. Introduction Chapter 1: Introducing T-SQL and Data Management Systems 1 T-SQL Language 1 Programming Language or Query Language? 2 What s New in SQL Server 2008 3 Database Management Systems 4 SQL Server

More information

1) Introduction to SQL

1) Introduction to SQL 1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform

More information

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer, A Access control, 165 granting privileges to users general syntax, GRANT, 170 multiple privileges, 171 PostgreSQL, 166 169 relational databases, 165 REVOKE command, 172 173 SQLite, 166 Aggregate functions

More information

Introduction to SQL/PLSQL Accelerated Ed 2

Introduction to SQL/PLSQL Accelerated Ed 2 Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Introduction to SQL/PLSQL Accelerated Ed 2 Duration: 5 Days What you will learn This Introduction to SQL/PLSQL Accelerated course

More information

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated

More information

INTRODUCTION TO DATABASE

INTRODUCTION TO DATABASE 1 INTRODUCTION TO DATABASE DATA: Data is a collection of raw facts and figures and is represented in alphabets, digits and special characters format. It is not significant to a business. Data are atomic

More information

Data about data is database Select correct option: True False Partially True None of the Above

Data about data is database Select correct option: True False Partially True None of the Above Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another

More information

Oracle Database 10g: SQL Fundamentals I

Oracle Database 10g: SQL Fundamentals I Oracle Database 10g: SQL Fundamentals I Student Guide Volume I D17108GC21 Edition 2.1 December 2006 D48183 Authors Chaitanya Koratamaddi Nancy Greenberg Technical Contributors and Reviewers Wayne Abbott

More information

Oracle SQL & PL SQL Course

Oracle SQL & PL SQL Course Oracle SQL & PL SQL Course Complete Practical & Real-time Training Job Support Complete Practical Real-Time Scenarios Resume Preparation Lab Access Training Highlights Placement Support Support Certification

More information

20461: Querying Microsoft SQL Server 2014 Databases

20461: Querying Microsoft SQL Server 2014 Databases Course Outline 20461: Querying Microsoft SQL Server 2014 Databases Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions,

More information

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables INDEX Exercise No Title 1 Basic SQL Statements 2 Restricting and Sorting Data 3 Single Row Functions 4 Displaying data from multiple tables 5 Creating and Managing Tables 6 Including Constraints 7 Manipulating

More information

20761 Querying Data with Transact SQL

20761 Querying Data with Transact SQL Course Overview The main purpose of this course is to give students a good understanding of the Transact-SQL language which is used by all SQL Server-related disciplines; namely, Database Administration,

More information

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109 Index A abbreviations in field names, 22 in table names, 31 Access. See under Microsoft acronyms in field names, 22 in table names, 31 aggregate functions, 74, 375 377, 416 428. See also AVG; COUNT; COUNT(*);

More information

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time SQL Basics & PL-SQL Complete Practical & Real-time Training Sessions A Unit of SequelGate Innovative Technologies Pvt. Ltd. ISO Certified Training Institute Microsoft Certified Partner Training Highlights

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

Bonus Content. Glossary

Bonus Content. Glossary Bonus Content Glossary ActiveX control: A reusable software component that can be added to an application, reducing development time in the process. ActiveX is a Microsoft technology; ActiveX components

More information

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez SQL Queries for Mere Mortals Third Edition A Hands-On Guide to Data Manipulation in SQL John L. Viescas Michael J. Hernandez r A TT TAddison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco

More information

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant Oracle Developer Track Course Contents Sandeep M Shinde Oracle Application Techno-Functional Consultant 16 Years MNC Experience in India and USA Trainer Experience Summary:- Sandeep M Shinde is having

More information

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney. MariaDB Crash Course Ben Forta A Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Cape Town Sydney Tokyo Singapore Mexico City

More information

ORACLE CERTIFIED ASSOCIATE ORACLE DATABASE 11g ADMINISTRATOR

ORACLE CERTIFIED ASSOCIATE ORACLE DATABASE 11g ADMINISTRATOR ORACLE CERTIFIED ASSOCIATE ORACLE DATABASE 11g ADMINISTRATOR The process of becoming Oracle Database certified broadens your knowledge and skills by exposing you to a wide array of important database features,

More information

Microsoft Querying Microsoft SQL Server 2014

Microsoft Querying Microsoft SQL Server 2014 1800 ULEARN (853 276) www.ddls.com.au Microsoft 20461 - Querying Microsoft SQL Server 2014 Length 5 days Price $4290.00 (inc GST) Version D Overview Please note: Microsoft have released a new course which

More information

Oracle Database 10g: SQL Fundamentals I

Oracle Database 10g: SQL Fundamentals I Oracle Database 10g: SQL Fundamentals I Volume I Student Guide D17108GC11 Edition 1.1 August 2004 D39766 Author Nancy Greenberg Technical Contributors and Reviewers Wayne Abbott Christian Bauwens Perry

More information

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries

More information

SQL STRUCTURED QUERY LANGUAGE

SQL STRUCTURED QUERY LANGUAGE STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an

More information

Today Learning outcomes LO2

Today Learning outcomes LO2 2015 2016 Phil Smith Today Learning outcomes LO2 On successful completion of this unit you will: 1. Be able to design and implement relational database systems. 2. Requirements. 3. User Interface. I am

More information

20761B: QUERYING DATA WITH TRANSACT-SQL

20761B: QUERYING DATA WITH TRANSACT-SQL ABOUT THIS COURSE This 5 day course is designed to introduce students to Transact-SQL. It is designed in such a way that the first three days can be taught as a course to students requiring the knowledge

More information

Relational Database Index Design and the Optimizers

Relational Database Index Design and the Optimizers Relational Database Index Design and the Optimizers DB2, Oracle, SQL Server, et al. Tapio Lahdenmäki Michael Leach A JOHN WILEY & SONS, INC., PUBLICATION Relational Database Index Design and the Optimizers

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,

More information

Relational Database Language

Relational Database Language DATA BASE MANAGEMENT SYSTEMS Unit IV Relational Database Language: Data definition in SQL, Queries in SQL, Insert, Delete and Update Statements in SQL, Views in SQL, Specifying General Constraints as Assertions,

More information

Review -Chapter 4. Review -Chapter 5

Review -Chapter 4. Review -Chapter 5 Review -Chapter 4 Entity relationship (ER) model Steps for building a formal ERD Uses ER diagrams to represent conceptual database as viewed by the end user Three main components Entities Relationships

More information

Greenplum SQL Class Outline

Greenplum SQL Class Outline Greenplum SQL Class Outline The Basics of Greenplum SQL Introduction SELECT * (All Columns) in a Table Fully Qualifying a Database, Schema and Table SELECT Specific Columns in a Table Commas in the Front

More information

Oracle PL/SQL. DUMmIES. by Michael Rosenblum and Dr. Paul Dorsey FOR

Oracle PL/SQL. DUMmIES. by Michael Rosenblum and Dr. Paul Dorsey FOR Oracle PL/SQL FOR DUMmIES by Michael Rosenblum and Dr. Paul Dorsey Oracle PL/SQL For Dummies Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright 2006 by

More information

Slides by: Ms. Shree Jaswal

Slides by: Ms. Shree Jaswal Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval

More information

Beginning Transact-SQL with SQL Server 2000 and Paul Turley with Dan Wood

Beginning Transact-SQL with SQL Server 2000 and Paul Turley with Dan Wood Beginning Transact-SQL with SQL Server 2000 and 2005 Paul Turley with Dan Wood Beginning Transact-SQL with SQL Server 2000 and 2005 Beginning Transact-SQL with SQL Server 2000 and 2005 Paul Turley with

More information

Chapter 1 SQL and Data

Chapter 1 SQL and Data Chapter 1 SQL and Data What is SQL? Structured Query Language An industry-standard language used to access & manipulate data stored in a relational database E. F. Codd, 1970 s IBM 2 What is Oracle? A relational

More information

Deccansoft softwareservices-microsoft Silver Learing Partner. SQL Server Syllabus

Deccansoft softwareservices-microsoft Silver Learing Partner. SQL Server Syllabus SQL Server Syllabus Overview: Microsoft SQL Server is one the most popular Relational Database Management System (RDBMS) used in Microsoft universe. It can be used for data storage as well as for data

More information

Course Outline. Querying Data with Transact-SQL Course 20761B: 5 days Instructor Led

Course Outline. Querying Data with Transact-SQL Course 20761B: 5 days Instructor Led Querying Data with Transact-SQL Course 20761B: 5 days Instructor Led About this course This course is designed to introduce students to Transact-SQL. It is designed in such a way that the first three days

More information

Querying Data with Transact-SQL

Querying Data with Transact-SQL Querying Data with Transact-SQL Course 20761C 5 Days Instructor-led, Hands on Course Information The main purpose of the course is to give students a good understanding of the Transact- SQL language which

More information

Sample Question Paper

Sample Question Paper Sample Question Paper Marks : 70 Time:3 Hour Q.1) Attempt any FIVE of the following. a) List any four applications of DBMS. b) State the four database users. c) Define normalization. Enlist its type. d)

More information

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH 2017 Institute of Aga Network Database LECTURER NIYAZ M. SALIH Database: A Database is a collection of related data organized in a way that data can be easily accessed, managed and updated. Any piece of

More information

Basant Group of Institution

Basant Group of Institution Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of

More information

Oracle Database: Introduction to SQL/PLSQL Accelerated

Oracle Database: Introduction to SQL/PLSQL Accelerated Oracle University Contact Us: Landline: +91 80 67863899 Toll Free: 0008004401672 Oracle Database: Introduction to SQL/PLSQL Accelerated Duration: 5 Days What you will learn This Introduction to SQL/PLSQL

More information

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014 COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014 MODULE 1: INTRODUCTION TO MICROSOFT SQL SERVER 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions,

More information

Querying Data with Transact-SQL

Querying Data with Transact-SQL Querying Data with Transact-SQL 20761B; 5 Days; Instructor-led Course Description This course is designed to introduce students to Transact-SQL. It is designed in such a way that the first three days can

More information

Mahathma Gandhi University

Mahathma Gandhi University Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed

More information

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH Institute of Aga 2018 Microsoft SQL Server LECTURER NIYAZ M. SALIH Database: A Database is a collection of related data organized in a way that data can be easily accessed, managed and updated. Any piece

More information

STRUCTURED QUERY LANGUAGE (SQL)

STRUCTURED QUERY LANGUAGE (SQL) STRUCTURED QUERY LANGUAGE (SQL) EGCO321 DATABASE SYSTEMS KANAT POOLSAWASD DEPARTMENT OF COMPUTER ENGINEERING MAHIDOL UNIVERSITY SQL TIMELINE SCOPE OF SQL THE ISO SQL DATA TYPES SQL identifiers are used

More information

EDUVITZ TECHNOLOGIES

EDUVITZ TECHNOLOGIES EDUVITZ TECHNOLOGIES Oracle Course Overview Oracle Training Course Prerequisites Computer Fundamentals, Windows Operating System Basic knowledge of database can be much more useful Oracle Training Course

More information

Oracle SQL Developer. Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E

Oracle SQL Developer. Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E Oracle SQL Developer Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E39882-02 December 2013 Oracle SQL Developer Oracle TimesTen In-Memory Database Support User's Guide, Release 4.0

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: +27 (0)11 319-4111 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn This Oracle Database: Introduction to SQL training helps you write subqueries,

More information

Slicing and Dicing Data in CF and SQL: Part 1

Slicing and Dicing Data in CF and SQL: Part 1 Slicing and Dicing Data in CF and SQL: Part 1 Charlie Arehart Founder/CTO Systemanage carehart@systemanage.com SysteManage: Agenda Slicing and Dicing Data in Many Ways Handling Distinct Column Values Manipulating

More information

SYSTEM 2000 Essentials

SYSTEM 2000 Essentials 7 CHAPTER 2 SYSTEM 2000 Essentials Introduction 7 SYSTEM 2000 Software 8 SYSTEM 2000 Databases 8 Database Name 9 Labeling Data 9 Grouping Data 10 Establishing Relationships between Schema Records 10 Logical

More information

Essential SQLite3. Section Title Page

Essential SQLite3. Section Title Page One Introduction to SQL 2 Definition of SQL 3 Definition of a Database 4 Two Database Tables 5 Three The SQLite Interface 10 Introduction 11 Running SQLite 12 DOS commands 14 Copying and Pasting 17 Exiting

More information

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Table of Contents. PDF created with FinePrint pdffactory Pro trial version Table of Contents Course Description The SQL Course covers relational database principles and Oracle concepts, writing basic SQL statements, restricting and sorting data, and using single-row functions.

More information

"Charting the Course... Oracle18c SQL (5 Day) Course Summary

Charting the Course... Oracle18c SQL (5 Day) Course Summary Course Summary Description This course provides a complete, hands-on introduction to SQL including the use of both SQL Developer and SQL*Plus. This coverage is appropriate for users of Oracle11g and higher.

More information

Full file at

Full file at David Kroenke's Database Processing: Fundamentals, Design and Implementation (10 th Edition) CHAPTER TWO INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) True-False Questions 1. SQL stands for Standard

More information

Brad Dayley. Sams Teach Yourself. NoSQL with MongoDB. SAMS 800 East 96th Street, Indianapolis, Indiana, USA

Brad Dayley. Sams Teach Yourself. NoSQL with MongoDB. SAMS 800 East 96th Street, Indianapolis, Indiana, USA Brad Dayley Sams Teach Yourself NoSQL with MongoDB SAMS 800 East 96th Street, Indianapolis, Indiana, 46240 USA Table of Contents Introduction 1 How This Book Is Organized 1 Code Examples 2 Special Elements

More information

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions RDBMS-Day3 SQL Basic DDL statements DML statements Aggregate functions SQL SQL is used to make a request to retrieve data from a Database. The DBMS processes the SQL request, retrieves the requested data

More information

The SQL data-definition language (DDL) allows defining :

The SQL data-definition language (DDL) allows defining : Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries

More information

AVANTUS TRAINING PTE LTD

AVANTUS TRAINING PTE LTD [MS20461]: Querying Microsoft SQL Server 2014 Length : 5 Days Audience(s) : IT Professionals Level : 300 Technology : SQL Server Delivery Method : Instructor-led (Classroom) Course Overview This 5-day

More information

Using SQL with SQL Developer 18.2

Using SQL with SQL Developer 18.2 One Introduction to SQL 2 - Definition 3 - Usage of SQL 4 - What is SQL used for? 5 - Who uses SQL? 6 - Definition of a Database 7 - What is SQL Developer? 8 Two The SQL Developer Interface 9 - Introduction

More information

Exam code: Exam name: Database Fundamentals. Version 16.0

Exam code: Exam name: Database Fundamentals. Version 16.0 98-364 Number: 98-364 Passing Score: 800 Time Limit: 120 min File Version: 16.0 Exam code: 98-364 Exam name: Database Fundamentals Version 16.0 98-364 QUESTION 1 You have a table that contains the following

More information

Listing of SQLSTATE values

Listing of SQLSTATE values Listing of values 1 of 28 5/15/2008 11:28 AM Listing of values The tables in this topic provide descriptions of codes that can be returned to applications by DB2 UDB for iseries. The tables include values,

More information

Chapter-14 SQL COMMANDS

Chapter-14 SQL COMMANDS Chapter-14 SQL COMMANDS What is SQL? Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is Structured Query Language, which is a computer language

More information

Certification Exam Preparation Seminar: Oracle Database SQL

Certification Exam Preparation Seminar: Oracle Database SQL Oracle University Contact Us: 0800 891 6502 Certification Exam Preparation Seminar: Oracle Database SQL Duration: 1 Day What you will learn This video seminar Certification Exam Preparation Seminar: Oracle

More information

Oracle Database: Introduction to SQL

Oracle Database: Introduction to SQL Oracle University Contact Us: (+202) 35 35 02 54 Oracle Database: Introduction to SQL Duration: 5 Days What you will learn View a newer version of this course This Oracle Database: Introduction to SQL

More information

Chapter 4: SQL. Basic Structure

Chapter 4: SQL. Basic Structure Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL

More information