Midterm Practical Flashcards
Create a database
CREATE DATABASE databaseName;
Open a database
USE databaseName;
Create a table with attributes
CREATE TABLE employee(
employeeID CHAR(11),
ssn CHAR(11),
name VARCHAR(35),
dob DATE,
CONSTRAINT employee_pk PRIMARY KEY(employeeID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Remove a table within the current database
DROP tableName;
Remove a database
DROP DATABASE databaseName;
DROP DATABASE IF EXISTS test;
View metadata commands
SHOW DATABASES; SHOW TABLES; DESCRIBE tableName;
Run a script
. filepath.sql
INSERT syntax
INSERT INTO tableName
(filedlist) VALUES (valuelist);
SELECT all values
SELECT *
FROM tableName;
Select some values
SELECT attributes_to_include
FROM tableName;
Select with a column alias
SELECT attribute as “longer attribute”
FROM tableName;
WHERE clause syntax
SELECT * | attributes_to_include
FROM tableName
WHERE condition(s);
Logical Operators
NOT, AND, OR
How to find NULL values
SELECT employeeID
FROM employee
WHERE name IS NULL;
INSERT NULL values
INSER INTO tableNAME (test, test2)
VALUES(‘3333’, NULL);