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
Correlated sub query
It is dependent on the containing statement from which it references one or more columns
26
Top key word
Top clause is used to limit the number of rows returned by query. It is used in SELECT query
27
In operator
It is used to check if a value exists in the set of values.
28
Not in operator
It is used to check if value does not exist in a set of values
29
All operator
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
Any operator
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
Set Nocount On
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
Rtrim()
It is used to remove trailing spaces(spaces at the end) from a string.
33
Isnull (expression, replacement_value)
This is used to replace NULL values(when expression is evaluated)with a specified replacement value.
34
Object_id()
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
rank()
this function assigns a unique value to each distinct row. but it leaves value gaps between groups
36
dense_rank()
this is same as rank() but does not leave gaps.
37
extract year,month,day seperately from Date
YEAR(date_column), MONTH(date_column),DAY(date_column)
38
syntax to create a view
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
syntax to read from a view
SELECT * FROM [Description];
40
syntax to update a view
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
delete a view
DROP VIEW [Description];
42
how to delete a column from a table
alter table [dbo].[halls]drop column seatId
43
drop a constriant
ALTER TABLE DROP CONSTRAINT