SQL Basics + Manipulation Flashcards
define table
collection of data organized into rows and columns.
relation
another word for a table: collection of data organized into rows and columns.
define column
a set of data values of a particular type
define row
A row is a single record in a table.
“*” character
Wildcard character. It allows you to select every column in a table without having to name each one individually.
most common data types (4)
INTEGER, a positive or negative whole number
TEXT, a text string
DATE, the date formatted as YYYY-MM-DD
REAL, a decimal value
define statement
text that the database recognizes as a valid command.
what do statements end with?
SEMICOLON ;
What does the SELECT statement return?
a new table called the result set.
3 components of a statement
1) Clause/Command: performs a specific task
2) Table Name
3) Parameter: list of columns, data types, or values passed to a clause as an argument
CREATE statements
allow us to create a new table in the database
SELECT statements
fetch data from a database
INSERT statement
inserts a new row into a table.
ALTER TABLE statement
add, delete, or modify columns in an existing table.
also used to add and drop various constraints on an existing table.
ADD COLUMN statement
lets you add a column to the table
syntax for adding a column
ALTER TABLE [talename]
ADD COLUMN [columnname] COLUMN DATA TYPE;
what is NULL?
Represents missing or unknown data
can you add a column at a specific position to a table?
No. by default a new column will always be added to the end of the table.
BUT you can always select columns in any order eg SELECT col3, col5, col2;
an alternative is to reate a new table and add columns in your preferred order.
UPDATE statement
edits a row in a table.
SET command
indicates the column to edit, takes the =
WHERE command
indicates which row(s) to update with the new column value
how is ALTER different from UPDATE?
ALTER modifies columns. Can add, delete, or modify.
UPDATE modifies rows. Can only change them, not add or remove.
UPDATE syntax
UPDATE table name
SET column name = new data
WHERE row name = row specifier
DELETE FROM statement
deletes one or more existing rows from a table