SQL Basics Flashcards
What is a relational database?
A collection of tables where each table is related to one another in some way
What is a table comprised of?
Columns and rows/records
T/F: The primary key
column can contain duplicate data
False
T/F: The primary key
column can contain null values
False
Insert ‘Baby’ and ‘Domestic’ into a table called ‘departments’ which has two columns
insert into departments values ('Baby', 'Domestic');
Create a table called ‘departments’ with two columns, ‘department’ and ‘division’, which have type ‘varchar(100)’. Make the primary key ‘department’.
create table departments ( department varchar(100), division varchar(100), primary key (department) );
T/F: You can have more than one primary key constraint in a table
False
T/F: You can have multiple columns acting as one primary key
True
What does ; do in a query?
It separates statements in one script
Write a WHERE clause that returns all ‘department’ values that start with ‘F’ and end with ‘e’
WHERE department like ‘F%e’;
Write a WHERE clause that returns all ‘salary’ values greater than 10
WHERE salary > 10;
Write a WHERE clause that returns values where ‘salary’ < 40000 and ‘department’ is either ‘Clothing’ or ‘Pharmacy’
WHERE 'salary' < 40000 AND (department = 'Pharmacy' OR department = 'Clothing');
Write a WHERE clause where ‘department’ does not equal ‘Sports’
WHERE NOT department = ‘Sports’;
What’s another way of writing negative assertion other than NOT?
!= or <>
Write a WHERE clause that returns all emails that are NULL
WHERE email IS NULL;