Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Question1

Temporary Stored Procedures - SQL Server supports two types of temporary procedures:

Local temporary procedure

Global temporary procedure

Local temporary:

A local temporary procedure is visible only to the connection that created it.

Local temporary procedures are automatically dropped at the end of the current session.

Global temporary:

A global temporary procedure is available to all connections.

Global temporary procedures are dropped at the end of the last session using the
procedure. Usually, this is when the session that created the procedure ends.

Temporary procedures named with # and ## can be created by any user.

are created and stored in the master database and have the sp_ prefix.(or
System stored procedures
xp_) System stored procedures can be executed from any database without having to qualify the
stored procedure name fully using the database name master.

- One or more stored procedures can execute


Automatically Executing Stored Procedures
automatically when SQL Server starts. The stored procedures must be created by the system
administrator and executed under the sysadmin fixed server role as a background process.
The procedure(s) cannot have any input parameters.

Que2

Que3

System Stored Procedures

Many of your administrative activities in Microsoft SQL Server 2000 are performed through
a special kind of procedure known as a system stored procedure. System stored procedures are
created and stored in the master database and have the sp_ prefix. System stored procedures can
be executed from any database without having to qualify the stored procedure name fully using
the database name master.
It is strongly recommended that you do not create any stored procedures using sp_ as a prefix.
SQL Server always looks for a stored procedure beginning with sp_ in this order:

1. The stored procedure in the master database.

2. The stored procedure based on any qualifiers provided (database name or owner).

3. The stored procedure using dbo as the owner, if one is not specified.

Therefore, although the user-created stored procedure prefixed with sp_ may exist in the current
database, the master database is always checked first, even if the stored procedure is qualified
with the database name.

Que4

The fact that the stored procedure plan is cached in memory and not on disk means
that it will fall out of the cache on a server restart or due to low re-use. It can also
fall out of cache if the data on which the procedure depends changes enough to
cause the statistics to be invalidated. This causes SQL Server to invalidate the plan.

Que5

Factors in Recompilation

Inserting or deleting lots of data (data density in indexes & tables often controls query
plans)

Rebuilding indexes (a change to underlying objects)

Creating/dropping temp tables (again, underlying DML changes).

query plan ages out (think not used recently and sql want's to clean up memory use)

Que6

Recompile a Stored Procedure

There are three ways to do this: WITH RECOMPILE option in the procedure definition
or when the procedure is called, the RECOMPILE query hint on individual
statements, or by using the sp_recompile system stored procedure

Que7
RAISERROR is used to return messages back to applications using the same format as a system
error or warning message generated by the SQL Server Database Engine.

RAISERROR can return either:

A user-defined error message that has been created using the sp_addmessage system
stored procedure. These are messages with a message number greater than 50000 that can
be viewed in the sys.messages catalog view.

A message string specified in the RAISERROR statement.

DECLARE @DBID INT;


SET @DBID = DB_ID();

DECLARE @DBNAME NVARCHAR(128);


SET @DBNAME = DB_NAME();

RAISERROR
(N'The current database ID is:%d, the database name is: %s.',
10, -- Severity.
1, -- State.
@DBID, -- First substitution argument.
@DBNAME); -- Second substitution argument.
GO

Categories

(1) Basic SQL


Each record has a unique identifier or primary key. SQL, which stands for Structured Query
Language, is used to communicate with a database. Through SQL one can create and delete
tables. Here are some commands:

CREATE TABLE - creates a new database table

ALTER TABLE - alters a database table

DROP TABLE - deletes a database table

CREATE INDEX - creates an index (search key)

DROP INDEX - deletes an index

SQL also has syntax to update, insert, and delete records.


SELECT - get data from a database table

UPDATE - change data in a database table

DELETE - remove data from a database table

INSERT INTO - insert new data in a database table

(2) PL/SQL

PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's


procedural language extension for SQL and the Oracle relational database. PL/SQL is available
in Oracle Database (since version 7), TimesTen in-memory database (since version 11.2.1), and
IBM DB2 (since version 9.7).[1] Oracle Corporation usually extends PL/SQL functionality with
each successive release of the Oracle Database.

PL/SQL includes procedural language elements such as conditions and loops. You can declare
constants and variables, procedures and functions, types and variables of those types, and
triggers. You can handle exceptions (runtime errors). Arrays are supported involving the use of
PL/SQL collections. Implementations from version 8 of Oracle Database onwards have included
features associated with object-orientation. You can create PL/SQL unitsprocedures, functions,
packages, types, and triggers that are stored in the database for reuse by applications that use
any of the Oracle Database programmatic interfaces.

(3) MySQL

MySQL, the most popular Open Source SQL database management system, is developed,
distributed, and supported by Oracle Corporation.

(4) Post gre SQL

PostgreSQL is a powerful, open source object-relational database system. It has more than 15
years of active development and a proven architecture that has earned it a strong reputation for
reliability, data integrity, and correctness. It runs on all major operating systems, including
Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It is
fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored
procedures (in multiple languages). It includes most SQL:2008 data types, including INTEGER,
NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP. It also
supports storage of binary large objects, including pictures, sounds, or video. It has native
programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others,
and exceptional documentation.
(4) Sybase (Sybase was founded in 1984)

Sybase, an SAP company, is an enterprise software and services company offering software to
manage, analyze, and mobilize information, using relational databases, analytics and data
warehousing solutions and mobile applications development platforms.

(5) SQL Server

Microsoft SQL Server is a relational database management system developed by Microsoft. As


a database, it is a software product whose primary function is to store and retrieve data as
requested by other software applications, be it those on the same computer or those running on
another computer across a network (including the Internet).

(6) Common Queries

Create, insert, update, joins, add, drop, order by, having, alter

You might also like