What does sql stand for
Structured Query Language
What is a relational database
A database that stores data in tables (rows + columns) with relationships via keys.
How do you create a database in SQL?
CREATE DATABASE dbname;
What does dropping a database do? DROP dbname
Permanently deletes the entire database and all tables.
What is a table in SQL
A structure of rows (records) and columns (fields)
How do you create a table in SQL
CREATE TABLE tableName ( columns… );
What does SELECT * do?
Selects all rows and all columns in a table
How do you select specific columns in SQL
SELECT col1, col2 FROM tableName;
What is the purpose of the where clause
Filters rows based on a condition.
Give an example of using the where clause employees have an hourly_pay greater than equal to 15
SELECT *
FROM employees
WHERE hourly_pay >= 15;
Name 3 SQL composition operators
=, != (or <>), <, >, >=, <=, IS NULL, IS NOT NULL.
How do you insert one row into a table in SQL
INSERT INTO table VALUES (…);
How do you insert multiple rows into a table in SQL
INSERT INTO table
VALUES (…),
(…),
(…);
How do you insert only specific columns?
INSERT INTO table (col1, col2) VALUES (…);
How do you update a single column in a table in SQL?
UPDATE table
SET col = value
WHERE condition;
Why must every UPDATE or DELETE include a WHERE clause?
Without it, all rows in the table will be modified or removed.
What is COMMIT used for?
Saves the current transaction permanently.
What is ROLLBACK used for?
Undoes all changes since the last COMMIT.
What do CURRENT_DATE(), CURRENT_TIME(), and NOW() return?
Today’s date, the current time, and current date + time.
What does the UNIQUE constraint ensure?
All values in the column must be different.
What does the NOT NULL constraint ensure?
The column cannot contain NULL values.
show how to implement NOT NULL and UNIQUE into a new table
CREATE TABLE products(
product _id INT, product_name VARCHAR (25)UNIQUE AND NOTNULL,
price DECIMAL (4, 2)
What does a check constraint too
Restricts what values are allowed in a column.
Give an example of adding a names check constraint
*CREATE TABLE employees (
employee_id INT,
first_name VARCHAR (50),
last _name VARCHAR(50),
hourly_pay DECIMAL (5, 2),
hire_date DATE,
CONSTRAINT chk hourly pay CHECK (hourly pay >= 10.00) );