SQL Flashcards
What is SQL(Structure Query Language) and how is it different from languages like JavaScript?
JavaScript is used for front end web development while SQL is used for performing operations on database. JavaScript is a procedural ,scripting language. SQL is a declarative language.
How do you retrieve specific columns from a database table?
To select a single column, we specify the column name between SELECT and FROM as follows:
How do you filter rows based on some specific criteria?
where
What are the benefits of formatting your SQL?
Helps us to make the queries more readable and easy to understand.
When the queries are formatted and laid out with proper spacing it comes easy to find the errors in the query and fix the error.
Formatted queries are easy to be passed on to the fellow developers.
Helps in increasing the efficiency of the database transaction system.
Makes it easy to scale and deploy the database system.
What are four comparison operators that can be used in a where clause?
=,< ,> !=
How do you limit the number of rows returned in a result set?
using limit
How do you retrieve all columns from a database table?
To retrieve all columns, use the wild card * (an asterisk)
How do you control the sort order of a result set?
order by
How do you add a row to a SQL table?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;
How do you get back the row being inserted into a table without a separate select statement?
returning *
How do you update rows in a database table?
update “products”
set “price” = 100;
Why is it important to include a where clause in your update statements?
To target specific rows
How do you delete rows from a database table?
delete from “products”
where “productId” = 24
returning *;