SQL For Dummies

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5
At a glance
Powered by AI
The key takeaways are the different SQL concepts covered like normal forms, data types, functions and predicates.

The different normal forms in SQL are first normal form (1NF), second normal form (2NF) and third normal form (3NF). They aim to ensure tables are designed to reliably hold data and prevent anomalies.

The different data types in SQL include exact numerics, approximate numerics, binary strings, boolean, character strings, datetimes and intervals.

SQL For Dummies Cheat Sheet - For Dummies

http://www.dummies.com/how-to/content/sql-for-dummies-cheat-sheet.na...

Cheat Sheet

SQL For Dummies


From SQL For Dummies, 7th Edition by Allen G. Taylor
This Cheat Sheet consists of several helpful tables and lists, containing information that comes up repeatedly when working with SQL. In one place, you can get a quick answer to a number of different questions that frequently arise during an SQL development effort.

SQL Criteria for Normal Forms


To ensure that database tables are designed in such a way that they will hold your data reliably, you need to be sure that they are not subject to modification anomalies. Normalizing your databases will give you that assurance. Compare the SQL criteria in the following list to the tables in your database. Doing so will alert you to the possibility of anomalies, when you find that your database is not sufficiently normalized. First Normal Form (1NF): Table must be two-dimensional, with rows and columns. Each row contains data that pertains to one thing or one portion of a thing. Each column contains data for a single attribute of the thing being described. Each cell (intersection of row and column) of the table must be singlevalued. All entries in a column must be of the same kind. Each column must have a unique name. No two rows may be identical. The order of the columns and of the rows does not matter. Second Normal Form (2NF): Table must be in first normal form (1NF). All nonkey attributes (columns) must be dependent on the entire key. Third Normal Form (3NF): Table must be in second normal form (2NF). Table has no transitive dependencies. Domain-Key Normal Form (DK/NF): Every constraint on the table is a logical consequence of the definition of keys and domains.

1 of 5

4/5/2013 7:42 PM

SQL For Dummies Cheat Sheet - For Dummies

http://www.dummies.com/how-to/content/sql-for-dummies-cheat-sheet.na...

SQL Data Types


Heres a list of all the formal data types that ISO/IEC standard SQL recognizes. In addition to these, you may define additional data types that are derived from these. Exact Numerics: INTEGER SMALLINT BIGINT NUMERIC DECIMAL Approximate Numerics: REAL DOUBLE PRECISION FLOAT Binary Strings: BINARY BINARY VARYING BINARY LARGE OBJECT Boolean: BOOLEAN Character Strings: CHARACTER CHARACTER VARYING (VARCHAR) CHARACTER LARGE OBJECT NATIONAL CHARACTER NATIONAL CHARACTER VARYING NATIONAL CHARACTER LARGE OBJECT Datetimes: DATE TIME WITHOUT TIMEZONE TIMESTAMP WITHOUT TIMEZONE TIME WITH TIMEZONE TIMESTAMP WITH TIMEZONE Intervals: INTERVAL DAY INTERVAL YEAR Collection Types:
2 of 5

4/5/2013 7:42 PM

SQL For Dummies Cheat Sheet - For Dummies

http://www.dummies.com/how-to/content/sql-for-dummies-cheat-sheet.na...

ARRAY MULTISET Other Types: ROW XML

SQL Value Functions


These SQL value functions perform operations on data. There are all kinds of operations that could conceivably be performed on data items, but these are some that are needed most often.

String Value Functions


Function SUBSTRING SUBSTRING SIMILAR SUBSTRING_REGEX Effect Extracts a substring from a source string Extracts a substring from a source string, using POSIX-based regular expressions Extracts from a string the first occurrence of an XQuery regular expression pattern and returns one occurrence of the matching substring Extracts from a string the first or every occurrence of an XQuery regular expression pattern and replaces it or them with an XQuery replacement string Converts a character string to all uppercase Converts a character string to all lowercase Trims off leading or trailing blanks Transforms a source string from one character set to another Transforms a source string from one character set to another

TRANSLATE_REGEX

UPPER LOWER TRIM TRANSLATE

CONVERT

Numeric Value Functions


Function POSITION Effect Returns the starting position of a target string within a source string Returns the number of characters in a string Returns the number of octets (bytes) in a character string Extracts a single field from a datetime or interval

CHARACTER_LENGTH OCTET_LENGTH

EXTRACT

3 of 5

4/5/2013 7:42 PM

SQL For Dummies Cheat Sheet - For Dummies

http://www.dummies.com/how-to/content/sql-for-dummies-cheat-sheet.na...

Datetime Value Functions


Function CURRENT_DATE CURRENT_TIME(p) Effect Returns the current date Returns the current time; (p) is precision of seconds Returns the current date and the current time; (p) is precision of seconds

CURRENT_TIMESTAMP(p)

SQL Set Functions


The SQL set functions give you a quick answer to questions you may have about the characteristics of your data as a whole. How many rows does a table have? What is the highest value in the table? What is the lowest? These are the kinds of questions that the SQL set functions can answer for you. COUNT MAX MIN SUM AVG Returns the number of rows in the specified table Returns the maximum value that occurs in the specified table Returns the minimum value that occurs in the specified table Adds up the values in a specified column Returns the average of all the values in the specified column

SQL WHERE Clause Predicates


Predicates boil down to either a TRUE or a FALSE result. You can filter out unwanted rows from the result of an SQL query by applying a WHERE clause whose predicate excludes the unwanted rows.

Comparison Predicates
= <> < <= > >= Equal Not equal Less than Less than or equal Greater than Greater than or equal

Other Predicates
ALL DISTINCT IN BETWEEN EXISTS LIKE

4 of 5

4/5/2013 7:42 PM

SQL For Dummies Cheat Sheet - For Dummies

http://www.dummies.com/how-to/content/sql-for-dummies-cheat-sheet.na...

MATCH NOT LIKE OVERLAPS SOME, ANY

NOT IN NULL SIMILAR UNIQUE

Other Predicates
ALL DISTINCT IN MATCH NOT LIKE OVERLAPS SOME, ANY BETWEEN EXISTS LIKE NOT IN NULL SIMILAR UNIQUE

Copyright 2013 & Trademark by John Wiley & Sons, Inc. All rights reserved.

5 of 5

4/5/2013 7:42 PM

You might also like