Basics of SQL Flashcards
What does SQL stand for?
Structured Query Language (SQL) - a language for managing data in a RDMS - Relational Database Management System (where related data is grouped together in tables).
What is RDBMS?
RDMS - Relational Database Management System = where related data is grouped together in tables which in turn can be linked by relationships.
What is a PRIMARY KEY and FOREIGN KEY?
Primary key = usually a table column header/field/unique identifier for records stored within the table.
Foreign key is a field (table column header) or collection of fields that refer to the headers/primary key of another table.
Is SQL case sensitive?
No, SQLanguage is not case-sensitive however it is a BEST PRACTICE to always use capitals for KEYWORDS.
How to write a string inside SQL?
Use ‘string’ SINGLE QUOTES.
How would you destroy a database called Flights in SQL?
DROP DATABASE Flights;
How would you create a database called SimpsonsDB?
CREATE DATABASE SimpsonsDB;
How to start working in a database called SevenHells?/Change the active DB to it.
USE SevenHells;
How would you make a table called prime?
CREATE TABLE prime;
Create a SQL table called Animals with a column called Dogs with a INT type of data.
CREATE TABLE Animals (
Dogs INT
);
Add another column/field to the Animals table called CatNames that takes in string values with a maximum string length of 100 chars.
ALTER TABLE Animals
ADD CatNames VARCHAR(100);
Does:
ALTER
TABLE
tableName;
Run the same as:
ALTER TABLE tableName;
Yes! These statements run identically even though they are split over multiples lines as the CLI interpreter reads everything as continuous blocks until there is a ;
Why should every SQL table you make have an ID column/field?
So that if there is the same data on different rows (e.g. two users enter name: Mike, age: 20) then you can tell them apart with the Unique IDentifier column value.
How would you create a table called Painting with a foreign key with a field of: colour linking to a table called anomalies with a field/column of extra?
CREATE TABLE Painting (
colour VARCHAR(20),
FOREIGN KEY (colour)
REFERENCES anomalies(extra)
);
How to add a column called columnName intoto a table called Painting. Add in the values to the column: purple, yellow, red
ALTER TABLE Painting
ADD columnName;
INSERT INTO Painting (columnName)
VALUES (‘purple’), (‘yellow’), (red’);