Lesson 2 - Introduction to SQL Flashcards
A standard language for storing, manipulating and retrieving data in databases.
SQL!
stands for Structured Query Language
ANSI stands for…?
Bonus Tip: SQL is an ANSI standard
AMERICAN NATIONAL STANDARDS INSTITUTE
for defining the database structure and controlling access to the data.
- CREATE
- DROP
- ALTER
DDL (DATA DEFINTION LANGUAGE)
for retrieving and updating data.
* INSERT INTO
* SELECT
* UPDATE
* DELETE
DML (Database Manipulation System)
creates an object ( a table, for example) in the database.
SQL CREATE STATEMENT
CREATE DATABASE database_name;
deletes an object in the databases usually irretrie
SQL DROP STATEMENT
DROP DATABASE database_name;
modifies the structure an existing object in various ways. For example, adding a column to an existing table.
SQL ALTER STATEMENT
ALTER TABLE table_name;
Each column in a database table is required to have a name and a data type.
SQL BASIC DATA TYPES
SQL String Data Types (3)
CHAR
* VARCHAR
* TEXT
CHAR(size) Fixed length is 0-255. Default is 1.
VARCHAR(size) - variable length is 0-65535 characters.
TEXT - holds a string with a maximum length of 65, 535 bytes.
SQL Numeric Data Types (3)
INT
* FLOAT
* BOOLEAN
Boolean - zero is false, and nonzero is true
SQL Date and Time Data Types (4)
DATE
* DATETIME
* TIME
* YEAR
Date format is YYYY-MM-DD
Time format is hh:mm:ss
used to specify rules for the data in a table.
SQL CONSTRAINTS
SQL Constraints contains the…?
- NOT NULL
- UNIQUE
- PRIMARY KEY
- FOREIGN KEY
- CHECK
- DEFAULT
is used to select data from a database.
SQL SELECT STATEMENT
SELECT*FROM table_name
can be used to return only distinct (different) values.
SQL DISTINCT STATEMENT
SELECT DISTINCT column_name1, column_name2 FROM table_name
is used to filter records, (numeric fields should not be enclosed in quotes)
SQL WHERE CLAUSE
SELECT column_name,column_name FROM table_name WHERE condition
The ____ displays a record if both the first condition and the second condtion are true.
AND operator
The ____ displays a record if either the first condition or the second condition is true.
** OR operator**
The ____ keyword is used to sort the result-set by one or more columns.
ORDER BY
The ____ is used in a WHERE clause to search for a specified pattern in a column.
LIKE operator
character that can be used to substitute
WILDCARD
%- A substitute for zero or more characters
_ - A substitute for a single character.
[charlist] - Sets and ranges of characters to match.
[^charlist] or [!charlist] - Matches only a character NOT specified within the brackets.
The ____ operator allows you to specify multiple values in a WHERE clause.
IN
The ____ operator selects values within a range.
BETWEEN
The ____ statement is used to insert new records in a table.
INSERT INTO
The ____ statement is used to update existing records in a table.
UPDATE
duh:0
The ____ statement is used to delete rows in a table.
DELETE
well duh:D
The ____ function returns the number of rows that matches a specified criteria.
COUNT()
The ____ function returns the average value of a a numeric column.
AVG()
The ____ function returns the total sum of a numeric column.
SUM()
The ____ function returns the smallest value of the selected column, while the ____ function returns the largest.
MIN
and
MAX