0% found this document useful (0 votes)
0 views4 pages

SQL

The document provides a comprehensive overview of SQL concepts, including cursors, triggers, SQL injection, and various types of joins. It explains the differences between stored procedures and functions, transaction control commands, and SQL constraints. Additionally, it covers normalization, collation, and data types in SQL, along with performance improvement tips for stored procedures.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

SQL

The document provides a comprehensive overview of SQL concepts, including cursors, triggers, SQL injection, and various types of joins. It explains the differences between stored procedures and functions, transaction control commands, and SQL constraints. Additionally, it covers normalization, collation, and data types in SQL, along with performance improvement tips for stored procedures.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Cursor:
1.A cursor in SQL is a temporary work area created in system memory when a SQL
statement is executed.
2.A SQL cursor is a set of rows together with a pointer that identifies a
current row.
3.It is a database object to retrieve data from a result set one row at a time.

Types:
Implicit Cursor:
1.These types of cursors are generated and used by the system during the
manipulation of a DML query (INSERT, UPDATE, and DELETE).
2.An implicit cursor is also generated by the system when a single row is
selected by a SELECT command.
Explicit Cursor:
1.Explicit cursor is generated by the user using a SELECT command.
2.An explicit cursor contains more than one row, but only one row can be
processed at a time.

2.Triggers:
1.A trigger is a special type of stored procedure that automatically runs when
an event occurs in the database server.
2.DML triggers run when a user tries to modify data through a data manipulation
language (DML) event.
3.DML events are INSERT, UPDATE, or DELETE statements on a table or view.

3.Sql Injection:
1.SQL Injection is a web vulnerability caused by mistakes made by programmers.
2.It allows an attacker to send commands to the database that the website or web
application communicates with.
3.This, in turn, lets the attacker get data from the database or even modify it.

4.Diff bw UNION ALL / UNION:


1.UNION ALL keeps all of the records from each of the original data sets,
2.UNION removes any duplicate records.
3.UNION first performs a sorting operation and eliminates of the records that
are duplicated across all columns before finally
returning the combined data set.

5.Table-valued parameters:
1.Table-valued parameters are declared by using user-defined table types.
2.You can use table-valued parameters to send multiple rows of data to a
Transact-SQL statement or a routine,
such as a stored procedure or function, without creating a temporary table or
many parameters.

6.diff B/W Full join and cross join:


1.A full outer join combines a left outer join and a right outer join.
2.The result set returns rows from both tables where the conditions are met but
returns null columns where there is no match.
3.A cross join is a Cartesian product that does not require any condition to
join tables

7.Temp table:
Temporary tables are stored in tempdb. They work like a regular table in that
you can perform the operations select, insert and delete as for a regular table.
If created inside a stored procedure they are destroyed upon completion of the
stored procedure

8.Clustered index vs Non cluster index


A Clustered index is a type of index in which table records are physically
reordered to match the index will perform sorting in that table only.
You can create only one clustered index in a table like primary key. Clustered
index is as same as dictionary where the data is arranged by alphabetical order.

A Non-Clustered index is a special type of index in which logical order of index


does not match physical stored order of the rows on disk.
The data is stored in one place, and index is stored in another place. Since, the
data and non-clustered index is stored separately,
then you can have multiple non-clustered index in a table.

9.The following commands are used to control transactions:


COMMIT�- the transactional command used to save changes invoked by a transaction
to the database.
ROLLBACK�- to roll back the changes.
undo transactions that have not already been saved to the database.
This command can only be used to undo transactions since the last COMMIT or
ROLLBACK command was issued.
SAVEPOINT�- creates points within the groups of transactions in which to
ROLLBACK.
The RELEASE SAVEPOINT command is used to remove a SAVEPOINT that you have
created.
SET TRANSACTION�- The SET TRANSACTION command can be used to initiate a database
transaction
SET TRANSACTION [ READ WRITE | READ ONLY ];

GO : Its used to separate the batches.

Set Nocount on :
When you use SET NOCOUNT ON, the message that indicates the number of rows that
are affected by the T-SQL statement is not returned as part of the results.
SET NOCOUNT ON prevents SQL Server from sending DONE_IN_PROC message for each
statement in a stored procedure or batch of SQL statements.

