0% found this document useful (0 votes)
152 views

CS404L Lab 2 Assignment

This document contains information about system procedures in SQL Server and differences between stored procedures and functions. It lists 20 common system procedures in SQL Server like sp_addlogin, sp_grantlogin, sp_revokelogin, and sp_droplogin. It then explains key differences between stored procedures and functions such as procedures allowing DML statements while functions only allow SELECT, procedures being pre-compiled while functions are compiled each time, and procedures supporting transactions while functions do not.

Uploaded by

Nilesh Chittem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

CS404L Lab 2 Assignment

This document contains information about system procedures in SQL Server and differences between stored procedures and functions. It lists 20 common system procedures in SQL Server like sp_addlogin, sp_grantlogin, sp_revokelogin, and sp_droplogin. It then explains key differences between stored procedures and functions such as procedures allowing DML statements while functions only allow SELECT, procedures being pre-compiled while functions are compiled each time, and procedures supporting transactions while functions do not.

Uploaded by

Nilesh Chittem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment Lab 2

Roll No : 2012064

1) LIST OF 20 SYSTEM PROCEDURES:

1. sp_addlogin: Creates a new Microsoft SQL Server login that allows a


user to connect to an instance of SQL server using SQL server
authentication.
2. sp_grantlogin: Allows a user or group account to connect to
Microsoft SQL Server using Windows authentication.
3. sp_revokelogin: Removes the login entries from Microsoft SQL Server
for a user or group created with sp_grantlogin or sp_denylogin.
4. sp_password: Adds or changes a password for a Microsoft SQL
Server login.
5. sp_defaultdb: Changes the default database for a login.
6. sp_denylogin: Prevents a user or group from connecting to Microsoft
SQL Server.
7. sp_dropserver: Removes a server from the list of known remote and
linked servers on the local Microsoft SQL Server.
8. sp_droplogin: Removes a Microsoft SQL Server login, preventing
access to SQL Server using that login name.
9. sp_databases: Lists databases that reside in an instance of Microsoft
SQL Server or are accessible through a database gateway.
10.
sp_fkeys: Returns logical foreign key information for the
current environment showing foreign key relationships including
disabled foreign keys.
11.
sp_pkeys: Returns primary key information for a single table
in the current environment.
12.
sp_linkedservers: Returns the list of linked servers defined in
the local server.
13.
sp_primarykeys: Returns the primary key columns, one row
per key column, for the specified remote table.
14.
sp_tables_ex: Returns table information about the tables from
the specified linked server.
15.
sp_attach_db: Attaches a database to a server.
16.
sp_help: Reports information about a database object, a userdefined data type, or a data type supplied by Microsoft SQL Server.
17.
sp_who: Provides information about current Microsoft SQL
Server users and processes.
18.
sp_stored_procedures: Returns a list of stored procedures in
the current environment.
19.
sp_foreignkeys: Returns the foreign keys that reference
primary keys on the table in the linked server.

20.
sp_indexes: Returns index information for the specified
remote table.

2) Differences between stored procedure and a function:

Stored Procedures are pre-compile objects which are compiled for first
time and its compiled format is saved which executes (compiled code)
whenever it is called. But Function is compiled and executed every time
when it is called. For more about stored procedure and function refer the
articles Different types of Stored Procedure and Different types of
Function.

Basic Difference

1. Function must return a value but in Stored Procedure it is optional


(Procedure can return zero or n values).
2. Functions can have only input parameters for it whereas Procedures
can have input/output parameters.
3. Functions can be called from Procedure whereas Procedures cannot
be called from Function.

Advance Difference

1. Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE)


statement in it whereas Function allows only SELECT statement in it.
2. Procedures cannot be utilized in a SELECT statement whereas
Function can be embedded in a SELECT statement.
3. Stored Procedures cannot be used in the SQL statements anywhere
in the WHERE/HAVING/SELECT section whereas Function can be.
4. The most important feature of stored procedures over function is to
retention and reuse the execution plan while in case of function it
will be compiled every time.
5. Functions that return tables can be treated as another rowset. This
can be used in JOINs with other tables.
6. Inline Function can be thought of as views that take parameters and
can be used in JOINs and other Rowset operations.
7. Exception can be handled by try-catch block in a Procedure whereas
try-catch block cannot be used in a Function.

8. We can go for Transaction Management in Procedure whereas we

can't go in Function.

You might also like