Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
31 Cards in this Set
- Front
- Back
Insert into |
INSERT INTO table_name
INSERT INTO table_name (column1,column2,column3,...) |
|
Update |
UPDATE table_name |
|
Like |
SELECT * FROM Customers |
|
Wildcards |
%A substitute for zero or more characters _A substitute for a single character [charlist]Sets and ranges of characters to match [^charlist] |
|
Wildcards |
SELECT * FROM Customers |
|
SELECT Customers.CustomerName, Orders.OrderID |
he INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns. If there are rows in the "Customers" table that do not have matches in "Orders", these customers will NOT be listed. |
|
SELECT Customers.CustomerName, Orders.OrderID |
The LEFT JOIN keyword returns all the rows from the left table (Customers), even if there are no matches in the right table (Orders). |
|
SELECT Orders.OrderID, Employees.FirstName |
The RIGHT JOIN keyword returns all the rows from the right table (Employees), even if there are no matches in the left table (Orders). |
|
Joins |
* INNER JOIN: Returns all rows when there is at least one match in BOTH tables |
|
Select into |
SELECT * |
|
Insert into |
INSERT INTO table2 |
|
Constraints |
* NOT NULL - Indicates that a column cannot store NULL value
* UNIQUE - Ensures that each row for a column must have a unique value * PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or combination of two or more columns) have an unique identity which helps to find a particular record in a table more easily and quickly * FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in another table * CHECK - Ensures that the value in a column meets a specific condition * DEFAULT - Specifies a default value when specified none for this column |
|
Index |
The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading the whole table. |
|
IsNull |
ISNULL(UnitsOnOrder,0) |
|
Sql Functions |
* AVG() - Returns the average value |
|
Sql Scalar Functions |
* UCASE() - Converts a field to upper case
* LCASE() - Converts a field to lower case * MID() - Extract characters from a text field * LEN() - Returns the length of a text field * ROUND() - Rounds a numeric field to the number of decimals specified * NOW() - Returns the current system date and time * FORMAT() - Formats how a field is to be displayed |
|
The HAVING Clause |
The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions. |
|
Union vs Union All |
UNION removes duplicate records (where all columns in the results are the same), UNION ALL does not. |
|
Pivot |
SELECT , [first pivoted column] AS , [last pivoted column] AS FROM PIVOT ( () FOR [] IN ( [first pivoted column], ... [last pivoted column]) ) AS ; |
|
Dynamic Sql |
DECLARE @city varchar(75) |
|
Dynamic Sql EXEC |
DECLARE @sqlCommand varchar(1000) |
|
Dynamic Sql sp_executesql |
DECLARE @sqlCommand nvarchar(1000) |
|
Clustered Index vs Non Clustered Inde |
Clustered Index * Only one per table Both types of index will improve performance when select data with fields that use the index but will slow down update and insert operations. Because of the slower insert and update clustered indexes should be set on a field that is normally incremental ie Id or Timestamp. SQL Server will normally only use an index if its selectivity is above 95%. |
|
Index |
An index is used to speed up the performance of queries. It does this by reducing the number of database data pages that have to be visited/scanned. |
|
Join |
|
|
Given the following tables, representing pilots that can fly planes and planes in a hangar:
create table PilotSkills ( pilot_name char(15) not null, plane_name char(15) not null )
create table Hangar ( plane_name char(15) not null ) Select the names of the pilots who can fly every plane in the hangar. |
select distinct pilot_name from PilotSkills as ps1 where not exists ( select * from hangar where not exists ( select * from PilotSkills as ps2 where ps1.pilot_name = ps2.pilot_name and ps2.plane_name = hangar.plane_name ) ) |
|
in vs exist vs join |
SELECT * FROM tableA WHERE tableA.id IN (SELECT tableB.id FROM tableB WHERE title = 'Analyst');
|
|
in vs exist vs join |
SELECT * FROM tableA WHERE EXISTS (SELECT 1 FROM tableB WHERE title = 'Analyst' AND tableA.id = tableB.id); |
|
in vs exist vs join |
SELECT * FROM tableA JOIN tableB ON tableA.id = tableB.id WHERE tableB.title = 'Analyst'; |
|
in vs exist vs join |
In most cases, EXISTS or JOIN will be much more efficient (and faster) than an IN statement.
|
|
in vs exist vs join |
When using an IN combined with a subquery, the database must process the entire subquery first, then process the overall query as a whole, matching up based on the relationship specified for the IN. With an EXISTS or a JOIN, the database will return true/false while checking the relationship specified. Unless the table in the subquery is very small, EXISTS or JOIN will perform much better than IN. |