SQL Notes

SQL is a programming language designed to manipulate and manage data stored in relational databases.


  • A relational database is a database that organizes information into one or more tables.

  • A table is a collection of data organized into rows and columns.

  • A statement is a string of characters that the database recognizes as a valid command.


CREATE TABLE creates a new table.

INSERT INT0 adds a new row to a table.

SELECT queries data from a table

ALTER TABLE changes an existing table.

UPDATE edits a row in a table.

DELETE FROM deletes rows from a table.


COMPARISON OPERATORS

  • = equal to

  • != not equal to

  • > greater than

  • < less than

  • >= greater than or equal to

  • <= less than or equal to


Ascending (ASC)

  • Sorts data from the smallest value to the largest. 

  • For numbers, this is from lowest to highest

  • For text, this is from A to Z. 

  • For dates, this is from the earliest to the latest.  

Descending (DESC)

  • Sorts data from the largest value to the smallest.

  • For numbers, this is from highest to lowest

  • For text, this is from Z to A.

  • For dates, this is from the latest to the earliest. 



PRIMARY KEY - A field that uniquely identifies each row, generally as ID or numbers. 


FOREIGN KEYS - Often easy to spot because they generally have nothing to do with the table that they are in. However, for purposes of linking them they are placed like that.