Basic Flashcards

1
Q

How to declare SQL variable?

A

Declare @temp varchar(100) = ‘’;

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

How to get day name when date is passed as parameter

A

DateName(dw, Order date) => returns name of the day

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

Get number of days between two dates

A

Select Datediff(dd,OrderDate, ship date) +1 from table

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

What is normalization

A

Normalization is a design technique used to remove the redundant data

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

What is 1st normal form

A

The columns of the table should not have separated values. It should be atomic value

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

What is 2nd NF

A

1st NF is satisfied and all non primary key columns should be fully dependent on the primary key.

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

Why use views in SQL

A

Reusability of complex queries.
Security by exposing only required columns of sensitive table data

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

What stored procs can do

A

They can return results, manipulate data

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

Advantages of using stored procs

A

Reusability, improve performance by caching, improve security

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

What is CTE

A

CTE is a named query and to be used in subsequent select statement

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

What funtions in SQL return

A

They return a scalar value

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

What are SQL Triggers

A

These are special kinds of stored procedures, which react to certain actions we make in the database (perform actions when some event happens)

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

Where and having

A

Where introduces a condition on individual rows
Having introduces a condition on aggregation formed by group by

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

Temporary table

A

They are created in TempDB and are automatically deleted as soon as last connection is terminated.

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

Temporary table syntax

A

Create table #EmpDetails (id INT, name VARCHAR(25))

Insert into #EmpDetails values (01,’LALIT’)

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

Clustered index

A

Determines the physical order of the data in the table. Hence we have only one clustered index.by default this is enabled on primary key of table

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

What is order by 1 do?

A

It sorts the results based on the values in column1

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

What union do

A

Union operator combines result sets of two or more select queries into single result set. It returns only distinct rowa

19
Q

What is getdate() does?

A

It returns the current date and time

20
Q

What is convert() used ?

A

Convert() is used to convert from one data type to another type

21
Q

Convert(Date, getdate())

A

It is used to convert current date and time returned by getdate() to just DATE component

22
Q

Datediff(date part, start_date, end_date) does ?

A

It is used to calculate the difference
Based on the date part which can be years, months, days, hours, minutes,seconds

23
Q

Nolock

A

It is used to specify that a query should not acquire shared locks on the data it is reading

24
Q

Non correlated sub query

A

It may be executed alone and does not refer anything from the containing statement

25
Q

Correlated sub query

A

It is dependent on the containing statement from which it references one or more columns

26
Q

Top key word

A

Top clause is used to limit the number of rows returned by query. It is used in SELECT query

27
Q

In operator

A

It is used to check if a value exists in the set of values.

28
Q

Not in operator

A

It is used to check if value does not exist in a set of values

29
Q

All operator

A

It is used to check if the value is satisfied for every value in a set of values. It is generally used in conjunction with a comparison operator like <>all

30
Q

Any operator

A

It is like all operator but it evaluates to true even if a single value is satisfied in a set of values. It is used in conjunction with comparison operators

31
Q

Set Nocount On

A

This command is used to supress the “no of rows affected” message. It can be used in the scenarios to improve the performance of application

32
Q

Rtrim()

A

It is used to remove trailing spaces(spaces at the end) from a string.

33
Q

Isnull (expression, replacement_value)

A

This is used to replace NULL values(when expression is evaluated)with a specified replacement value.

34
Q

Object_id()

A

It is used to retrieve the database object identification number of a specified database object.it takes database object as input . If the object exists then it returns object_id or else it returns NULL

35
Q

rank()

A

this function assigns a unique value to each distinct row. but it leaves value gaps between groups

36
Q

dense_rank()

A

this is same as rank() but does not leave gaps.

37
Q

extract year,month,day seperately from Date

A

YEAR(date_column), MONTH(date_column),DAY(date_column)

38
Q

syntax to create a view

A

CREATE VIEW [Description] AS SELECT C.C_Name, P.P_Name, P.P_ID, P.P_Price, P.P_MAN_DATE, P.P_EXP_DATE
FROM Customer C, Products P ;

39
Q

syntax to read from a view

A

SELECT * FROM [Description];

40
Q

syntax to update a view

A

CREATE OR REPLACE VIEW Description AS
SELECT C.C_Name, P.P_Name, P.P_ID, P.Price, P.P_MAN_DATE,
P.P_EXP_DATE, C_NO
FROM Customer C, Products P;

41
Q

delete a view

A

DROP VIEW [Description];

42
Q

how to delete a column from a table

A

alter table [dbo].[halls]drop column seatId

43
Q

drop a constriant

A

ALTER TABLE <TABLE_NAME> DROP CONSTRAINT <FOREIGN_KEY_NAME></FOREIGN_KEY_NAME></TABLE_NAME>