Relational Algebra Cheat Sheet PDF
Relational Algebra Cheat Sheet PDF
Relational Algebra Cheat Sheet PDF
*Must be union compatible: 1) Same number of columns 2) Corresponding columns are of the same variable type
Queries: Insertions:
SELECT INSERT INTO table_name (field1, field2, …fieldN)
● DISTINCT VALUES
(value1, value2, …valueN);
● T.attr, T.attr as attribute
● COUNT(*) Deletions:
● MAX(T.attr), MIN(T.attr), AVG(T.attr) DELETE FROM table_name [WHERE clause]
FROM
● Table T Views:
● Table2 T2 CREATE VIEW view_name(attr1, attr2, …) AS
WHERE SELECT []
● =, !=, >, <, >=, <= FROM []
WHERE []
● [NOT] IN
● [NOT] EXISTS
Procedures: CALL P rocedure(params)
● ANY CREATE PROCEDURE NewChirp(
● ALL new_btag VARCHAR(30),
● LIKE _ (1 char), % (n chars) content VARCHAR(255))
GROUP BY BEGIN
● attribute DECLARE new_cno INT(11);
SET new_cno = (SELECT MAX(cno)+1 FROM C hirp
HAVING
WHERE btag = new_btag);
● condition on grouping INSERT INTO Chirp(btag, cno, content)
VALUES (new_btag, new_cno, content);
END
Alter Table:
DROP COLUMN col_name
DROP PRIMARY KEY
DROP FOREIGN KEY fk_name
Update Table:
UPDATE [LOW_PRIORITY] [IGNORE] table
SET column1 = expression1,
column2 = expression2,
…
[WHERE conditions]
[ORDER BY expression [ASC | DESC]]
[LIMIT number_rows]