Shared Flashcard Set

Details

SQL Flash Cards
Terms from SQL
76
Computer Science
Professional
04/29/2014

Additional Computer Science Flashcards

 


 

Cards

Term

Data Base

Definition
A database is an organized collection of data physically stored on a computer HD.  A particular DB management system (DBMS), such as SQL server, is designed to interact with the physical storage to allow the datbase to capture, store and allow the retrieval of data.  DB's are arranged in schemas, table and columns.
Term
Relational Databases
Definition
A relational database management system (RDMS) is based on a relational model, meaning data is represented and tied together logically through related sets of data ie tables in SQL
Term
SQL
Definition
Stands for structured query language.  It is a standard computer programming syntax or language.  It is designed to allow displaying data stored in a database through queries as well as managing the insertion and deletion of data.  Microsofts version is T-SQL
Term
Multi-Dimensional DataBase
Definition
Often called a Data Warehouse.  This is a format for arranging databases and its tables into a structure that is optimized for data retrieval and reporting.  This structure is essential for online analytical processing (OLAP) structure such as SSAS
Term
OLTP
Definition
Stands for OnLine Transactional Processing.  It is a database structure designed for transactional data entry not reporting of data.  Designed for fast inserting, deleting and updating of data (ie bank accounts)  Reporting services would add/sum the data to produce reports of spending habits and average balances.
Term
Schema
Definition
In database modeling terms, this is the middle layer of organization that SQL supports.  It logically seperate related items in the database.  The top layer (database) can have several schemas and the schema later can have multiple tables.
Term
Table
Definition
The database model layer below schemas. Data is represented and related with other entities called tables.  The tables consist of rows and columns.  The columns can be just attributes or they can be primary or foreign keys 9by which the tables relate/tie together
Term
What is an 'int'?
Definition
It is a type of numeric data, it stores interger values ranging from -2,147,483,648 to 2,147,483,647.  It is 4 bytes in length
Term
What is a tinyint?
Definition
It is a form of numerica data type.  It stores interger values ranging from 0 to 255.  It is 1 byte in length
Term
What is a bigint?
Definition

It is a numeric data type, it stores interger values from

-263 to 263 -1

Term
What is money?
Definition
It is a numeric data type.  Stores monetary values ranging from -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Term
What is smallmoney?
Definition
A form of numeric data type.  It stores monetary values from -214,748.3848 to 214,748,3647
Term
What is decimal (p,s)
Definition
It is a numeric data type.  Stores decimal values of precision (p) and scale (s).  The maximum precision is 38 digits.
Term
What is numeric (p,s)
Definition
A numeric data type.  It is functionally equivalent of decimal
Term
What is a float (n)
Definition
It is a type of numeric data type.  It stores floating point values with precision of 7 digits (when n=24) or 15 digits (when n=53)
Term
What is real?
Definition
A numeric data type.  It is functionally equivalent to float (24)
Term
Name the different data types
Definition
int, tinyint, smallint, bigint, money, smallmoney, decimal, numeric, float and real
Term
What is date
Definition
It is a type of date and time data type. It stores dates between 1/1/0001 and 12/31, 9999
Term
What is datetime
Definition
It is a type of date and time data type.  It stores dates and times between 1/1/1753 and 12/31/9999 with an accuracy of 3.33 MS
Term
What is datetime2
Definition
It is a type of date and time data type.  It stores date and times between 1/1/0001 and 12/31/9999 with an accuracy of 100 NS
Term
What is datetimeoffset
Definition
It is a type of date and time data type.  Stores dates and times with the same precision as datetime2 and also includes an offset from UTC/GMT
Term
What is time?
Definition
It is a type of date and time data type.  It stores times with an accuracy of 100 NS
Term
What is char (n)
Definition
It is a type of character string data type.  Stores n characters.  Length n bytes(where n is in the range of 1-8,000)
Term
What is nchar (n)
Definition
It is a type of character string data type. Stores n Unicode characters.  Length 2n (where n is in the range of 1-4,000)
Term
What is varchar (n)?
Definition
It is a type of character string data type.  Stores approximately n characters The length is actual string length +2 bytes (where n is in the range of 1-8000)
Term
What is varchar (max)
Definition
It is a type of character string data type.  It stores up to 231-1 characters.  The actual string length +2 bytes
Term
What is nvarchar (n)
Definition
It is a type of character string data type.  It stores approximately n characters.  Length is 2* (actual string lengths) +2bytes (where n is in the range of 1-4000)
Term
What is nvarchar (max)
Definition
It is a type of character string data type.  Stores up to ((231-1)/2)-2 characters.  Length 2*(actual string characters) + 2 bytes
Term
What is a bit?
Definition
It is a binary data type. It stores a single bit of data.  there is 1 byte per 8 bit columns in a table
Term
What is a binary (n)
Definition
It is a binary data type..  Stores n bytes of binary data.  Length is n bytes (where n is in the range of 1-8,000)
Term
What is varbinary (n)
Definition
It is a binary data type.  It stores approximately n bytes of binary data.  The actual length +2 bytes
Term
What is a cursor
Definition
It is a binary data type.  It stores a reference to a cursor.  It cannot be used in a table
Term
What is sql_variant?
Definition
It is a binary data type.  It may store any data type other than sql_variant, text, ntext, image and timestamp.  It can be up to 8k bytes
Term
It is a binary data type.
Definition
It is a binary data type. It stores a temporary table (such as a query result)
Term
What is a rowversion
Definition
It is a binary data type.  It stores a value of the database time (a relative number that increments each time you insert or update data in a database.  It is not related to a calendar/clock time)  It has a length of 8 bytes.
Term
What is a uniqueidentifier
Definition
It is a binary data type.  It stores a globally unique identifier.  It has a length of 2 bytes
Term
What is xml?
Definition
It stores formatted XML documents.  It can go up to 2GB.
Term
What is the BI Stack?
Definition

