SQL insert, update, delete, join and aggregates Flashcards
How do you add a row to a SQL table?
insert into “name of table to insert to” (“column names separated by commas”)
values (’text values wrapped in single quotes’, number values with literal numbers);
What is a tuple?
In SQL, a list of values is referred to as atuple.
How do you add multiple rows to a SQL table at once?
Data rows can be batch inserted into a database table by specifying more than onetupleof values, separated by commas
How to you get back the row being inserted into a table without a separate select statement?
Keyword returning *;
How do you update rows in a database table?
update “table name”
set “attribute column name” = ‘value’ and no single quotes if it’s a number value
Why is it important to include a where clause in your update statements?
You don’t want to update every row to have the same value (unless that is what you intend to do)
How do you delete rows from a database table?
Keyword delete from
and table name and followed a where
clause!!!! If not, the entire table will be deleted
How do you accidentally delete all rows from a table?
By not specifying where
What is a foreign key?
Is a set of attributes in a table that refers to the primary key of another table. Theforeign keylinks these two tables.
How do you join two SQL tables?
Use the join
keyword followed by “tableName” followed by using
keyword followed by (“foreign key”);
How do you temporarily rename columns or tables in a SQL statement?
Use as
(e.g table_name as
alias_name)
What are some examples of aggregate functions?
max(), avg(), count(), min(),sum(), andevery()
What is the purpose of a group by clause?
Groups only certain rows that the user chooses to perform an action on – apply aggregate functions only on selected rows