Topic 8 Structured Query Language (SQL) : DML Part 2
|
|
- Esmond Anthony
- 5 years ago
- Views:
Transcription
1 FIT1004 Database Topic 8 Structured Query Language (SQL) : DML Part 2 Learning Objectives: Use SQL functions Manipulate sets of data Write subqueries Manipulate data in the database References: Rob, P. & Coronel, C., Database Systems, 6 th Edition, Chapters. 6 & 7 Rob, P. & Coronel, C., Database Systems, 7 th Edition, Chapters. 7 &
2 Where We Are Introduction to Database Systems The Relational Model Database Lifecycle Conceptual Design Logical Design Normalisation Physical Design Implementation SQL (DML) SQL (DDL & DCL) Transaction Management Database Administration Data Warehousing & Data Mining 2
3 SQL Functions are useful for manipulating data by decomposing the data elements use numerical, date or string values and may appear in a SQL statement wherever a value or attribute is used support within a DBMS differs between vendors are categorised according to their operand types Function Type Applicable To Arithmetic numerical data Text alphanumeric date Date date/time-related data General any datatype Conversion datatype conversion Group sets of values 3
4 Oracle Arithmetic Functions abs(n) The column s absolute value ceil(n) Nearest whole integer greater than or equal to number > SELECT ceil(10.6) FROM dual; floor(n) Largest integer equal to or less than n > SELECT floor(10.6) FROM dual; mod(m,n) Remainder of m divided by n. If n=0, then m is returned > SELECT mod(7,5) FROM dual; power(m,n) Number m raised to the power of n round(n,m) Results rounded to m places to the right of decimal point sign(n) If n=0, returns 0; if n>0, returns 1; if n<0, returns -1 sqrt(n) Square root of n 4
5 Oracle Text Functions initcap(char) Changes the first character of each character string to uppercase > SELECT initcap( mr teplow ) FROM dual; lower(char), upper(char) Makes the entire string lowercase/uppercase > SELECT lower(ename) FROM employee; replace(char, str1, str2) Character string with every occurrence of str1 being replaced with str2 substr(char,m,n) Picks off part of the character string char starting in position m for n characters > SELECT substr( ABCDEF,2,1) FROM dual; length(char) Length of char > SELECT length( Anderson ) FROM dual; str1 str2 Concatenates two character fields together ltrim(char[, k]), rtrim(char[, k]) remove characters from the left/right of t, until the first character not in k 5
6 Oracle Date Functions last_day Last day of the month SELECT last_day(sysdate) FROM dual; add_months(d,n) Adds or subtracts n months from date d SELECT add_months(sysdate, 2) FROM dual; months_between(f,s) Difference in months between date f and date s SELECT months_between(sysdate, '1-JAN-2006') FROM dual; next_day(d,day) Date that is the specified day of the week after d SELECT next_day(sysdate, 'Monday') FROM dual; extract(c from d) Extract date/time component c from expression d SELECT bdate, extract (year from bdate) AS year_of_birth, extract (month from bdate) AS month_of_birth, extract (day from bdate) AS day_of_birth FROM employee; 6
7 Oracle General Functions greatest(a, b, ) greatest value of the function arguments least(a, b, ) least value of the function arguments SELECT greatest(12*6, 148/2, 73), least(12*6, 148/2, 73) FROM dual; nullif(a, b) NULL if a = b; otherwise a NVL(x, y) y if x is NULL; otherwise x decode (x, a 1, b 1, a 2, b 2,., a n, b n [, y]) b 1 if x = a 1, b 2 if x = a 2,. b n if x = a n, and otherwise y (or default:null) 7
8 Oracle Conversion Functions Three main conversion functions: to_char > converts any data type to character data to_number > converts a valid set of numeric character data to number data type SELECT 123, to_char(123, '$ '), to_number('123') FROM dual; to_date > converts character data of the proper format to date data type. 8
9 Conversion Functions Yor YY or YYYY Last one, two,three or four digits of year. Q Quarter of year (Jan thru March = 1) MM, RM Month(01-12), Roman numeral month (IV for April) Month Name of month WW, W Week of year, Week of month DDD, DD, D Day of the year, month, week DY Abbreviated name of day HH or HH12 Hour of day HH24 Hour of day using 24-hour clock MI Minutes (0-59) SS Seconds (0-59) 9
10 Conversion Functions Yor YY or YYYY Last one, two,three or four digits of year. > SELECT to_char(sysdate, YYYY ) FROM dual; Q Quarter of year (Jan thru March = 1) > SELECT to_char(sysdate, Q ) FROM dual; MM, RM Month(01-12), Roman numeral month (IV for April) > SELECT to_char(sysdate, MM) FROM dual; > SELECT to_char(sysdate, RM ) FROM dual; Month Name of month > SELECT to_char(sysdate, Month ) FROM dual; WW, W Week of year, Week of month > SELECT to_char(sysdate, WW ) FROM dual; > SELECT to_char(sysdate, W ) FROM dual; 10
11 Conversion Functions DDD, DD, D Day of the year, month, week > SELECT to_char(sysdate, DDD ) FROM dual; > SELECT to_char(sysdate, DD ) FROM dual; > SELECT to_char(sysdate, D ) FROM dual; DY, DAY Abbreviated, full name of day > SELECT to_char(sysdate, DY ) FROM dual; HH or HH12 Hour of day > SELECT to_char(sysdate, HH ) FROM dual; HH24 Hour of day using 24-hour clock MI Minutes (0-59) SS Seconds (0-59) > SELECT to_char(sysdate, HH24:MI:SS ) FROM dual; 11
12 Handling of dates in Oracle Dates are stored differently from the SQL standard standard uses two different types: date and time Oracle uses one type: DATE > Stored in internal format contains date and time > Output is controlled by formatting select to_char(sysdate,'dd-mon-yyyy') from dual;» 25-Aug-2006 select to_char(sysdate,'dd-mon-yyyy hh:mi:ss pm') from dual;» 25-Aug :56:50 AM 10G introduced TIMESTAMP finer granularity on secs > select cast(sysdate as TIMESTAMP) from dual; 25/AUG/06 11:15: AM 12
13 Handling of dates in Oracle cont d DATE data type should normally be formatted with TO_CHAR when selecting for display formatted with TO_DATE when comparing or inserting/updating Example: select empno, ename, to_char(bdate,'dd-mon-yyyy') from payroll.employee where bdate > to_date('01-feb-1962','dd-mon-yyyy') order by bdate In the where clause, why not convert bdate on the left to CHAR? where to_char(bdate,'dd-mon-yyyy') > '01-Feb-1962' 13
14 Oracle Group Functions Used to perform mathematical summaries such as: counting the number of rows finding the minimum and maximum values for some specified attribute summing the values in a column, and averaging the values in a specified column. All group functions can be applied only to sets of values return a single aggregated value, derived from a set of values NULL values are ignored by the group functions, the only exception is the COUNT(*) function 14
15 COUNT Function Can use the COUNT function for any datatype COUNT(*) returns the number of rows in a table SELECT COUNT(*) FROM employee; COUNT(expr) returns the number of nonnull rows. SELECT COUNT(empno) FROM employee; SELECT COUNT(comm) FROM employee; 15
16 MAX and MIN Functions Use MIN and MAX functions for any datatype. SELECT MIN(bdate), MAX(bdate) FROM employee; SELECT MIN(ename), MAX(ename) FROM employee; SELECT MIN(comm), MAX(comm) FROM employee; 16
17 SUM and AVG Functions Use the SUM and AVG functions for numeric data. SELECT SUM(msal) FROM employee; SELECT SUM(comm) FROM employee; SELECT AVG(msal) FROM employee; SELECT AVG(comm) FROM employee; 17
18 NVL Function The NVL function forces group functions to include null values. SELECT COUNT(NVL(comm, 0)) FROM employee; SELECT AVG(NVL(comm, 0)) FROM employee; NVL(x,, y) > y if x is NULL; otherwise x > y can be any value SELECT AVG(NVL(comm, 10)) FROM employee; 18
19 GROUP BY clause Is used to divide the rows in a table into groups Allows the aggregate functions to return summary information for each group All columns in the SELECT list that are not in the group functions must be included in the GROUP BY clause The GROUP BY column does not have to be in the SELECT clause SELECT deptno, COUNT(*), MIN(msal), MAX(msal), SUM(msal), AVG(msal) FROM employee GROUP BY deptno; 19
20 GROUP BY clause All columns in the SELECT list that are not in group functions must be in the GROUP BY clause. SELECT deptno, AVG(msal) FROM employee; SQL> SELECT deptno, AVG(msal) 2 FROM employee; SELECT deptno, AVG(msal) * ERROR at line 1: ORA-00937: not a single-group group function SELECT d.deptno, d.dname, AVG(e.msal) FROM employee e, department d WHERE e.deptno = d.deptno GROUP BY d.deptno; SQL> SELECT d.deptno, d.dname, AVG(e.msal) 2 FROM employee e, department d 3 WHERE e.deptno = d.deptno 4 GROUP BY d.deptno; SELECT d.deptno, d.dname, AVG(e.msal) * ERROR at line 1: ORA-00979: not a GROUP BY expression 20
21 GROUP BY clause The GROUP BY column does not have to be in the SELECT list. SELECT d.dname, AVG(e.msal) FROM employee e, department d WHERE e.deptno = d.deptno GROUP BY d.deptno, d.dname; Grouping by more than one column SELECT deptno, job, SUM(msal) FROM employee GROUP BY deptno, job; 21
22 Illegal queries using GROUP BY Who earns more than the average salary? SELECT empno, msal FROM employee WHERE msal > avg(msal); SQL> SELECT empno, msal 2 FROM employee 3 WHERE msal > avg(msal); WHERE msal > avg(msal) * ERROR at line 3: ORA-00934: group function is not allowed here Which department pays more than $10000 in salary per month? SELECT deptno, SUM(msal) FROM employee WHERE SUM(msal) > GROUP BY deptno; Cannot use the WHERE clause to restrict groups. 22
23 HAVING clause Is applied to the output of a GROUP BY operation to restrict the selected rows. Operates like a WHERE clause, however, the WHERE clause applies to columns and expressions for individual rows, while the HAVING clause is applied to the output of a GROUP BY operation. The DBMS evaluates the clauses in a SQL statement in the following order: WHERE clause GROUP BY clause HAVING clause Therefore if we wish to restrict the results of a query based on the result of a GROUP BY clause we need to use a HAVING clause rather than the WHERE clause. 23
24 HAVING clause Use the HAVING clause to restrict groups Rows are grouped. The group function is applied. Groups matching the HAVING clause are displayed. SQL> SELECT deptno, max(msal) 2 FROM employee 3 WHERE max(msal)> GROUP BY deptno; SQL> SELECT deptno, max(msal) 2 FROM employee 3 GROUP BY deptno 4 HAVING max(msal)>2900; WHERE max(msal)>2900 * ERROR at line 3: ORA-00934: group function is not allowed here DEPTNO MAX(MSAL)
25 HAVING clause SELECT job, SUM(msal) PAYROLL FROM employee WHERE job NOT LIKE 'SALES%' GROUP BY job HAVING SUM(msal)>5000 ORDER BY SUM(msal); SQL> SELECT job, SUM(msal) PAYROLL 2 FROM employee 3 WHERE job NOT LIKE 'SALES%' 4 GROUP BY job 5 HAVING SUM(msal)> ORDER BY SUM(msal); JOB PAYROLL TRAINER 7900 MANAGER
26 Nesting Functions Can nest aggregate functions Display the maximum average monthly salary SELECT max(avg(msal)) FROM employee GROUP BY deptno; Which department has the greatest average monthly salary? 26
27 Subqueries A subquery is a query that is embedded (or nested) inside another query Also known as a nested query or an inner query. SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM table); The first query in the SQL statement is known as the outer query. The query inside the SQL statement is known as the inner query. The inner query is evaluated first and the output from this query is used as the input for the outer query. The inner query is normally expressed inside parentheses. 27
28 Subqueries The Oracle Server executes subqueries first. returns results into the clause of the main query. Which employee has a greater monthly salary than Blake? SELECT empno, ename, msal FROM employee WHERE msal > (SELECT msal FROM employee WHERE ename = 'BLAKE'); Guidelines Enclose subqueries in parentheses. Place subqueries on the right side of the comparison operator. Do not use an ORDER BY clause to a subquery. Use single-row operators with single-row subqueries. Use multiple-row operators with multiple-row subqueries 28
29 Types of Subqueries Single-row subquery Main query Subquery returns CLERK Multiple-row subquery Main query Subquery returns Multiple-column subquery Main query Subquery returns CLERK MANAGER CLERK 7900 MANAGER
30 Single-Row Subqueries Return only one row Use single-row comparison operators Operator = > >= < <= <> Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to 30
31 Single-Row Subqueries Display the name and job of employees who have the same job as Allen and a monthly salary greater than employee Ward SELECT ename, job, msal FROM employee WHERE job = (SELECT job FROM employee WHERE ename = 'ALLEN') AND msal > (SELECT msal FROM employee WHERE ename = 'WARD'); Display the name, job and monthly salary of employees who earn the least in salary. SELECT ename, job, msal FROM employee WHERE msal = (SELECT min(msal) FROM employee); 31
32 Single-Row Subqueries Which department has the most employees? SELECT d.deptno, d.dname, count(*) FROM department d, employee e WHERE d.deptno = e.deptno HAVING count(*) = (SELECT max(count(*)) FROM employee GROUP BY deptno) GROUP BY d.deptno, d.dname; Which department has the greatest average monthly salary? SELECT d.deptno, d.dname, avg(msal) FROM department d, employee e WHERE d.deptno = e.deptno HAVING avg(msal) = (SELECT max(avg(msal)) FROM employee GROUP BY deptno) GROUP BY d.deptno, d.dname; 32
33 Single-Row Subqueries What is wrong with this statement? SELECT empno, ename FROM employee WHERE msal = (SELECT MIN(msal) FROM employee GROUP BY deptno); SQL> SELECT empno, ename 2 FROM employee 3 WHERE msal = (SELECT MIN(msal) 4 FROM employee 5 GROUP BY deptno); WHERE msal = (SELECT MIN(msal) * ERROR at line 3: ORA-01427: single-row subquery returns more than one row 33
34 Multiple-Row Subqueries Return more than one row Use multiple-row comparison operators Operator IN ANY ALL Meaning Equal to any member in the list Compare value to each value returned by the subquery Compare value to every value returned by the subquery 34
35 Multiple-Row Subqueries Which employees will be displayed? SELECT empno, ename, job, msal FROM employee WHERE msal < ANY (SELECT msal FROM employee WHERE job = 'SALESREP') AND job <> 'SALESREP'; SQL> SELECT msal FROM employee 2 WHERE job = 'SALESREP'; MSAL
36 Multiple-Row Subqueries Which employees will be displayed? SELECT empno, ename, job, msal FROM employee WHERE msal > ALL (SELECT AVG(msal) FROM employee GROUP BY deptno); SQL> SELECT AVG(msal) FROM employee 2 GROUP BY deptno; AVG(MSAL)
37 Multiple-Column Subqueries The number of columns in the main query must match the number of columns returned from the inner query. Display the employees that work in the same department and have the same job as Martin. SELECT empno, ename, deptno, job FROM employee WHERE (deptno, job) = (SELECT deptno, job FROM employee WHERE ename = 'MARTIN'); Write another SQL query that would produce the same result. 37
38 Relational Set Operators SQL data manipulation commands are set oriented, that is they operate over entire sets of rows and columns at once. Using the set operators you can combine two or more sets to create new sets (relations) Union All rows selected by either query Union All All rows selected by either query, including all duplicates Intersect All distinct rows selected by both queries Minus All distinct rows selected by the first query but not the second All set operators have equal precedence. If a SQL statement contains multiple set operators, Oracle evaluates them from the left to right if no parentheses explicitly specify another order. The corresponding expressions in the select lists of the component queries of a compound query must match in number and datatype. 38
39 UNION The UNION statement combines rows from two or more queries without including duplicate rows. The UNION ALL statement combines rows from two or more queries and retains the duplicate rows. The following statement combines the results with the UNION operator, which eliminates duplicate selected rows. You must match datatype (using the TO_CHAR, TO_DATE and TO_NUMBER functions) when columns do not exist in one or the other table: SELECT 'Manager', empno, ename, job, mgr FROM employee WHERE empno IN (SELECT mgr FROM employee) UNION SELECT 'Employee', empno, ename, job, mgr FROM employee WHERE empno NOT IN (SELECT NVL(mgr, 0) FROM employee) ORDER BY mgr 39
40 INTERSECT The INTERSECT statement combines rows from two queries and returns only those rows that appear in both sets. SELECT empno, ename, job, mgr FROM employee WHERE empno IN (SELECT mgr FROM employee) INTERSECT SELECT empno, ename, job, mgr FROM employee; EMPNO ENAME JOB MGR JONES MANAGER BLAKE MANAGER CLARK MANAGER SCOTT TRAINER KING DIRECTOR 7902 FORD TRAINER rows selected. 40
41 MINUS The MINUS statement combines rows from two queries and returns only those rows that appear in the first set but not in the second. SELECT empno, ename, job, mgr FROM employee MINUS SELECT empno, ename, job, mgr FROM employee WHERE empno IN (SELECT mgr FROM employee); EMPNO ENAME JOB MGR SMITH TRAINER ALLEN SALESREP WARD SALESREP MARTIN SALESREP TURNER SALESREP ADAMS TRAINER JONES ADMIN MILLER ADMIN rows selected. 41
42 Manipulating data There are six basic SQL data manipulation commands 42
43 INSERT statement The INSERT statement is used to enter data into a table INSERT INTO table [(column [, column...])] VALUES (value [, value...]); The INSERT statement allows the insertion of data one row at a time If you insert a new row that contains values for each column in the table, the column list is not required in the INSERT clause If you do not use the column list, the values must be listed according to the default order of the columns in the table INSERT INTO department VALUES (50, 'SUPPORT', 'SEATTLE', 7788); INSERT INTO VALUES department (deptno, dname, location) (60, 'ADMIN', 'ORLANDO'); 43
44 INSERT statement Can use the reserved word NULL to specify a null value for a specific column INSERT INTO department VALUES (50, 'SUPPORT', 'SEATTLE', NULL); Can specify the reserved word DEFAULT to insert the default value associated with the corresponding column. If a DEFAULT value was not defined for the column a NULL is inserted instead INSERT INTO employee (empno, ename, init, bdate, msal, deptno) VALUES (7999, 'DUCK', 'D.', to_date('01-jun-1985, DD-MON-YYYY ), 0, DEFAULT); What is the problem with this statement? INSERT INTO employee (empno, ename, init, bdate, msal, deptno) VALUES (8999, 'DOO', 'S.', to_date('01-jun-1985, DD-MON-YYYY ), 4995, 60); What is the problem with this statement? INSERT INTO employee (empno, ename, init, bdate, msal, deptno) VALUES (8999, 'O'BRIEN', 'F.', to_date('01-jun-1985, DD-MON-YYYY ), 4995, 60); 44
45 INSERT statement Can use subqueries in the VALUES clause INSERT INTO employee(empno, ename, init, bdate, msal) VALUES (1111, 'Baggins', 'B.', to_date('25-nov-1985, DD-MON-YYYY ), (SELECT msal FROM employee WHERE ename = 'SMITH')); To insert multiple rows of data use an INSERT statement with a subquery. INSERT INTO table [ column (, column) ] (subquery); INSERT INTO managers(id, name, salary, bdate) SELECT empno, ename, msal, bdate FROM employee WHERE job = 'MANAGER'; Do not use the VALUES clause. Match the number of columns in the INSERT clause to those in the subquery. 45
46 UPDATE statement The UPDATE statement allows you to change attribute values in one or more rows of a table. UPDATE table SET column = value [, column = value,...] [WHERE condition]; UPDATE: the table you want to update SET: the change you want to apply WHERE: the rows to which you want to apply the change if you omit the optional WHERE clause the change is applied to all rows of the table 46
47 UPDATE statement UPDATE employee SET job = 'SALESREP', msal = msal - 500, comm = 0, deptno = 30 WHERE empno = 7876; What is the problem with this statement? UPDATE employee SET deptno = 50 WHERE empno = 7876; 47
48 UPDATE statement You can use subqueries in an UPDATE statement to update rows in a table based on values from another table. UPDATE table SET column = (subquery) [, column = value,...] [WHERE condition]; UPDATE employee SET job = (SELECT job FROM employee WHERE ename = 'CLARK'), deptno = (SELECT deptno FROM employee WHERE ename = 'ALLEN') WHERE empno = 7876; 48
49 DELETE statement The DELETE statement allows you to delete rows of data from a table. DELETE FROM table [WHERE condition]; the WHERE clause is optional, if omitted the DELETE command will delete all rows in the table DELETE FROM employee; DELETE FROM employee WHERE empno = 7999; What is the problem with this statement? DELETE FROM employee WHERE empno = 7566; 49
50 DELETE statement You can use subqueries in a DELETE statement to delete rows in a table based on values from another table. DELETE FROM table [WHERE condition = (subquery)]; DELETE FROM employee WHERE deptno = (SELECT deptno FROM department WHERE dname = 'SALES'); 50
51 Summary This lecture SQL operators and functions Manipulating sets of data Writing subqueries Manipulating data in the database Next lecture Understand the datatypes supported by the SQL standard Use DDL statements to create, alter and drop database objects Use DCL statements to control access to database objects Understand the importance of transaction management Understand the importance of concurrency control Understand the importance of database recovery 51
CS2 Current Technologies Lecture 2: SQL Programming Basics
T E H U N I V E R S I T Y O H F R G E D I N B U CS2 Current Technologies Lecture 2: SQL Programming Basics Dr Chris Walton (cdw@dcs.ed.ac.uk) 4 February 2002 The SQL Language 1 Structured Query Language
More informationReal-World Performance Training SQL Introduction
Real-World Performance Training SQL Introduction Real-World Performance Team Basics SQL Structured Query Language Declarative You express what you want to do, not how to do it Despite the name, provides
More informationCS2 Current Technologies Lecture 3: SQL - Joins and Subqueries
T E H U N I V E R S I T Y O H F R G E D I N B U CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries Chris Walton (cdw@dcs.ed.ac.uk) 11 February 2002 Multiple Tables 1 Redundancy requires excess
More informationGIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement
GIFT Department of Computing Science [Spring 2013] CS-217: Database Systems Lab-2 Manual Data Selection and Filtering using the SELECT Statement V1.0 4/12/2016 Introduction to Lab-2 This lab reinforces
More informationObjectives. After completing this lesson, you should be able to do the following:
Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve Define subqueries List the types of subqueries Write single-row
More informationNone of the techniques used till now allows display of data from a after some arithmetic has been done it. Computations may include displaying
None of the techniques used till now allows display of data from a after some arithmetic has been done it. Computations may include displaying employee salary from the Employee_Master table along with
More informationOracle 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 informationGIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL
GIFT Department of Computing Science [Spring 2016] CS-217: Database Systems Lab-3 Manual Single Row Functions in SQL V3.0 4/26/2016 Introduction to Lab-3 Functions make the basic query block more powerful,
More informationSQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 )
SQL Database Design ( 데이터베이스설계 ) - single row functions - JUNG, Ki-Hyun ( 정기현 ) 1 SQL Functions Input Function Output Function performs action that defined already before execution 2 Two Types of SQL Functions
More informationMANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 3 Professional Program: Data Administration and Management MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) AGENDA
More informationProgramming Languages
Programming Languages Chapter 19 - Continuations Dr. Philip Cannata 1 Exceptions (define (f n) (let/cc esc (/ 1 (if (zero? n) (esc 1) n)))) > (f 0) 1 > (f 2) 1/2 > (f 1) 1 > Dr. Philip Cannata 2 Exceptions
More informationCS2 Current Technologies Note 1 CS2Bh
CS2 Current Technologies Note 1 Relational Database Systems Introduction When we wish to extract information from a database, we communicate with the Database Management System (DBMS) using a query language
More information1 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 informationKing Fahd University of Petroleum and Minerals
1 King Fahd University of Petroleum and Minerals Information and Computer Science Department ICS 334: Database Systems Semester 041 Major Exam 1 18% ID: Name: Section: Grades Section Max Scored A 5 B 25
More informationPractical Workbook Database Management Systems
Practical Workbook Database Management Systems Name : Year : Batch : Roll No : Department: Third Edition Reviewed in 2014 Department of Computer & Information Systems Engineering NED University of Engineering
More informationRDBMS Using Oracle. BIT-4 Lecture Week 3. Lecture Overview
RDBMS Using Oracle BIT-4 Lecture Week 3 Lecture Overview Creating Tables, Valid and Invalid table names Copying data between tables Character and Varchar2 DataType Size Define Variables in SQL NVL and
More information@vmahawar. Agenda Topics Quiz Useful Links
@vmahawar Agenda Topics Quiz Useful Links Agenda Introduction Stakeholders, data classification, Rows/Columns DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE CONSTRAINTS, DATA TYPES DML Data
More informationThe Seven Case Tables
A P P E N D I X A The Seven Case Tables This appendix offers an overview of the seven case tables used throughout this book, in various formats. Its main purpose is to help you in writing SQL commands
More informationDatabase Programming with SQL 5-1 Conversion Functions. Copyright 2015, Oracle and/or its affiliates. All rights reserved.
Database Programming with SQL 5-1 Objectives This lesson covers the following objectives: Provide an example of an explicit data-type conversion and an implicit data-type conversion Explain why it is important,
More informationTO_CHAR Function with Dates
TO_CHAR Function with Dates TO_CHAR(date, 'fmt ) The format model: Must be enclosed in single quotation marks and is case sensitive Can include any valid date format element Has an fm element to remove
More informationOracle 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 informationSQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya.
SQL FUNCTIONS Prepared By:Dr. Vipul Vekariya. SQL FUNCTIONS Definition of Function Types of SQL Function Numeric Function String Function Conversion Function Date Function SQL Function Sub program of SQL
More informationGIFT Department of Computing Science. CS-217: Database Systems. Lab-4 Manual. Reporting Aggregated Data using Group Functions
GIFT Department of Computing Science CS-217: Database Systems Lab-4 Manual Reporting Aggregated Data using Group Functions V3.0 4/28/2016 Introduction to Lab-4 This lab further addresses functions. It
More informationUNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)
UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) 3.1Data types 3.2Database language. Data Definition Language: CREATE,ALTER,TRUNCATE, DROP 3.3 Database language. Data Manipulation Language: INSERT,SELECT,UPDATE,DELETE
More informationOracle 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 informationChapter-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 informationOracle 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 information1 SQL Structured Query Language
1 SQL Structured Query Language 1.1 Tables In relational database systems (DBS) data are represented using tables (relations). A query issued against the DBS also results in a table. A table has the following
More informationFull 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 informationDepartment of Computer Science and Information Systems, College of Business and Technology, Morehead State University
1 Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University Lecture 3 Part A CIS 311 Introduction to Management Information Systems (Spring 2017)
More informationPivot Tables Motivation (1)
Pivot Tables The Pivot relational operator (available in some SQL platforms/servers) allows us to write cross-tabulation queries from tuples in tabular layout. It takes data in separate rows, aggregates
More informationWhat are temporary tables? When are they useful?
What are temporary tables? When are they useful? Temporary tables exists solely for a particular session, or whose data persists for the duration of the transaction. The temporary tables are generally
More information1 SQL Structured Query Language
1 SQL Structured Query Language 1.1 Tables In relational database systems (DBS) data are represented using tables (relations). A query issued against the DBS also results in a table. A table has the following
More informationIntroduction 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 informationDatabase implementation Further SQL
IRU SEMESTER 2 January 2010 Semester 1 Session 2 Database implementation Further SQL Objectives To be able to use more advanced SQL statements, including Renaming columns Order by clause Aggregate functions
More informationTest Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke
Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke Link full download: https://testbankservice.com/download/test-bank-fordatabase-processing-fundamentals-design-and-implementation-13th-edition-bykroenke
More information2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36
Database Processing, 12e (Kroenke/Auer) Chapter 2: Introduction to Structured Query Language (SQL) 1) SQL stands for Standard Query Language. Diff: 1 Page Ref: 32 2) SQL includes a data definition language,
More informationCOSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1
COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE
More informationCourse 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 informationLab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama
The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 6 Using Subqueries and Set Operators Eng. Alaa O Shama November, 2015 Objectives:
More informationOracle 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 informationConversion Functions
Conversion Functions Data type conversion Implicit data type conversion Explicit data type conversion 3-1 Implicit Data Type Conversion For assignments, the Oracle server can automatically convert the
More informationINDEX. 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 informationSQL Structured Query Language (1/2)
Oracle Tutorials SQL Structured Query Language (1/2) Giacomo Govi IT/ADC Overview Goal: Learn the basic for interacting with a RDBMS Outline SQL generalities Available statements Restricting, Sorting and
More informationITEC212 Database Management Systems Laboratory 2
ITEC212 Database Management Systems Laboratory 2 Aim: To learn how to use Single Row Functions and other important functions. In this handout we will learn about the single row functions that are used
More informationDatabase Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL SQL Join Operators Join operation merges rows from two tables and returns the rows with one of the following:
More informationCOGS 121 HCI Programming Studio. Week 03 - Tech Lecture
COGS 121 HCI Programming Studio Week 03 - Tech Lecture Housekeeping Assignment #1 extended to Monday night 11:59pm Assignment #2 to be released on Tuesday during lecture Database Management Systems and
More informationOverview of PL/SQL. About PL/SQL. PL/SQL Environment. Benefits of PL/SQL. Integration
About PL/ Overview of PL/ PL/ is an extension to with design features of programming languages. Data manipulation and query statements of are included within procedural units of code. PL/ Environment Benefits
More informationIntroduction. Introduction to Oracle: SQL and PL/SQL
Introduction Introduction to Oracle: SQL and PL/SQL 1 Objectives After completing this lesson, you should be able to do the following: Discuss the theoretical and physical aspects of a relational database
More informationPart III. Data Modelling. Marc H. Scholl (DBIS, Uni KN) Information Management Winter 2007/08 1
Part III Data Modelling Marc H. Scholl (DBIS, Uni KN) Information Management Winter 2007/08 1 Outline of this part (I) 1 Introduction to the Relational Model and SQL Relational Tables Simple Constraints
More informationOracle 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 informationAO3 - Version: 2. Oracle Database 11g SQL
AO3 - Version: 2 Oracle Database 11g SQL Oracle Database 11g SQL AO3 - Version: 2 3 days Course Description: This course provides the essential SQL skills that allow developers to write queries against
More informationRMS Report Designing
RMS Report Designing RMS Report Writing Examples for designing custom report in RMS by RMS Support Center RMS uses the Report Builder report writing tool to allow users to design customized Reports using
More informationOracle Database SQL Basics
Oracle Database SQL Basics Kerepes Tamás, Webváltó Kft. tamas.kerepes@webvalto.hu 2015. február 26. Copyright 2004, Oracle. All rights reserved. SQL a history in brief The relational database stores data
More informationTopics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia
Topics Fundamentals of PL/SQL, Integration with PROIV SuperLayer and use within Glovia 1. Creating a Database Alias 2. Introduction to SQL Relational Database Concept Definition of Relational Database
More informationChapter 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 informationIntroduction to SQL, SQL*Plus, and SQL Developer
C H A P T E R 2 Introduction to SQL, SQL*Plus, and SQL Developer This chapter provides an introduction to the SQL language and two tools for working with it. The first section presents a high-level overview
More informationNURSING_STAFF NNbr NName Grade
The SELECT command is used to indicate which information we need to obtain not how the information is to be processed. SQL is a non-procedural language. SELECT [DISTINCT ALL] {* [column_expression [AS
More informationSQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior
SQL Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior 1 DDL 2 DATA TYPES All columns must have a data type. The most common data types in SQL are: Alphanumeric: Fixed length:
More informationSQL Structured Query Language Introduction
SQL Structured Query Language Introduction Rifat Shahriyar Dept of CSE, BUET Tables In relational database systems data are represented using tables (relations). A query issued against the database also
More informationLab # 6. Data Manipulation Language (DML)
Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 6 Data Manipulation Language (DML) Eng. Haneen El-Masry December, 2014 2 Objective To be more familiar
More informationObjectives. After completing this lesson, you should be able to do the following:
Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using equality and nonequality joins View data that generally
More informationUsing the Set Operators. Copyright 2006, Oracle. All rights reserved.
Using the Set Operators Objectives After completing this lesson, you should be able to do the following: Describe set operators Use a set operator to combine multiple queries into a single query Control
More informationQuerying 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 informationTable 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 informationIntroduction to Functions and Variables
Introduction to Functions and Variables Functions are a way to add additional elements into your OBI Report. They enable you to manipulate data, perform computations and comparisons, and get system information.
More informationDatabase Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 8 Advanced SQL Objectives In this chapter, you will learn: How to use the advanced SQL JOIN operator syntax About the different
More informationOracle 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 informationnormalization 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 informationPractical Workbook Database Management Systems
Practical Workbook Database Management Systems Name : Year : Batch : Roll No : Department: Department of Computer & Information Systems Engineering NED University of Engineering & Technology, Karachi 75270,
More informationChapter 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 informationIntroduction to SQL. SQL is a standard language for accessing and manipulating databases. What is SQL?
Introduction to SQL SQL is a standard language for accessing and manipulating databases. What is SQL? SQL (Structured Query Language) is a standard interactive and programming language for getting information
More informationOracle 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 informationOracle 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 informationInformatics Practices (065) Sample Question Paper 1 Section A
Informatics Practices (065) Sample Question Paper 1 Note 1. This question paper is divided into sections. Section A consists 30 marks. 3. Section B and Section C are of 0 marks each. Answer the questions
More informationSlides 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 informationChapter 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 informationAn Introduction to Structured Query Language
An Introduction to Structured Query Language Alexandra Roatiş David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2016 CS 348 SQL Winter
More informationSQL. Char (30) can store ram, ramji007 or 80- b
SQL In Relational database Model all the information is stored on Tables, these tables are divided into rows and columns. A collection on related tables are called DATABASE. A named table in a database
More informationWhat Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions
What Are Group Functions? Group functions operate on sets of rows to give one result per group. Reporting Aggregated Data Using the Group Functions Maximum salary in table Copyright 2004, Oracle. All rights
More informationDatabase design process
Database technology Lecture 2: Relational databases and SQL Jose M. Peña jose.m.pena@liu.se Database design process 1 Relational model concepts... Attributes... EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS
More informationCreating and Managing Tables Schedule: Timing Topic
9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the
More informationTeradata 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 informationOracle 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 informationOracle 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 informationOracle 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 informationRelational 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 informationOracle 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 informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features
More informationCS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen
CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen LECTURE 10: INTRODUCTION TO SQL FULL RELATIONAL OPERATIONS MODIFICATION LANGUAGE Union, Intersection, Differences (select
More informationCS Week 10 - Page 1
CS 425 Week 10 Reading: 1. Silberschatz, Krth & Sudarshan, Chapter 3.2 3.5 Objectives: 1. T learn mre abut SQL Functins used in queries. Cncepts: 1. SQL Functins Outline: SQL Functins Single rw functins
More informationCOSC 304 Introduction to Database Systems SQL. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general
More informationAn Introduction to Structured Query Language
An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2017 CS 348 (Intro to DB Mgmt) SQL
More informationCSEN 501 CSEN501 - Databases I
CSEN501 - Databases I Lecture 5: Structured Query Language (SQL) Prof. Dr. Slim slim.abdennadher@guc.edu.eg German University Cairo, Faculty of Media Engineering and Technology Structured Query Language:
More informationMiguel Anjo (IT/ADC)
Database Workshop for LHC online/offline developers SQL (2/2) (IT/ADC) Miguel.Anjo@cern.ch http://cern.ch/it-adc (based on Andrea Valassi slides on Advanced SQL) 26 January 2005 Previous tutorials: Database
More informationCS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13
CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible
More informationPBarel@Qualogy.com http://blog.bar-solutions.com About me Patrick Barel Working with Oracle since 1997 Working with PL/SQL since 1999 Playing with APEX since 2003 (mod_plsql) ACE since 2011 OCA since December
More informationInformation Systems. Database System Architecture. Relational Databases. Nikolaj Popov
Information Systems Database System Architecture. Relational Databases Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline
More informationDatabase Management System. * First install Mysql Database or Wamp Server which contains Mysql Databse.
Database Management System * First install Mysql Database or Wamp Server which contains Mysql Databse. * Installation steps are provided in pdf named Installation Steps of MySQL.pdf or WAMP Server.pdf
More informationAn Introduction to Structured Query Language
An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB
More information