Outline Overview Relational Data Model

Total Page:16

File Type:pdf, Size:1020Kb

Outline Overview Relational Data Model Relational databases and MySQL Juha Takkinen Outline [email protected] 1. Introduction: Relational data model and SQL 2. Creating tables in Mysql 3. Simple queries and matching 4. Joins and aliasing 5. More about syntax and built-in functions 6. What is NULL? 7. Inserting, deleting and modifying data 8. Views 3 Thanks to José and Vaida for most forof most the slides. José Thanksandto Vaida Overview Relational data model Real world Query Answer IBM Research Laboratory, San Model Jose, California Edgar F. Codd (1970), “A Relational Model of Data for Large Shared Data Database DBMS Processing of Banks”, in Communications of the queries and updates ACM, vol. 13 no. 6, p. 377-387, June 1970 . Access to stored data All data organized into tables Other models, e.g. hierarchical, network, object Physical or object-relational DBMS, XML (back to network database model!) 4 5 1 Relational model concepts Relational database constraints Relation name Attributes Domain Integer String shorter than 30 chars of values Character 400 < x < 8000 M or F ... ... yyyy-mm-dd EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS S SALARY SUPERSSN DNO Ramesh K Narayan 666884444 1962-09-15 … M 38000 333445555 5 EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS S SALARY SUPERSSN DNO Joyce A English 453453453 1972-07-31 … F 25000 333445555 5 Tuples ... Ahmad V Jabbar 987987987 1969-03-29 … M 25000 987654321 4 Ramesh K Narayan 666884444 1962-09-15 … M 38000 333445555 5 James E Borg 888665555 1937-11-10 … M 55000 null 1 Joyce A English 453453453 1972-07-31 … F 25000 333445555 5 Ahmad V Jabbar 987987987 1969-03-29 … M 25000 987654321 4 James E Borg 888665555 1937-11-10 … M 55000 null 1 Relation schema Is not null EMPLOYEE ( FNAME, M, LNAME, SSN, BDATE, ADDRESS, S, SALARY, SUPERSSN, DNO) Relation – set of tuples, Candidate keys Primary key + Database – collection of relations i.e. no duplicates entity integrity constraint Database schema – collection of relation schemas + integrity constraints Unique 6 7 Relational database constraints Integrity constraints Foreign keys + referential integrity constraint (Atomic) domain (or NULL). EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS S SALARY SUPERSSN DNO Key. Ramesh K Narayan 666884444 1962-09-15 … M 38000 333445555 5 Joyce A English 453453453 1972-07-31 … F 25000 333445555 5 NOT NULL. Ahmad V Jabbar 987987987 1969-03-29 … M 25000 987654321 4 James E Borg 888665555 1937-11-10 … M 55000 null 1 Entity integrity: PK is NOT NULL. Referential integrity: FK of R referring to S if domain(FK(R))=domain(PK(S)) DEPARTMENT DNAME DNUMBER MGRSSN MGRSTARTDATE r.FK = s.PK for some s, otherwise NULL. Research 5 333445555 1988-05-22 Administration 4 987654321 1995-01-01 Headquarters 1 888665555 1981-06-19 8 9 2 SQL and MySQL COMPANY schema from book Structured Query Language DDL and DML EMPLOYEE (FNAME, MINIT, LNAME, SSN , BDATE, ADDRESS, SEX, SALARY, SUPERSSN, DNO ) Declarative (what, not how) Originally interface to System R (SEQUEL) DEPT-LOCATIONS (DNUMBER, DLOCATION ) Used in many database systems, e.g. Oracle DEPARTMENT (DNAME, DNUMBER , MGRSSN, http://www.forbes.com/lists/2010/10/ MGRSTARTDATE ) billionaires-2010_Lawrence-Ellison_JKEX.html WORKS-ON (ESSN, PNO , HOURS ) Standard language for relational databases MySQL: Open source DBMS. PROJECT (PNAME, PNUMBER, PLOCATION, DNUM ) Table, row, column = DEPENDENT (ESSN, DEPENDENT-NAME , SEX, = relation, tuple, attribute BDATE, RELATIONSHIP ) 10 11 Optional but necessary if reserved words in table name Creating tables Creating tables CREATE TABLE `<tablename>` ( <colname> <datatype> [<constraint>] , CREATE TABLE works_on ( …, essn integer references emp(ssn) on delete cascade , pno integer , [<constraint>] , hours decimal (3,1), … constraint pk_workson primary key (essn, pno), ); ENGINE=InnoDB DEFAULT CHARSET=latin1; constraint fk_workson foreign key (pno) references data types: integer, decimal(3,1), boolean, varchar(8), proj(pnumber) on delete cascade char(2), date, time, datetime, timestamp, ) ENGINE=InnoDB; enum(‘v1’,’v2’,’v3’), … constraints: not null, primary key, foreign key, unique, check Other: auto_increment 12 13 3 Creating tables Creating tables CONSTRAINT cand_key UNIQUE(FName,LName) CREATE TABLE dependent ( essn integer references emp(ssn) on delete cascade , dependent_name varchar (9) default 'NN', PNum FName LName Office Phone sex varchar (1) check (sex in ('F', 'M')), bdate date , • CREATE TABLE TEACHER ( relationship varchar (8), PNum CHAR(11), constraint pk_dependent primary key (essn, dependent_name)) FName VARCHAR(20) UNIQUE , ENGINE=InnoDB; LName VARCHAR(20), Office CHAR(10) DEFAULT ’CommonRoom’, Phone CHAR(4) NOT NULL , CONSTRAINT pk_TEACHER PRIMARY KEY (PNum), CONSTRAINT fk_TEACHER FOREIGN KEY (Office) REFERENCES OFFICE(ID) ON DELETE CASCADE ON UPDATE SET NULL ) ENGINE=InnoDB; 14 15 Modifying tables Change the definition of a table: add, delete and modify columns and constraints Querying tables ALTER TABLE EMPLOYEE ADD COLUMN JOB VARCHAR(12); ALTER TABLE EMPLOYEE DROP COLUMN ADDRESS CASCADE; SELECT <attribute-list> ALTER TABLE DEPTS-INFO DROP PRIMARY KEY ; ALTER TABLE DEPTS-INFO DROP FOREIGN KEY fk_DEPARTMENT_EMPLOYEE; FROM <table-list> ALTER TABLE DEPTS-INFO ADD CONSTRAINT PK_Dept PRIMARY KEY (Dno) ; WHERE <condition> ; ALTER TABLE TEACHER ADD CONSTRAINT fk_TEACHER FOREIGN KEY (Office) REFERENCES OFFICE(ID) ON DELETE CASCADE ON UPDATE SET NULL; ALTER TABLE EMPLOYEE MODIFY COLUMN ADDRESS VARCHAR(10) DEFAULT attribute-list: R 1.A 1, …, R k.A r ‘None’; ALTER TABLE ACCOUNT CONVERT TO CHARACTER SET latin1 COLLATE Attributes that are required latin1_swedish_ci; table-list: R 1, …, R k Relations that are needed to process the query Delete a table and its definition condition: expression with logical operators (and, or, not) DROP TABLE EMPLOYEE ; and equality, inequality and comparison operators(=, <>, Getting information about the tables >, >=, …); identifies the tuples that should be retrieved SHOW TABLES; DESCRIBE TEACHER; SHOW CREATE TABLE TEACHER; 16 17 4 Simple query Use of * List SSN for all employees List all information about the employees of department 5 SELECT SSN SSN SELECT FNAME, MINIT, LNAME,SSN, BDATE, FROM EMPLOYEE ; 123456789 ADDRESS, SEX, SALARY, SUPERSSN, DNO 333445555 FROM EMPLOYEE 999887777 987654321 WHERE DNO = 5 ; 666884444 453453453 or 987987987 888665555 SELECT * FROM EMPLOYEE 18 WHERE DNO = 5 ; 19 Simple query Exact vs substring matching List last name, birth date and address for all List birth date and address for all employees employees whose name is `Alicia J. Zelaya' whose name contains the substring ‘aya’ SELECT LNAME, BDATE, ADDRESS SELECT BDATE, ADDRESS FROM EMPLOYEE FROM EMPLOYEE Different from WHERE LNAME = ‘%aya %’; WHERE FNAME = ‘ Alicia ’ WHERE LNAME LIKE ‘%aya %’; AND MINIT = ‘ J’ AND LNAME = ‘ Zelaya ’; LNAME BDATE ADDRESS % replaces 0 or more Zel aya 1968-07-19 3321 Castle, Spring, TX LNAME BDATE ADDRESS characters _ replaces a single Nar aya n 1962-09-15 975 Fire Oak, Humble, TX Zelaya 1968-07-19 3321 Castle, Spring, TX character 20 Case insensitive !!! 21 5 Difference wrt Tables as multisets relational model !!! Example SALARY 30000 40000 SQL considers a table as a multi-set (bag), i.e. tuples can List all salaries 25000 occur more than once in a table 43000 Why? SELECT SALARY 38000 25000 Removing duplicates is expensive FROM EMPLOYEE ; User may want information about duplicates 25000 55000 Aggregation operators Exceptions: SALARY The table has a key, i.e. PK or UNIQUE (which is not compulsory). List all salaries without duplicates. Use SELECT DISTINCT instead of SELECT . 30000 40000 SELECT attributes1 FROM tables1 WHERE condition1; UNION SELECT DISTINCT SALARY 25000 SELECT attributes2 FROM tables2 WHERE condition2; 43000 But not if UNION ALL . FROM EMPLOYEE ; 38000 55000 22 23 Foreign key in Primary key in EMPLOYEE DEPARTMENT LNAME DNAME Join. Cartesian product Join. Equijoin LNAME DNO DNAME DNUMBER Smith Research Wong Research Zelaya Research Smith 5 Research 5 Wallace Research Wong 5 Research 5 Narayan Research Zelaya 4 Research 5 List all employees and their English Research List all employees and their Wallace 4 Research 5 Jabbar Research Narayan 5 Research 5 department Borg Research department English 5 Research 5 Smith Administration Jabbar 4 Research 5 Wong Administration Zelaya Administration SELECT LNAME, DNAME Borg 1 Research 5 SELECT LNAME, DNAME Wallace Administration Smith 5 Administration 4 Narayan Administration FROM EMPLOYEE Wong 5 Administration 4 FROM EMPLOYEE English Administration Zelaya 4 Administration 4 Jabbar Administration Wallace 4 Administration 4 Borg Administration INNER JOIN DEPARTMENT Narayan 5 Administration 4 INNER JOIN DEPARTMENT ; Smith Headquarters English 5 Administration 4 Wong Headquarters ON DNO = DNUMBER ; Jabbar 4 Administration 4 Zelaya Headquarters Wallace Headquarters Borg 1 Administration 4 Narayan Headquarters Smith 5 Headquarters 1 English Headquarters Wong 5 Headquarters 1 Jabbar Headquarters Equijoin Zelaya 4 Headquarters 1 Borg Headquarters Wallace 4 Headquarters 1 Result: each tuple in EMPLOYEE is Narayan 5 Headquarters 1 combined with each tuple in DEPARTMENT English 5 Headquarters 1 Jabbar 4 Headquarters 1 Cartesian product Borg 1 Headquarters 1 (result emphasized) 24 25 6 Ambiguous names. Aliasing Join. Self-join Why? Same attribute name used in different relations To increase readability (long relation names) List last name for all employees together with last names of their bosses No alias SELECT LNAME, DNAME FROM EMPLOYEE INNER JOIN
Recommended publications
  • Querying Graph Databases: What Do Graph Patterns Mean?
    Querying Graph Databases: What Do Graph Patterns Mean? Stephan Mennicke1( ), Jan-Christoph Kalo2, and Wolf-Tilo Balke2 1 Institut für Programmierung und Reaktive Systeme, TU Braunschweig, Germany [email protected] 2 Institut für Informationssysteme, TU Braunschweig, Germany {kalo,balke}@ifis.cs.tu-bs.de Abstract. Querying graph databases often amounts to some form of graph pattern matching. Finding (sub-)graphs isomorphic to a given graph pattern is common to many graph query languages, even though graph isomorphism often is too strict, since it requires a one-to-one cor- respondence between the nodes of the pattern and that of a match. We investigate the influence of weaker graph pattern matching relations on the respective queries they express. Thereby, these relations abstract from the concrete graph topology to different degrees. An extension of relation sequences, called failures which we borrow from studies on con- current processes, naturally expresses simple presence conditions for rela- tions and properties. This is very useful in application scenarios dealing with databases with a notion of data completeness. Furthermore, fail- ures open up the query modeling for more intricate matching relations directly incorporating concrete data values. Keywords: Graph databases · Query modeling · Pattern matching 1 Introduction Over the last years, graph databases have aroused a vivid interest in the database community. This is partly sparked by intelligent and quite robust developments in information extraction, partly due to successful standardizations for knowl- edge representation in the Semantic Web. Indeed, it is enticing to open up the abundance of unstructured information on the Web through transformation into a structured form that is usable by advanced applications.
    [Show full text]
  • Alias for Case Statement in Oracle
    Alias For Case Statement In Oracle two-facedly.FonsieVitric Connie shrieved Willdon reconnects his Carlenegrooved jimply discloses her and pyrophosphates mutationally, knavishly, butshe reticularly, diocesan flounces hobnail Kermieher apache and never reddest. write disadvantage person-to-person. so Column alias can be used in GROUP a clause alone is different to promote other database management systems such as Oracle and SQL Server See Practice 6-1. Kotlin performs for example, in for alias case statement. If more want just write greater Less evident or butter you fuck do like this equity Case When ColumnsName 0 then 'value1' When ColumnsName0 Or ColumnsName. Normally we mean column names using the create statement and alias them in shape if. The logic to behold the right records is in out CASE statement. As faceted search string manipulation features and case statement in for alias oracle alias? In the following examples and managing the correct behaviour of putting each for case of a prefix oracle autonomous db driver to select command that updates. The four lines with the concatenated case statement then the alias's will work. The following expression jOOQ. Renaming SQL columns based on valve position Modern SQL. SQLite CASE very Simple CASE & Search CASE. Alias on age line ticket do I pretend it once the same path in the. Sql and case in. Gke app to extend sql does that alias for case statement in oracle apex jobs in cases, its various points throughout your. Oracle Creating Joins with the USING Clause w3resource. Multi technology and oracle alias will look further what we get column alias for case statement in oracle.
    [Show full text]
  • Chapter 11 Querying
    Oracle TIGHT / Oracle Database 11g & MySQL 5.6 Developer Handbook / Michael McLaughlin / 885-8 Blind folio: 273 CHAPTER 11 Querying 273 11-ch11.indd 273 9/5/11 4:23:56 PM Oracle TIGHT / Oracle Database 11g & MySQL 5.6 Developer Handbook / Michael McLaughlin / 885-8 Oracle TIGHT / Oracle Database 11g & MySQL 5.6 Developer Handbook / Michael McLaughlin / 885-8 274 Oracle Database 11g & MySQL 5.6 Developer Handbook Chapter 11: Querying 275 he SQL SELECT statement lets you query data from the database. In many of the previous chapters, you’ve seen examples of queries. Queries support several different types of subqueries, such as nested queries that run independently or T correlated nested queries. Correlated nested queries run with a dependency on the outer or containing query. This chapter shows you how to work with column returns from queries and how to join tables into multiple table result sets. Result sets are like tables because they’re two-dimensional data sets. The data sets can be a subset of one table or a set of values from two or more tables. The SELECT list determines what’s returned from a query into a result set. The SELECT list is the set of columns and expressions returned by a SELECT statement. The SELECT list defines the record structure of the result set, which is the result set’s first dimension. The number of rows returned from the query defines the elements of a record structure list, which is the result set’s second dimension. You filter single tables to get subsets of a table, and you join tables into a larger result set to get a superset of any one table by returning a result set of the join between two or more tables.
    [Show full text]
  • The JOIN Clause
    2.1 The JOIN Clause The Join Clause A JOIN clause allows you to access data from two or more tables in a query. A join links to tables on a common key between the two tables. Usually the primary key on one table is compared to the foreign key on another table using the equals ( = ) sign. This is an equijoin or an inner-join. However, other comparison operators are also valid. If column names from each table in the join have the same name, they must be qualified with the table name or a table alias. Below is a basic example of a SQL statement with an inner join clause using explicit syntax. 1 USE world; 2 SELECT city.name AS "City Name", 3 country.name AS "Country Name" 4 FROM country 6 JOIN city 5 ON city.CountryCode = country. Code; Learning MySQL By Example 1 You could write SQL statements more succinctly with an inner join clause using table aliases. Instead of writing out the whole table name to qualify a column, you can use a table alias. 1 USE world; 2 SELECT ci.name AS "City Name", 3 co.name AS "Country Name" 4 FROM city ci 5 JOIN country co 6 ON ci.CountryCode = co.Code; The results of the join query would yield the same results as shown below whether or not table names are completely written out or are represented with table aliases. The table aliases of co for country and ci for city are defined in the FROM clause and referenced in the SELECT and ON clause: Results: Learning MySQL By Example 2 Let us break the statement line by line: USE world; The USE clause sets the database that we will be querying.
    [Show full text]
  • Using Sqlrender
    Using SqlRender Martijn J. Schuemie 2021-09-15 Contents 1 Introduction 1 2 SQL parameterization 1 2.1 Substituting parameter values . .1 2.2 Default parameter values . .2 2.3 If-then-else . .2 3 Translation to other SQL dialects 3 3.1 Functions and structures supported by translate . .4 3.2 String concatenation . .5 3.3 Table aliases and the AS keyword . .5 3.4 Temp tables . .5 3.5 Implicit casts . .6 3.6 Case sensitivity in string comparisons . .7 3.7 Schemas and databases . .7 3.8 Optimization for massively parallel processing . .8 4 Debugging parameterized SQL 8 5 Developing R packages that contain parameterized SQL 9 1 Introduction This vignette describes how one could use the SqlRender R package. 2 SQL parameterization One of the main functions of the package is to support parameterization of SQL. Often, small variations of SQL need to be generated based on some parameters. SqlRender offers a simple markup syntax inside the SQL code to allow parameterization. Rendering the SQL based on parameter values is done using the render() function. 2.1 Substituting parameter values The @ character can be used to indicate parameter names that need to be exchange for actual parameter values when rendering. In the following example, a variable called a is mentioned in the SQL. In the call to the render function the value of this parameter is defined: sql <- "SELECT * FROM table WHERE id = @a;" render(sql,a= 123) 1 ## [1] "SELECT * FROM table WHERE id = 123;" Note that, unlike the parameterization offered by most database management systems, it is
    [Show full text]
  • Data Warehouse Service
    Data Warehouse Service SQL Error Code Reference Issue 03 Date 2018-08-02 HUAWEI TECHNOLOGIES CO., LTD. Copyright © Huawei Technologies Co., Ltd. 2018. All rights reserved. No part of this document may be reproduced or transmitted in any form or by any means without prior written consent of Huawei Technologies Co., Ltd. Trademarks and Permissions and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd. All other trademarks and trade names mentioned in this document are the property of their respective holders. Notice The purchased products, services and features are stipulated by the contract made between Huawei and the customer. All or part of the products, services and features described in this document may not be within the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements, information, and recommendations in this document are provided "AS IS" without warranties, guarantees or representations of any kind, either express or implied. The information in this document is subject to change without notice. Every effort has been made in the preparation of this document to ensure accuracy of the contents, but all statements, information, and recommendations in this document do not constitute a warranty of any kind, express or implied. Huawei Technologies Co., Ltd. Address: Huawei Industrial Base Bantian, Longgang Shenzhen 518129 People's Republic of China Website: http://www.huawei.com Email: [email protected] Issue 03 (2018-08-02) Huawei Proprietary and Confidential i Copyright
    [Show full text]
  • Odata Common Schema Definition Language (CSDL) JSON Representation Version 4.01 Candidate OASIS Standard 01 28 January 2020
    OData Common Schema Definition Language (CSDL) JSON Representation Version 4.01 Candidate OASIS Standard 01 28 January 2020 This stage: https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/cos01/odata-csdl-json-v4.01-cos01.docx (Authoritative) https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/cos01/odata-csdl-json-v4.01-cos01.html https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/cos01/odata-csdl-json-v4.01-cos01.pdf Previous stage: https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/cs02/odata-csdl-json-v4.01-cs02.docx (Authoritative) https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/cs02/odata-csdl-json-v4.01-cs02.html https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/cs02/odata-csdl-json-v4.01-cs02.pdf Latest stage: https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/odata-csdl-json-v4.01.docx (Authoritative) https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/odata-csdl-json-v4.01.html https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/odata-csdl-json-v4.01.pdf Technical Committee: OASIS Open Data Protocol (OData) TC Chairs: Ralf Handl ([email protected]), SAP SE Michael Pizzo ([email protected]), Microsoft Editors: Michael Pizzo ([email protected]), Microsoft Ralf Handl ([email protected]), SAP SE Martin Zurmuehl ([email protected]), SAP SE Additional artifacts: This prose specification is one component of a Work Product that also includes: • JSON schemas; OData CSDL JSON schema. https://docs.oasis-open.org/odata/odata-csdl- json/v4.01/cos01/schemas/.
    [Show full text]
  • Sql Alias in Where Clause
    Sql Alias In Where Clause Patsy remains sulphuric after Noah yipping ungallantly or castaways any planchet. Wiggling and improvisational Ron never sped someway when Marcio congregates his Sudan. Pitifully remedial, Baird underwrote beehives and supersede polyglots. This is the where clause in sql alias An order by clause, being able to explicitly using clause in sql alias to see that we will be super users. Linux alias command How a create deploy use Linux aliases. Aliases in SQL Little helpers for better SQL Codekabinett. And diverse a column alias in summary WHERE clause because that's standard sql. From clause of the attempt is to generate left outer join ref_gender rg on gb_cat on emp left to discover the in sql? The syntax and try add where clause in? Spark SQL use of alias in keep clause match The following how does food work in hebrew nor damage the water Spark SQLContext or HiveContext. Notice that default, we select a sql alias are aliases in where. It open banking compliant apis with clause in where? Alias Law firm Legal Definition USLegal Inc. 1610 Using a Column Alias Teradata Database. Registry for the flavour of using an alias is applied for the incident itself from which one may have questions or clause in where clause? What should I complain in Alias? Snowflake Regular Expression Alias and ILIKE MS SQL Tips. You assign multiple column alias to new column took the emergency clause by using the AS keyword Let's even a site at the immense example of using SQL column alias to.
    [Show full text]
  • A Dictionary of DBMS Terms
    A Dictionary of DBMS Terms Access Plan Access plans are generated by the optimization component to implement queries submitted by users. ACID Properties ACID properties are transaction properties supported by DBMSs. ACID is an acronym for atomic, consistent, isolated, and durable. Address A location in memory where data are stored and can be retrieved. Aggregation Aggregation is the process of compiling information on an object, thereby abstracting a higher-level object. Aggregate Function A function that produces a single result based on the contents of an entire set of table rows. Alias Alias refers to the process of renaming a record. It is alternative name used for an attribute. 700 A Dictionary of DBMS Terms Anomaly The inconsistency that may result when a user attempts to update a table that contains redundant data. ANSI American National Standards Institute, one of the groups responsible for SQL standards. Application Program Interface (API) A set of functions in a particular programming language is used by a client that interfaces to a software system. ARIES ARIES is a recovery algorithm used by the recovery manager which is invoked after a crash. Armstrong’s Axioms Set of inference rules based on set of axioms that permit the algebraic mani- pulation of dependencies. Armstrong’s axioms enable the discovery of minimal cover of a set of functional dependencies. Associative Entity Type A weak entity type that depends on two or more entity types for its primary key. Attribute The differing data items within a relation. An attribute is a named column of a relation. Authorization The operation that verifies the permissions and access rights granted to a user.
    [Show full text]
  • Anatomy of a SQL Statement
    Anatomy of a SQL Statement Copyright © 2010, Oracle. All rights reserved. Anatomy of a SQL Statement What Will I Learn? In this lesson, you will learn to: • Match projection, selection, and join with their correct functions/ capabilities • Create a basic SELECT statement • Use the correct syntax to display all rows in a table • Use the correct syntax to select specific columns in a table, modify the way data is displayed and/or perform calculations using arithmetic expressions and operators Copyright © 2010, Oracle. All rights reserved. 2 Anatomy of a SQL Statement What Will I Learn? In this lesson, you will learn to (continued): • Formulate queries using correct operator precedence to display desired results • Define a null value • Demonstrate the effect null values create in arithmetic expressions • Construct a query using a column alias Copyright © 2010, Oracle. All rights reserved. 3 Anatomy of a SQL Statement Why Learn It? SELECT is one of the most important, if not the most important keyword in SQL. You use SELECT to retrieve information from the database. When you learn how to use SELECT, you’ve opened the door to the database. sdm_s16_l01_a01 Imagine a database containing information about movies such as title, genre, studio, producer, release date, series, country, language, rating, running time, and so on. What if you only wanted the titles of movies created in India? The SELECT statement allows you to search for specific data. Copyright © 2010, Oracle. All rights reserved. 4 Anatomy of a SQL Statement Tell Me / Show Me SELECT Statement The SELECT statement retrieves information from the database.
    [Show full text]
  • SQL Joins Cheat Sheet
    SQL JOINs Cheat Sheet JOINING TABLES LEFT JOIN JOIN combines data from two tables. LEFT JOIN returns all rows from the left table with matching rows from the right table. Rows without a match are filled with NULLs. LEFT JOIN is also called LEFT OUTER JOIN. TOY CAT toy_id toy_name cat_id cat_id cat_name SELECT * toy_id toy_name cat_id cat_id cat_name 1 ball 3 1 Kitty FROM toy 5 ball 1 1 Kitty 2 spring NULL 2 Hugo LEFT JOIN cat 3 mouse 1 1 Kitty 3 mouse 1 3 Sam ON toy.cat_id = cat.cat_id; 1 ball 3 3 Sam 4 mouse 4 4 Misty 4 mouse 4 4 Misty 2 spring NULL NULL NULL 5 ball 1 whole left table JOIN typically combines rows with equal values for the specified columns.Usually , one table contains a primary key, which is a column or columns that uniquely identify rows in the table (the cat_id column in the cat table). The other table has a column or columns that refer to the primary key columns in the first table (thecat_id column in RIGHT JOIN the toy table). Such columns are foreign keys. The JOIN condition is the equality between the primary key columns in returns all rows from the with matching rows from the left table. Rows without a match are one table and columns referring to them in the other table. RIGHT JOIN right table filled withNULL s. RIGHT JOIN is also called RIGHT OUTER JOIN. JOIN SELECT * toy_id toy_name cat_id cat_id cat_name FROM toy 5 ball 1 1 Kitty JOIN returns all rows that match the ON condition.
    [Show full text]
  • August Rodil Spring 2021 Database Education Officer Deliverable
    August Rodil Spring 2021 Database Education Officer Deliverable Please keep all questions and information on your deliverable when submitting it. Use any method to explain how to solve them: 1. Explain what the 4 major components of the Database course are, why they’re important, and how they relate to each other. Within MIS, there are 3 courses that help teach students the basics of Databases and their structure; Systems Analysis and Design, Database I and Database II. These classes provide 4 major components which are Relational Databases, • Relational Database – Strictly defined, a relational database is “structured to recognize relations among stored items of information.” This is simply a table that displays data into columns and rows while maintaining the connection between attributes or tuples. This table is also a great way to visually reaffirm relationships between tables and see the database in its fullest form. Personally, I have experienced it many times where my Professor would lecture us on the data in a table and I would understand the concepts he was talking about but could not wrap my head around some of the logic behind it. Having a visual aid such as a relational database really helped me understand some of the core mechanics in a database and laid the foundation for learning more about databases. • Structured Query Language (SQL) – There are many computer languages for a database application development project, but MIS courses heavily rely on SQL as the starting language for aspiring Data Scientists. SQL was first released around the mid-1970s but has maintained its popularity and usability to this day.
    [Show full text]