Begin & end:


BEGIN and END are used in Transact-SQL to group a set of statements into a
single compound statement,
so that control statements such as IF � ELSE, which affect the performance of
only a single SQL statement, can affect the performance of the whole group.

SP and function:
The function must return a value but in Stored Procedure it is optional. Even a
procedure can return zero or n values.
Functions can have only input parameters for it whereas Procedures can have
input or output parameters.
Functions can be called from Procedure whereas Procedures cannot be called from
a Function.

Inner join - return all the rows when there is a at least one match of the both
tables.

Left join : Return all the rows from left table matched of the right table.
Right join : return all the rows from right table and matched row from left table.
Full join : return all the rows of both tables where there is match of the one
table.

10.Types of two types of ariable available:


Local variable
Global variable
Variables are the object which acts as a placeholder.
Two types of Variable exist: Local and USING SELECT.

11.Sql constraints:
Primary key
Unique key
Foreign key
Index
NotCheck
Check

Primary key:
It contain unique values.
Not allow any null values.
A table can have only one primary key value.
Selection using primary key as clustered index.

Unique key:
Used to prevent duplicate value in a column.
In single table have multiple unique it easy to change or delete.
It allow null values.
Selection using unique as a non clustered index.

Foreign key:
Foreign used to link two tables together.
Foreign key coloumn or combination of columns whose values match primary key in a
different table .

12.Normalization:
Normalization is the process of organizing data into a related table; it also
eliminates redundancy and
increases the integrity which improves performance of the query.
To normalize a database, we divide the database into tables and establish
relationships between the tables.
Collation :
Collation refers to a set of rules that determine how data is sorted and
compared.
Character data is sorted using rules that define the correct character
sequence, with options for specifying case-sensitivity,
accent marks, kana character types and character width. Case sensitivity.

13.SQL Coalesce:
� SQL Coalesce IsNull functions are used to handle NULL values. During the
expression evaluation process the NULL values
are replaced with the user-defined value.
The�SQL Coalesce�function evaluates the arguments in order and always returns first
non-null value from the defined argument list.
SQL NULL�:
SQL NULL is the term used to represent a missing value. A�NULL�value in a table
is a value in a field that appears to be blank. A field with a�NULL�value is a
field with no value.
SQL left outer join�:
SQL left outer join is also known as�SQL left join. Suppose, we want to�join�two
tables: A and B.�
SQL left outer join�returns all rows in the�left�table (A) and all the matching
rows found in the right table (B).
It means the result of the�SQL left join�always contains the rows in
the�left�table.
The�RIGHT JOIN�:
keyword returns all records from the�right�table (table2), and the matched
records from the left table (table1). The result is NULL from the left side, when
there is no match.
The FULL OUTER JOIN :
keyword returns all records when there is a match in left (table1) or right
(table2) table records.
Note: FULL OUTER JOIN can potentially return very large result-sets! Tip: FULL
OUTER JOIN and FULL JOIN are the same.

14.Basic Differences between Stored Procedure and Function in SQL Server:


1.The function must return a value but in�Stored Procedure�it is optional. Even
a procedure can return zero or n values.
2.Functions can have only input parameters for it whereas Procedures can have
input or output parameters.
3.Functions can be called from Procedure whereas Procedures cannot be called
from a Function.

15.How to Increase Performance OF SP:


1.Specify column names instead of using * in SELECT statement. Try to avoid *
2.Avoid temp temporary table. Temporary tables usually increase a query's
complexity.
3.Create Proper Index. Proper indexing will improve the speed of the operations
in the database.
4.Use Join query instead of sub-query and co-related subquery.

16.Diff Datatypes in SQL:


1.Numeric data types such as int, tinyint, bigint, float, real etc.
2.Date and Time data types such as Date, Time, Datetime etc.
3.Character and String data types such as char, varchar, text etc.
4.Unicode character string data types, for example nchar, nvarchar, ntext etc.
5.Binary data types such as binary, varbinary etc.

You might also like