What is a relational database?
What is the typical format of a schema?
nameOfTable(Attribute1, Attribute2..)
In relational databases, columns are ___ and rows are ___
In relational databases, columns are attributes and rows are different entities
What does SQL stand for?
Standard query language
What is DDL and which SQL commands fall into it?
Data definition language
- Create/alter/delete databases, tables and their attributes.
What is DML and which SQL commands fall into it?
Data Manipulation Language
- Add/remove/update and query rows in tables Transact-SQL
What is the query for creating a table in a database?
CREATE tableName(attributeName attribute Type, …);
What is the query for creating a database in SQL?
CREATE DATABASE databaseName;
What are the data types in SQL?
INT, FLOAT, CHAR, VARCHAR, DATE, DATETIME, XML, BLOB
What does the UNIQUE keyword mean in SQL?
You can specify that you want some attribute (or set of attributes) to be unique, so all the values in that column must be different. Though this is not commonly used due to primary keys.
What is a primary key?
What is the SQL for a primary key?
CREATE TABLE people (name VARCHAR(20), birthday DATE, CONSTRAINT PK_people PRIMARY KEY (name));
What is a foreign key?
The primary key from another table used to reference things in this table.
- used to link two table together
What is the SQL for a foreign key?
CREATE TABLE staff (employee VARCHAR(20) , staffnum INT, CONSTRAINT FK_staff FOREIGN KEY (employee) REFERENCES people(name));
What is the SQL to delete/drop a database?
DROP DATABASE databaseName;
What is the SQL to delete/drop a table?
DROP TABLE tableName;
What is the SQL for adding an attribute to a table
ALTER TABLE people ADD email VARCHAR(30);
What is the SQL for changing an attribute to a table?
ALTER TABLE people MODIFY email VARCHAR(100)
What is the SQL for removing an attribute to a table?
ALTER TABLE people DROP COLUMN email;
What is the SQL for inserting into a table?
INSERT INTO people VALUES (‘phoebe’, 19, ‘student’)
if the schema is people(name, number, course) how do you insert into the database leaving a field empty in SQL?
INSERT INTO people(name, course) VALUES (‘Danny’, ‘G402’);
What is an SQL injection?
What are 4 common methods for avoiding SQL injection attacks?
What is the SQL command to delete from a table where the person is called John?
DELETE FROM people WHERE name = ‘John’;`