SQL
SQL
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.
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.
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
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.
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.
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.