sql Flashcards
What does SQL stand for?
Structured Query Language
What is SQL used for?
Create, maintain, and retrieve a relational database.
What does DDL stand for?
Data Definition Language.
What is DDL used for?
To define the structure of the database. e.g. CREATE TABLE, ADD COLUMN, DROP COLUMN, etc.
What does DML stand for?
Data Manipulation Language.
What is DML used for?
To extract the data from the relations. e.g. SELECT
What form do most SQL queries use?
SELECT L
FROM R
WHERE C
What does the FROM command do?
Specifies which table to select or delete data from.
What is the WHERE clause?
The condition part of a query. Tuples must satisfy the condition in order to match the query.
What does the SELECT clause do in a query?
Tells which attributes of the tuples matching the condition are produced as part of the answer.
What does the keyword AS do?
Allows an alias to be used for column headers. Used in the SELECT clause. e.g. SELECT title AS name.
What are the six comparison operators used in the WHERE clause?
= (equality), <> (not equal to), , <=, >=
What is the concatenation operator in SQL?
||
What is an alternative form of string comparison?
s LIKE p, where s is a string and p is a pattern.
What does % in p do in s LIKE p?
% in p can match any sequence of 0 or more characters in s.
What does _ in p do in s LIKE p?
_ in p matches any one character in s.
What does the ORDER BY clause do?
Presents the tuples produced by a query in sorted order.
What is the default order of ORDER BY?
asc
What does ORDER BY follow in a query?
The WHERE clause or the optional GROUP BY and HAVING clauses.
What does the ADD keyword do?
Adds a column to an existing table. Used with ALTER TABLE. ADD (column1 datatype, column2 datatype)
What does ADD CONSTRAINT do?
Adds a constraint (e.g. PRIMARY KEY) to an existing table. ADD CONSTRAINT constraintName constraint (col1, col2,)
What are the types of constraints available in SQL?
NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT
What are constraints in SQL?
Rules that apply to the data types in a table.
What is the NOT NULL constraint?
Constraint that ensures a column cannot have a NULL value.
What is the UNIQUE constraint?
Constraint that ensures all values in a column are different.
What is the PIMARY KEY constraint?
A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table.
What is the FOREIGN KEY constraint?
Constraint that uniquely identifies a record in another table.
What is the CHECK constraint?
Constraint that ensures all values in a column satisfy a specific condition.
What is the DEFAULT constraint?
Constraint that sets a default value for a column when no value is specified.