Basics Flashcards

1
Q

Update statement

A

UPDATE
SET =, =
WHERE

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

insert statement

A

INSERT INTO table_name (column1, column2, column3, …)

VALUES (value1, value2, value3, …);

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

Declare variable

A

DECLARE @ =

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

varchar(n)

A

Variable width character string

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

nvarchar(n)

A

Variable width Unicode string

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

Bit

A

Integer that can be 0, 1, or NULL

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

tinyint

A

Allows whole numbers from 0 to 255

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

Smallint

A

Allows whole numbers between -32,768 and 32,767

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

Int

A

Allows whole numbers between -2,147,483,648 and 2,147,483,647

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

bigint

A

Allows whole numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 8 bytes
decimal(p,s)

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

COALESCE()

A

returns the first non-null value in a list

COALESCE(val1, val2, …., val_n)

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

CAST()

A

Converts a value of any type into a specific datatype

CAST(value AS DataType)

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

ISNULL()

A

Checks to see if the first value is null, if so it is the second argument gets returned
ISNULL(expression, value)

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

ISNUMERIC()

A

Returns 1 if the value is a number, otherwise 0

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

CONCAT()

A

Adds two or strings together

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

Create table statement

A
Declare the table name, then list the columns and datatypes
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
17
Q

Create temp table

A

It is the same as a create table statement, the table name should bee declared with #.

18
Q

Primary key

A
The PRIMARY KEY constraint uniquely identifies each record in a table.
you can declare a primary key when creating a table
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
    PRIMARY KEY (column1)
);
19
Q

CONSTRAINT

A

SQL constraints are used to specify rules for data in a table.
Constraints can be specified when the table is created with the CREATE TABLE statement, or after the table is created with the ALTER TABLE statement.
Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table. If there is any violation between the constraint and the data action, the action is aborted.

Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table.

The following constraints are commonly used in SQL:

NOT NULL - Ensures that a column cannot have a NULL value
UNIQUE - Ensures that all values in a column are different
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
FOREIGN KEY - Uniquely identifies a row/record in another table
CHECK - Ensures that all values in a column satisfies a specific condition
DEFAULT - Sets a default value for a column when no value is specified
INDEX - Used to create and retrieve data from the database very quickly

20
Q

CLUSTERED index

A

The rows are stored physically on the disk in the same order as the index. Therefore, there can be only one clustered index.

It is generally faster to read from a clustered index if you want to get back all the columns. You do not have to go first to the index and then to the table.

Writing to a table with a clustered index can be slower, if there is a need to rearrange the data.

21
Q

NON CLUSTERED index

A

There is a second list that has pointers to the physical rows. You can have many non clustered indices, although each new index will increase the time it takes to write new records.

22
Q

ALTER TABLE ADD COLUMN

A

ALTER TABLE table_name

ADD column_name datatype;

23
Q

ALTER TABLE DROP COLUMN

A

ALTER TABLE table_name

DROP COLUMN column_name;

24
Q

Get current date

A

DECLARE @Today date = GETDATE();

25
Q

with (NOLOCK)

A

Allows other operations to be run on the table

26
Q

CTE

A
;WITH  AS
(
  SQL Statement (SELECT...)
)
Only use a CTE if you are going to use it once otherwise us a temp table
27
Q

%

A

Wildcard symbol

WHERE name LIKE ‘%an%’ – returns ‘Dan’, ‘Sandra’

28
Q

IN

A

is equivalent to multiply OR clauses

WHERE column_name IN (value1, value2, …);