A Access control, 165 granting privileges to users general syntax, GRANT, 170 multiple privileges, 171 PostgreSQL, 166 169 relational databases, 165 REVOKE command, 172 173 SQLite, 166 Aggregate functions AVG, 96 casting values, integers, 96 COUNT, 95 MAX and MIN, 98 100 SUM, 97 98 varchar value, 97 Alpha, 187 ALTER TABLE command, 42 43 American National Standards Institute (ANSI), 3 The Art of SQL, 177 Atomicity, 67 68 B Bitmap Heap Scan, 156 Bitmap Scan, 156 C Check constraints, 30 31 Compound queries, 140 Concatenation operator, 89 90 Constraints check, 30 31 NULL (see NULL constraints) primary key, 32 34 relational databases, 25 selective fields INSERT, 28 30 unique key, 34 36 CREATE USER command, 167 Cross joins, 115 117 D Database and database administrators (DBA s), 37 Database Management and Design, 177 Database Management System (DBMS), 1 3, 5, 8 Data Control Language (DCL), 5, 165 Data Definition Language (DDL), 5 Data Dictionary, 185 Rahul Batra 2018 R. Batra, SQL Primer, https://doi.org/10.1007/978-1-4842-3576-8 189
Data Manipulation Language (DML), 5 DELETE command, 63 64 INSERT and SELECT commands, 57 60 UPDATE command, 60 62 Data Query Language (DQL), 5, 21 Data types, 7 9 DB Browser for SQLite, 182 DBeaver, 181 Denormalization, 74 Difference operation EXCEPT operator, 139 IN and NOT IN operators, 138 mathematical, 138 DROP commands, 37 39 DROP TABLE command, 149 E Entry of database systems, 184 185 Equijoin, 111 EXPLAIN command, 154 create index PostgreSQL query, 156 EXPLAIN QUERY PLAN, 157 PostgreSQL query, 155 F File-oriented systems, 183 184 Firebird, 180 Foreign key constraint, 70 G Genesis of relational model, 185 186 GROUP BY clause adding language, 101 102 aggregate functions COUNT, 103 multiple, 104 standard, 104 group records, 100 SELECT clause, 102 Grouping data, see GROUP BY clause H HAVING clause, 105 107 H2 database, 181 Hierarchical database, 185 Homonym, 184 HyperSQL, 180 I ed Sequential Access Method (ISAM), 184 ing CREATE INDEX command, 152 databases, 151 DROP INDEX command, 163 pg_size_pretty function, 162 pg_total_relation_size function, 162 proglang_tbl, 152 190
storage, 161 syntax, 152 table and index size, 162 verification PostgreSQL, 153 SQLite pragma, 154 SQLite schema, 153 visual representation, 160 Information Management System (IMS), 185 Ingres, 186 187 Inner joins, 112 Integrated Data Store (IDS), 185 Intersection operation INTERSECT ALL operator, 137 INTERSECT keyword, 136 multiple columns, 137 SQL translation, 136 J, K Joins columns, resolving ambiguity, 112 113 cross, 115 117 equijoin, 111 FROM/WHERE syntax, 111 inner, 112 non-equi, 120 121 normalization, 109 outer, 113 115 self, 118 119 syntax, 111 table aliases, 113 L LIKE operator, 83 85 Literal values, 92 93 Logical data models, 185 M MariaDB, 180 Mathematical calculations creation decade, language, 88 89 operators, 87 remainder operation, 88 N Network data model, 185 Non-equi joins, 120 121 Normalization, 65 66, 74 NULL constraints CREATE TABLE statement, 26 error message, 27 PostgreSQL, 27 selective fields INSERT general syntax, 28 proglang_tblcopy table, 29 30 SQLite, 27 standard field, 26 O Organizing data atomicity, 67 68 normalization, 65 66, 74 191
Organizing data (cont.) repeating groups, 68 69 tables foreign key constraint, 70 referential integrity, 71 72 Outer joins, 113 115 P PostgreSQL, 179 180 Binary Packages, 12 command CREATE DATABASE, 16 DBMS systems, 11 download, latest version, 12 inserting data, 20 21 installation directory, EnterpriseDB, 12 13 port number and password, 13 psql command and output, 13 table creation, 18 19 table information, 43 45 Primary key constraint CREATE TABLE statement, 32 definition, 32 ID fields, 32 proglang_tblcopy table, 33 34 vs. unique key, 36 Primitive set theoretic operations, 133 PUBLIC keyword, 173 Q QUEL, 187 Queries AND operator, 55 56 column aliases, 79 81 counting records, table, 75 77 database administration, 47 DISTINCT with COUNT, 77 79 field abbreviations, 50 51 LIKE operator, 83 85 number of fields, 47 48 ORDER BY clause, 49 50, 82 83 ordering by multiple columns, 51 53 OR operator, 56 SELECT command, 47 48 SELECT evaluation, 82 * selection criteria, 48 WHERE condition, 53 54 Query plan, 155 R Referential integrity, 71 72 Relational algebra, 186 Relational calculus, 186 Relational database management systems Firebird, 180 H2, 181 HyperSQL, 180 MariaDB, 180 PostgreSQL, 179 180 SQLite, 180 192
Repeating groups, 68 69 Resultset, 133 S Self joins, 118 119 Sequential scan, 160 Set theory, 133 Simple SQL query, general syntax, 21 22 SQL Antipatterns, 178 SQL Cookbook, 177 SQLite, 180 column mode, 23 DBMS system, 11 DLL zip archive, 14 download, 14 Fedora Linux system, 15 headers, 23 24 installing, 14 precompiled binaries, 14 shell sqlite3, 15 table creation, 19 20 table information, 45 46 yum, 15 SQL Queries for mere mortals, 176 SQL variants, 175 String operations concatenation operator, 89 90 substring, 91 92 UPPER and LOWER, 92 Structured Query Language (SQL) advantages, 4 commands classification, 5 database, 1 data types, 7 9 DBMS, 1 3, 5, 8 development environments, 181 relational model, 2 4 tables, 5 7 Subqueries ALL operator, 131 132 ANY operator, 129 131 existence tests, 125 126 INSERT statements, 127 128 types, 124 125 row subqueries, 124 scalar subqueries, 124 table subqueries, 124 Substring, 91 92 SystemR project, 186 187 T Tables ALTER TABLE command, 42 43 creating new tables from existing, 39 41 DBA s, 37 DBMS, 46 DROP commands, 37 39 PostgreSQL, 43 45 SQLite, 45 46 Transaction Control Commands, 5 193
U UNION keyword, 134 Union operation, 133 duplicate values, elimination, 135 mathematical, 134 programming languages table, 134 UNION ALL operator, 136 usage, 134 Unique indexes creation, 158 duplicate values, 158 Unique key constraints, 34 36 V, W, X, Y, Z Views advantage, 141 calculated field, 143 creation, 142 data modification aggregate columns, 148 base table checking, 146 calculated field, 147 field value, 149 modified view, 146 non-calculated field, 147 updating value, 145 definition, 141 DROP VIEW command, 149 field renaming, 144 language_chronology, 142 syntax, 142 Virtual Storage Access Method (VSAM), 184 Virtual table, 141 194