Advanced SQL

Total Page:16

File Type:pdf, Size:1020Kb

Advanced SQL AdvSQL Advanced SQL Sources: [Mel02] Melton & Simon: SQL:1999 Understanding Relational Language Components, 2002 [Con02] Connolly & Begg: Database Systems, 3rd ed, 2002 [Gul99] Gulutzan & Pelzer: SQL-99 Complete, Really, 1999 [Cel99] Joe Celko: SQL for Smarties, 2nd ed, 1999 Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Standards, Specs, Implementations, .. See [Con02] • SQL Standards chapter 5 – ANSI X3.135-1986, X3.168-1989 (ESQL), X3.135-1989 (IEF) – ISO/IEC 9075:1992 (SQL-92), 9075:1999 (SQL:1999), 9075:2003 (SQL:2003), 9075:2006 (SQL:2006), .. – FIPS PUB 127-2 (see http://www.ocelot.ca/) • Specifications – IBM SAA / SQL – X/Open • Implementations (dialects) – Vendors: IBM, Oracle, .. • Related standards – ISO IRDS – ISO RDA – X/Open XA Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL:1999 Parts and Conformances (SQL:2003) [Gul99] • Part 1: SQL/Framework - fundamental concepts • Part 2: SQL/Foundation - syntax and operations • Part 3: SQL/Call-Level Interface - function library • Part 4: SQL/Persistent Stored Modules • Part 5: SQL/Host Language Bindings - ESQL – Ada, C, Cobol, Fortran, Mumps, Pascal, PL/I – (note: not included in SQL:2003) • Minimal Conformance – Core SQL Support • Enhanced Conformance – SQL Packages – SQL Flagger Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Parts of SQL:2003 • 9075-1 SQL/Framework • 9075-2 SQL/Foundation • 9075-3 SQL/CLI • 9075-4 SQL/PSM • 9075-9 SQL/MED • 9075-10 SQL/OLB • 9075-11 SQL/Schemata • 9075-13 SQL/JRT • 9075-14 SQL/XML Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL:1999 Packages [Gul99] [Mel02] • Enhanced datetime facility package • Enhanced integrity management package • OLAP facilities package • PSM package • CLI package (call-level interface) • Basic object support package • Enhanced object support package • Active database package • SQL/MM package (multimedia) Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Flagger [Gul99] Flags non-conforming extensions • Core SQL Flagging • Part SQL Flagging • Package SQL Flagging • Syntax Only • Catalog Lookup - syntax and access violations – INFORMATION_SCHEMA (Compare with FIPS-127 flagger) Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Statement Classes [Gul99] • SQL-Schema statements (DDL) – CREATE / ALTER / DROP ... • SQL-data statements (~ DML) – INSERT, UPDATE, DELETE, SELECT, cursor management • SQL-transaction statements – START TRANSACTION, SET TRANSACTION, COMMIT, ... • SQL-control statements – CALL, RETURN • SQL-connection statements – CONNECT, SET CONNECTION, DISCONNECT • SQL-session statements – SET TIME ZONE, SET ROLE, SET SESSION ... • SQL-diagnostics statements – GET DIAGNOSTICS Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Terminology & Concepts ISO SQL-92, SQL:1999: • SQL Environment • SQL Objects • Schema objects hierarchy: [ [catalog.]schema .]object • Connection objects, Session objects • SQL Datatypes • SQL Language Implementation concepts only: • Database, Indexes, ... Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Object name classes • Cluster • Character Set • <AuthorizationID> • Collation • Privilige • Translation • Catalog • Trigger • Schema • Module • Table • SQL-invoked routine • View – procedure • Column – function • Domain and UDT • Constraint and Assertion Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Name class hierarchy (draft) Physical Server DB Instance (Database) Catalog AuthorizationID Schema Domain / UDT Table / View SQL-Routine Trigger Procedure Function Column Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL-92 Definition Schema - just for defining the Information Schema views as part of the standard! Users Check_constraints Schemata Check_table_usage Data_Type_Descriptor Check_column_usage Domains Assertions Tables Table_privileges Views Column_privileges Columns Usage_privileges View_table_usage Character_sets View_column_usage Collations Table_constraints Translation Key_column_usage SQL_languages Referential_constraint Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL-92 Information Schema - Implemetations should provide these DBMS independent views Applicable_Roles Check_constraints Schemata Assertions Data_Type_Privileges Table_privileges Domains Usage_privileges Tables Character_sets Views Collations Columns Translations View_table_usage SQL_Languages View_column_usage SQL_Features Table_constraints … Key_column_usage Referential_constraints Haaga-Helia, Martti Laiho 1997-2007 AdvSQL SQL Datatypes Pre-defined datatypes: Constructed datatypes: • Number types • reference types • Bit String types • locators • Binary String types • row types • Character String types • collection types • Temporal types (arrays) • Boolean types • User-defined types Haaga-Helia, Martti Laiho 1997-2007 AdvSQL … Data types See [Con02] chapter 6 • Boolean data – Boolean • Character data – Char[acter], Character Varying (Varchar), NChar, NVarchar,.. • Bit data – Bit, Bit varying (not included in SQL:2003) • Exact numeric data – Integer, Smallint, Numeric, Decimal • Approximate numeric data – Float, Real, Double precision • Temporal data – Datetime data: Date, Time, Timestamp .. [WITH TIME ZONE] – Interval Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Literals • Character 'some text' • National character [varying] N'ÅäöÆçÐĦ' 'ﻕﺥﺖﺁ'N • Integer 12345 • Smallint 12 • Numeric 1.234 123 • Decimal 1.234 • Float 1.23E3 1.23E-2 • Real 1.23E3 1.23E-2 • Bit [varying] B'01011111' (deleted in 2001) X'5F' Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Integrity Enhancement Feature (IEF) • Required data - Not Null • DOMAIN integrity • Entity integrity (EI) - Primary Key, Unique • Referential integrity (RI) - Foreign Key referential actions ON UPDATE / ON DELETE: – No Action – Cascade – Set NULL – Set Default • Enterprise constraints Assertions Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Create / Alter / Drop object DROP … [ RESTRICT | CASCADE ] CASCADE: Drops also the related objects RESTRICT: Drop command fails if related objects exist Note: implementations may differ Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE DOMAIN Syntax: CREATE DOMAIN <domain name> [AS] <data type> [ DEFAULT <default value> ] [ <domain constraint> ... ] [ COLLATE <collation name> ] <domain constraint> ::= [CONSTRAINT <constraint name> ] CHECK (<predicate> ) [ <constraint attributes> ] <constraint attributes> ::= NOT DEFERRABLE | DEFERRABLE [INITIALLY IMMEDIATE] Note: no implementations in mainstream products! Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE TABLE CREATE [ { GLOBAL | LOCAL} TEMPORARY] TABLE <table_name> ( <table element list> ) [ ON COMMIT {PRESERVE ROWS | DELETE ROWS} ] <table element> ::= <column definition> | < table constraint > | ... [Gul99] p 356 - Haaga-Helia, Martti Laiho 1997-2007 AdvSQL ALTER TABLE • ADD COLUMN ... • DROP COLUMN … [RESTRICT | CASCADE] • ALTER COLUMN .. SET DEFAULT .. • ALTER COLUMN .. DROP DEFAULT • ADD CONSTRAINT • DROP CONSTRAINT … [RESTRICT | CASCADE] See [Con02] 6.2 Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE VIEW [Con02] 6.4 [Gul99] p 376- • Syntax CREATE [RECURSIVE] VIEW <view_name> [ (column_name [, …] ) ] AS <query expression> [WITH [CASCADED | LOCAL] CHECK OPTION ] • Implementations: – View resolution, restrictions, updatablity – Macro: inline replacements – Materialized view into a hidden temporary base table Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Views Advantages Disadvantages • Data independence • Update restrictions • Currency • Structure restrictions – changes reflected immed. • Performance? • Improved Security • Reduced complexity • Convenience • Customization • Data integrity See [Con02] chapter 6.4.7 – With Check Option Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Materialized Views Advantages Disadvantages • Data independence • Update restrictions • Currency • Structure restrictions – changes reflected immed. • Performance? • Improved Security • Reduced complexity • Convenience • Customization • Data integrity See [Con02] chapter 6.4.7 – With Check Option Haaga-Helia, Martti Laiho 1997-2007 AdvSQL CREATE ASSERTION Syntax: CREATE ASSERTION <constraint name> CHECK (<predicate> ) [ <constraint attributes> ] Note: no implementations in mainstream products! Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Numeric Value Functions [Mel02] • ABS ( numeric-value ) • BIT_LENGTH ( string-value ) • OCTET_LENGTH ( string-value ) • CHAR_LEGTH ( character-string ) • CARDINALITY ( collection-value ) • POSITION ( string-value IN string-value ) • EXTRACT ( datetime-field FROM datetime-value ) • EXTRACT ( datetime-field FROM interval-value ) • EXTRACT ( timezone-field FROM datetime-value ) • MOD ( numeric-dividend , numeric-divisor ) Haaga-Helia, Martti Laiho 1997-2007 AdvSQL String Value Functions / Operators [Mel02] • SUBSTRING ( string-value FROM start [ FOR length ] ) • SUBSTRING ( string-value SIMILAR string-value ESCAPE character-value ) • UPPER ( character-string-value ) • LOWER ( character-string-value ) • TRIM ( [ BOTH | LEADING | TRAILING ] character FROM character-string-value ) • TRANSLATE ( character-string-value USING translation ) • CONVERT ( character-string-value USING conversion ) • OVERLAY (string-value PLACING string-value FROM start [ FOR length ] ) • string-value || string-value Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Built-in Scalar Operators/functions • USER • CURRENT_USER • SESSION_USER • SYSTEM_USER • CURRENT_ROLE • CURRENT_PATH Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Datetime Value Functions [Mel02] • CURRENT_DATE • CURRENT_TIME [ ( precision ) ] • CURRENT_TIMESTAMP [ ( precision ) ] • LOCALTIME [ ( precision ) ] • LOCALTIMESTAMP [ ( precision ) ] Haaga-Helia, Martti Laiho 1997-2007 AdvSQL Temporal
Recommended publications
  • Database Concepts 7Th Edition
    Database Concepts 7th Edition David M. Kroenke • David J. Auer Online Appendix E SQL Views, SQL/PSM and Importing Data Database Concepts SQL Views, SQL/PSM and Importing Data Appendix E All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Appendix E — 10 9 8 7 6 5 4 3 2 1 E-2 Database Concepts SQL Views, SQL/PSM and Importing Data Appendix E Appendix Objectives • To understand the reasons for using SQL views • To use SQL statements to create and query SQL views • To understand SQL/Persistent Stored Modules (SQL/PSM) • To create and use SQL user-defined functions • To import Microsoft Excel worksheet data into a database What is the Purpose of this Appendix? In Chapter 3, we discussed SQL in depth. We discussed two basic categories of SQL statements: data definition language (DDL) statements, which are used for creating tables, relationships, and other structures, and data manipulation language (DML) statements, which are used for querying and modifying data. In this appendix, which should be studied immediately after Chapter 3, we: • Describe and illustrate SQL views, which extend the DML capabilities of SQL. • Describe and illustrate SQL Persistent Stored Modules (SQL/PSM), and create user-defined functions. • Describe and use DBMS data import techniques to import Microsoft Excel worksheet data into a database. E-3 Database Concepts SQL Views, SQL/PSM and Importing Data Appendix E Creating SQL Views An SQL view is a virtual table that is constructed from other tables or views.
    [Show full text]
  • 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]
  • SQL Standards Update 1
    2017-10-20 SQL Standards Update 1 SQL STANDARDS UPDATE Keith W. Hare SC32 WG3 Convenor JCC Consulting, Inc. October 20, 2017 2017-10-20 SQL Standards Update 2 Introduction • What is SQL? • Who Develops the SQL Standards • A brief history • SQL 2016 Published • SQL Technical Reports • What's next? • SQL/MDA • Streaming SQL • Property Graphs • Summary 2017-10-20 SQL Standards Update 3 Who am I? • Senior Consultant with JCC Consulting, Inc. since 1985 • High performance database systems • Replicating data between database systems • SQL Standards committees since 1988 • Convenor, ISO/IEC JTC1 SC32 WG3 since 2005 • Vice Chair, ANSI INCITS DM32.2 since 2003 • Vice Chair, INCITS Big Data Technical Committee since 2015 • Education • Muskingum College, 1980, BS in Biology and Computer Science • Ohio State, 1985, Masters in Computer & Information Science 2017-10-20 SQL Standards Update 4 What is SQL? • SQL is a language for defining databases and manipulating the data in those databases • SQL Standard uses SQL as a name, not an acronym • Might stand for SQL Query Language • SQL queries are independent of how the data is actually stored – specify what data you want, not how to get it 2017-10-20 SQL Standards Update 5 Who Develops the SQL Standards? In the international arena, the SQL Standard is developed by ISO/ IEC JTC1 SC32 WG3. • Officers: • Convenor – Keith W. Hare – USA • Editor – Jim Melton – USA • Active participants are: • Canada – Standards Council of Canada • China – Chinese Electronics Standardization Institute • Germany – DIN Deutsches
    [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]
  • Scalable Computation of Acyclic Joins
    Scalable Computation of Acyclic Joins (Extended Abstract) Anna Pagh Rasmus Pagh [email protected] [email protected] IT University of Copenhagen Rued Langgaards Vej 7, 2300 København S Denmark ABSTRACT 1. INTRODUCTION The join operation of relational algebra is a cornerstone of The relational model and relational algebra, due to Edgar relational database systems. Computing the join of several F. Codd [3] underlies the majority of today’s database man- relations is NP-hard in general, whereas special (and typi- agement systems. Essential to the ability to express queries cal) cases are tractable. This paper considers joins having in relational algebra is the natural join operation, and its an acyclic join graph, for which current methods initially variants. In a typical relational algebra expression there will apply a full reducer to efficiently eliminate tuples that will be a number of joins. Determining how to compute these not contribute to the result of the join. From a worst-case joins in a database management system is at the heart of perspective, previous algorithms for computing an acyclic query optimization, a long-standing and active field of de- join of k fully reduced relations, occupying a total of n ≥ k velopment in academic and industrial database research. A blocks on disk, use Ω((n + z)k) I/Os, where z is the size of very challenging case, and the topic of most database re- the join result in blocks. search, is when data is so large that it needs to reside on In this paper we show how to compute the join in a time secondary memory.
    [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]
  • Sql Server to Aurora Postgresql Migration Playbook
    Microsoft SQL Server To Amazon Aurora with Post- greSQL Compatibility Migration Playbook 1.0 Preliminary September 2018 © 2018 Amazon Web Services, Inc. or its affiliates. All rights reserved. Notices This document is provided for informational purposes only. It represents AWS’s current product offer- ings and practices as of the date of issue of this document, which are subject to change without notice. Customers are responsible for making their own independent assessment of the information in this document and any use of AWS’s products or services, each of which is provided “as is” without war- ranty of any kind, whether express or implied. This document does not create any warranties, rep- resentations, contractual commitments, conditions or assurances from AWS, its affiliates, suppliers or licensors. The responsibilities and liabilities of AWS to its customers are controlled by AWS agree- ments, and this document is not part of, nor does it modify, any agreement between AWS and its cus- tomers. - 2 - Table of Contents Introduction 9 Tables of Feature Compatibility 12 AWS Schema and Data Migration Tools 20 AWS Schema Conversion Tool (SCT) 21 Overview 21 Migrating a Database 21 SCT Action Code Index 31 Creating Tables 32 Data Types 32 Collations 33 PIVOT and UNPIVOT 33 TOP and FETCH 34 Cursors 34 Flow Control 35 Transaction Isolation 35 Stored Procedures 36 Triggers 36 MERGE 37 Query hints and plan guides 37 Full Text Search 38 Indexes 38 Partitioning 39 Backup 40 SQL Server Mail 40 SQL Server Agent 41 Service Broker 41 XML 42 Constraints
    [Show full text]
  • SQL Version Analysis
    Rory McGann SQL Version Analysis Structured Query Language, or SQL, is a powerful tool for interacting with and utilizing databases through the use of relational algebra and calculus, allowing for efficient and effective manipulation and analysis of data within databases. There have been many revisions of SQL, some minor and others major, since its standardization by ANSI in 1986, and in this paper I will discuss several of the changes that led to improved usefulness of the language. In 1970, Dr. E. F. Codd published a paper in the Association of Computer Machinery titled A Relational Model of Data for Large shared Data Banks, which detailed a model for Relational database Management systems (RDBMS) [1]. In order to make use of this model, a language was needed to manage the data stored in these RDBMSs. In the early 1970’s SQL was developed by Donald Chamberlin and Raymond Boyce at IBM, accomplishing this goal. In 1986 SQL was standardized by the American National Standards Institute as SQL-86 and also by The International Organization for Standardization in 1987. The structure of SQL-86 was largely similar to SQL as we know it today with functionality being implemented though Data Manipulation Language (DML), which defines verbs such as select, insert into, update, and delete that are used to query or change the contents of a database. SQL-86 defined two ways to process a DML, direct processing where actual SQL commands are used, and embedded SQL where SQL statements are embedded within programs written in other languages. SQL-86 supported Cobol, Fortran, Pascal and PL/1.
    [Show full text]
  • Sql Merge Performance on Very Large Tables
    Sql Merge Performance On Very Large Tables CosmoKlephtic prologuizes Tobie rationalised, his Poole. his Yanaton sloughing overexposing farrow kibble her pausingly. game steeply, Loth and bound schismatic and incoercible. Marcel never danced stagily when Used by Google Analytics to track your activity on a website. One problem is caused by the increased number of permutations that the optimizer must consider. Much to maintain for very large tables on sql merge performance! The real issue is how to write or remove files in such a way that it does not impact current running queries that are accessing the old files. Also, the performance of the MERGE statement greatly depends on the proper indexes being used to match both the source and the target tables. This is used when the join optimizer chooses to read the tables in an inefficient order. Once a table is created, its storage policy cannot be changed. Make sure that you have indexes on the fields that are in your WHERE statements and ON conditions, primary keys are indexed by default but you can also create indexes manually if you have to. It will allow the DBA to create them on a staging table before switching in into the master table. This means the engine must follow the join order you provided on the query, which might be better than the optimized one. Should I split up the data to load iit faster or use a different structure? Are individual queries faster than joins, or: Should I try to squeeze every info I want on the client side into one SELECT statement or just use as many as seems convenient? If a dashboard uses auto refresh, make sure it refreshes no faster than the ETL processes running behind the scenes.
    [Show full text]
  • “A Relational Model of Data for Large Shared Data Banks”
    “A RELATIONAL MODEL OF DATA FOR LARGE SHARED DATA BANKS” Through the internet, I find more information about Edgar F. Codd. He is a mathematician and computer scientist who laid the theoretical foundation for relational databases--the standard method by which information is organized in and retrieved from computers. In 1981, he received the A. M. Turing Award, the highest honor in the computer science field for his fundamental and continuing contributions to the theory and practice of database management systems. This paper is concerned with the application of elementary relation theory to systems which provide shared access to large banks of formatted data. It is divided into two sections. In section 1, a relational model of data is proposed as a basis for protecting users of formatted data systems from the potentially disruptive changes in data representation caused by growth in the data bank and changes in traffic. A normal form for the time-varying collection of relationships is introduced. In Section 2, certain operations on relations are discussed and applied to the problems of redundancy and consistency in the user's model. Relational model provides a means of describing data with its natural structure only--that is, without superimposing any additional structure for machine representation purposes. Accordingly, it provides a basis for a high level data language which will yield maximal independence between programs on the one hand and machine representation and organization of data on the other. A further advantage of the relational view is that it forms a sound basis for treating derivability, redundancy, and consistency of relations.
    [Show full text]
  • Firebird SQL Best Practices
    Firebird SQL best practices Firebird SQL best practices Review of some SQL features available and that people often forget about Author: Philippe Makowski IBPhoenix Email: [email protected] Licence: Public Documentation License Date: 2016-09-29 Philippe Makowski - IBPhoenix - 2016-09-29 Firebird SQL best practices Common table expression Syntax WITH [RECURSIVE] -- new keywords CTE_A -- first table expression’s name [(a1, a2, ...)] -- fields aliases, optional AS ( SELECT ... ), -- table expression’s definition CTE_B -- second table expression [(b1, b2, ...)] AS ( SELECT ... ), ... SELECT ... -- main query, used both FROM CTE_A, CTE_B, -- table expressions TAB1, TAB2 -- and regular tables WHERE ... Philippe Makowski - IBPhoenix - 2016-09-29 Firebird SQL best practices Emulate loose index scan The term "loose indexscan" is used in some other databases for the operation of using a btree index to retrieve the distinct values of a column efficiently; rather than scanning all equal values of a key, as soon as a new value is found, restart the search by looking for a larger value. This is much faster when the index has many equal keys. A table with 10,000,000 rows, and only 3 differents values in row. CREATE TABLE HASH ( ID INTEGER NOT NULL, SMALLDISTINCT SMALLINT, PRIMARY KEY (ID) ); CREATE ASC INDEX SMALLDISTINCT_IDX ON HASH (SMALLDISTINCT); Philippe Makowski - IBPhoenix - 2016-09-29 Firebird SQL best practices Without CTE : SELECT DISTINCT SMALLDISTINCT FROM HASH SMALLDISTINCT ============= 0 1 2 PLAN SORT ((HASH NATURAL)) Prepared in
    [Show full text]
  • Join , Sub Queries and Set Operators Obtaining Data from Multiple Tables
    Join , Sub queries and set operators Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … … Cartesian Products – A Cartesian product is formed when: • A join condition is omitted • A join condition is invalid • All rows in the first table are joined to all rows in the second table – To avoid a Cartesian product, always include a valid join condition in a WHERE clause. Generating a Cartesian Product EMPLOYEES (20 rows) DEPARTMENTS (8 rows) … Cartesian product: 20 x 8 = 160 rows … Types of Oracle-Proprietary Joins – Equijoin – Nonequijoin – Outer join – Self-join Joining Tables Using Oracle Syntax • Use a join to query data from more than one table: SELECT table1.column, table2.column FROM table1, table2 WHERE table1.column1 = table2.column2; – Write the join condition in the WHERE clause. – Prefix the column name with the table name when the same column name appears in more than one table. Qualifying Ambiguous Column Names – Use table prefixes to qualify column names that are in multiple tables. – Use table prefixes to improve performance. – Instead of full table name prefixes, use table aliases. – Table aliases give a table a shorter name. • Keeps SQL code smaller, uses less memory – Use column aliases to distinguish columns that have identical names, but reside in different tables. Equijoins EMPLOYEES DEPARTMENTS Primary key … Foreign key Retrieving Records with Equijoins SELECT e.employee_id, e.last_name, e.department_id, d.department_id, d.location_id FROM employees e, departments d WHERE e.department_id = d.department_id; … Retrieving Records with Equijoins: Example SELECT d.department_id, d.department_name, d.location_id, l.city FROM departments d, locations l WHERE d.location_id = l.location_id; Additional Search Conditions Using the AND Operator SELECT d.department_id, d.department_name, l.city FROM departments d, locations l WHERE d.location_id = l.location_id AND d.department_id IN (20, 50); Joining More than Two Tables EMPLOYEES DEPARTMENTS LOCATIONS … • To join n tables together, you need a minimum of n–1 • join conditions.
    [Show full text]