SSAS, SSRS, SSIS,SSMS

SQL Server Analysis Services

SS Reporting Services

SS Integration Service

SS Management Services

 

Term
Common Table Expression 'CTE'
Definition
Temporary result set that you use with another select, update and insert statement
Term
Subquery
Definition
A subquery is a query that is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. A subquery can be used anywhere an expression is allowed. In this example a subquery is used as a column expression named MaxUnitPrice in a SELECT statement.
Term
The 2 types of subqueries
Definition
Correlated and Non-correlated
Term
what is a correlated subquery?
Definition
The inner query references the outer query
Term
what is a non-correlated subquery?
Definition
The query is independent of the outer query
Term
What is a charindex?
Definition
Searches an expression for another expression and returns its starting position if found.
Term
What is a concat?
Definition

Returns a string that is the result of concatenating two or more string values.

CONCAT ( string_value1, string_value2 [, string_valueN ] )

CONCAT takes a variable number of string arguments and concatenates them into a single string. It requires a minimum of two input values; otherwise, an error is raised. All arguments are implicitly converted to string types and then concatenated. Null values are implicitly converted to an empty string. If all the arguments are null, an empty string of type varchar(1) is returned. The implicit conversion to strings follows the existing rules for data type conversions. For more information about data type conversions, see CAST and CONVERT (Transact-SQL).

Term
Difference
Definition

Returns an integer value that indicates the difference between the SOUNDEX values of two character expressions

DIFFERENCE ( character_expression , character_expression )

The integer returned is the number of characters in the SOUNDEX values that are the same. The return value ranges from 0 through 4: 0 indicates weak or no similarity, and 4 indicates strong similarity or the same values.

DIFFERENCE and SOUNDEX are collation sensitive.

 

Term
Format
Definition

Returns a value formatted with the specified format and optional culture in SQL Server 2012. Use the FORMAT function for locale-aware formatting of date/time and number values as strings. For general data type conversions, use CAST or CONVERT.

FORMAT ( value, format [, culture ] )

FORMAT returns NULL for errors other than a culture that is not valid. For example, NULL is returned if the value specified in format is not valid.

FORMAT relies on the presence of .the .NET Framework Common Language Runtime (CLR).

This function will not be remoted since it depends on the presence of the CLR. Remoting a function that requires the CLR would cause an error on the remote server.

Term
What is the Select statement
Definition

It is the SQL command used to retrieve data from a database.

3 things you need to do for a proper SELECT query

  1. The colums you need to retrieve
  2. The table you want to retrieve them from
  3. The conditions (if any) that the data must satisfy

 

Term
What is the WHERE clause
Definition
It allows you to be specific about the types of data you'd like to retrieve from the tables identified in the SELECT...FROM clause.  You may include conditions that each row in the resule set must satisfy
Term
What is the BETWEEN condition
Definition

It allows you to retrieve records that satisfy a range condition

i.e. list of people whose bday is between certain dates

 

ex. WHERE birthdate BETWEEN 'xxxx' and 'xxxx'

Term
NOT condition
Definition

It prevents certain data that you dont want to see.

 

ex. WHERE NOT last_name = 'Jones'

ex WHERE last_name <> 'Jones'

 

 

Term
What are the list conditions?
Definition

When you have a list of values you'd like to search for

 

ex. WHERE last_name IN ('Jones', 'Smith', 'Thomas')

