SQL Deck 2 Flashcards

1
Q

If you wanted to delete information from a table what statement would you use?

A

Truncate [Table Name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the truncate statement used for? What is the key difference between this and your other options to remove data?

A

The Truncate statement is used to delete all data of a certain target in the database.

DROP and TRUNCATE are DDL(Data Definition Language) commands, whereas DELETE is a DML(Data Manipulation Language) command. Therefore DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back. TRUNCATE can be rolled back if wrapped in a transaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the basic parts of a simple TSQL Query

A

They normally begin with a command statement describing the action to take, followed by a clause that describes the target of the command (such as the specific table within a database affected by the command) and finally, a series of clauses that provide additional instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When are “Joins” used?

A

JOINS are used to JOIN tables together with related information when you need data from more than one table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the different type of Joins? (Write examples of each)

A

Inner Join: Select all records from Table A and Table B, where the join condition is met.
Ex: select first_name, last_name, order_date, order_amount
from customers c
inner join orders o
on c.customer_id = o.customer_id

Left Join:Select all records from Table A, along with records from Table B for which the join condition is met (if at all).
Ex:select first_name, last_name, order_date, order_amount
from customers c
left join orders o
on c.customer_id = o.customer_id

Right Join: Select all records from Table B, along with records from Table A for which the join condition is met
Ex:select first_name, last_name, order_date, order_amount
from customers c
right join orders o
on c.customer_id = o.customer_id

Full Join: Select all records from Table A and Table B, regardless of whether the join condition is met or not.
Ex: select first_name, last_name, order_date, order_amount
from customers c
full join orders o
on c.customer_id = o.customer_id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is data normalization?

A

Database normalization is the process of restructuring a relational database in accordance with a series of so-called normal forms. Essentially used to organize a database into tables and columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why would we go through the process of normalizing our data?

A

There are three main reasons to normalize a database. The first is to minimize duplicate data, the second is to minimize or avoid data modification issues, and the third is to simplify queries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many normal forms are there?

A

There are three.
First Normal Form – The information is stored in a relational table with each column containing atomic values. There are no repeating groups of columns.

Second Normal Form – The table is in first normal form and all the columns depend on the table’s primary key.

Third Normal Form – the table is in second normal form and all of its columns are not transitively dependent on the primary key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you declare a variable in TSQL?

A

To assign a value to a variable, use the DECLARE statement.
Ex:
DECLARE @MyAge int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If a stored procedure is too slow how can you enhance the speed?

A

There are many ways to enhance the speed of stored procedures.

  1. SET NOCOUNT ON-SET NOCOUNT ON and can increase performance by decreasing network traffic.SQL Server returns informational messages when running select or DML operations and this can suppress those messages.
  2. Use schema name before objects.
    It helps SQL Server to find the object.

Ex. SELECT EmpID, EmpName, EmpSalary FROM dbo.Employee

3.Use EXISTS () instead of COUNT ()

This SQL optimization technique concerns the use of EXISTS (). If you want to check if a record exists, use EXISTS () instead of COUNT (). While COUNT () scans the entire table. This will give you better performance.

  1. Specify column names instead of using * in SELECT statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a SQL Server?

A

SQL Server is a relational database management system. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly