SQL Flashcards
How do you order by in SQL
ORDER BY DataPublished Desc (autimatically does it by ascending if you dont put desc)
How to create a table
CREATE TABLE TableName
(
Attribute1 INTEGER NOT NULL, PRIMARY KEY
Attribute2 VARCHAR(20) NOT NULL
)
What do you have to include when making a table
Wether it is a primary key, its data type and wether it must be filled in (“not null”)
Obscure data types
CHAR(n), VARCHAR(n), DATE,TIME,CURRENCY
N in char v N in varchar
In char it means it must be that length but in varchar that is just the max length
Alter adding column
Alter Table TableName
ADD attributeX and their datatypesD
Alter deleting collumn
ALTER table tablename
drop column attribute x
Alter modyfying data type of column
ALTER TABLE tablename
modify column attribute x newdatatype
Insert new record into database
INSERT INTO (Column 1m column 2 )
VALUES( value1,value2)
Update record in data base
Update tablename
set column 1=x, column2=y
wheree column x=value
Delete row from table
Delete from table
where columnx=value
nested select
Select firstName, secondName
FROM people
where favfoodID=
(select foodID
FROM foods
where foodname=”cheese”)
Join
Select people. firstname, people, secondmame
from people
join foods on people.favouritefoodID=foods.foodid
where foods.foodname=”cheese”