ex Where last_name NOT IN ('Jones', 'Smith', 'Thomas')

Term
Name the wildcard types
Definition

_ Any single character


% Any series of zero or more characters


[a-f] any singer character in the range a-f


[^a-f] any single character not in the range a-f


[abc] Any single character contained in the last (a,b,c)


[^abc] any single character not contained in the list(a,b,c)

Term
Selecting rows with NULL values
Definition

You use this in the WHERE statement as a condition

 

ex. IS NULL and IS NOT NULL

Term
ORDER BY clause
Definition

It is a way to sort your data

 

ex. ORDER BY last_name

 

you can use ASC (ascending) or DESC (Descending)

Term
Summarizing data with aggregate functions
Definition

This allows you to answer more complicated questions about datasets.

 

ex How to come up with number of records that meet a certain condition

Term
What are some common type of Aggregate functions?
Definition

AVG returns the average of the values in a group


Count Returns a count of the number of items in a group


MAX returns the largest value in a group


MIN Returns the smallest value


SUM Returns the sum of all values in the group


STDEV Returns the stat std dev of all values in the group


VAR Returns the stat variance of all values in the grp

Term

Examples of using aggregate functions

 

COUNT

Definition

SELECT COUNT (*)

FROM Students

 

SELECT COUNT(DISTINCTIVE(last_name))

FROM students

 

SELECT DISTINCT(last_name)

FROM students

Term

Examples of using aggregate functions

 

Using minimum, maximum, average, sum values and count

 

Definition

SELECT min(abs), max (abs), avg(abs)

FROM students

 

SELECT sum(abs)

FROM students

WHERE gender = 'male'

Term
The GROUP BY clause
Definition

The GROUP BY statement is used in conjunction with the aggregate functions (like SUM and COUNT) to group the result-set by one or more columns.

 

SELECT gender, avg(abs)

FROM students

GROUP BY gender

Term
Renaming columns
Definition

SELECT gender AS 'Gender'

, min(abs) AS 'Lowest ABS

, max(abs) AS 'Highest Absence'

,avg(abs) AS 'Average Abs'

FROM students

GROUP BY gender

Term
What are the types of JOIN statements?
Definition

INNER JOIN:  allows you to match related records from different tables

 

OUTER JOIN:  Also include  records from one of both tables that do not have corresponding records in the other table

 

Self Joins are a special case in which you join a table with itself to compare records in the same table.

Term
Writing an INNER JOIN
Definition

You creat an INNER JOIN by including the 2 tables in the FROM clause with the INNER JOIN keyword and specifying the join condition using the ON keyword

 

ex. Select x

FROM oldDB

INNER JOIN newDB

ON table=table

Term

What is an OUTER JOIN?

 

Definition
OUTER JOINS create records on tables that do not have any matching results
Term

What are the types of OUTER JOINS?

 

Definition
  • LEFT OUTER JOIN
  • RIGHT OUTER JOIN
  • FULL OUTER JOIN
Term

What is a LEFT OUTER JOIN?

 

Definition

The LEFT OUTER JOIN includes rows that appear in the left table but dont have a matching record in the right table.  It includes both records that have a non matching value for the join attributes and records that have NULL values for the join attributes

 

 

Term
What is a RIGHT OUTER JOIN?
Definition
A RIGHT OUTER JOIN similiar to a LEFT OUTER JOIN but reverse, it matches records  on the right table but no matching record on the left.
Term

What is a FULL OUTER JOIN?

 

Definition
The FULL OUTER JOIN is essentially a combination of the left and right outer join.  The output includes records that appear in either the left or right table.
Term
What is a CASE statement?
Definition

The CASE statement allows you to perform different actions based upon the value of a database column. 

ex. A principal  wanted to expand the absence scoring system

Cases start with CASE and end with END

Students with 2 or fewer absences 'good'

3 to 5 absences 'warning'

6+ violation

ex. Select absence, 'abs rating' = CASE When abs IS NULL THEN 'Good Job!'

 

 

 

Term
What would you use a View for?
Definition

1.  It allows you to limit the data users can access.  ex. you can create a view that returns only certain rows from a table and then grant users permission to access the view

 

2.  Views reduce complexity for end users.  If end users aren't comfortable writing complex SQL queries, you can write the query for them and then hide the complexity of in a view

Term
How do you create a view?
Definition
You start with 'CREATE VIEW'
Term
How do you modify a view?
Definition
Start with 'Modify View'
Term
How do you delete a view?
Definition
use 'DROP VIEW'
Term
What is a clustered index?
Definition
Physically arranges the table in a sorted order according to the chosen field
Supporting users have an ad free experience!