1. Advantages and
Disadvantages of Stored Procedure
Stored procedure can be used as a modular programming –
means create once, store and call for several times whenever required.
This supports faster execution instead of executing multiple
queries. This reduces network traffic and provides better security to the data.
Disadvantage is
that it can be executed only in the Database and utilizes more memory in the
database server.
2. What are different SQL statement
There are 3 types of SQL
statements
1) DDL (Data Definition Language): It is used
to define the database structure such as tables. It includes three statements
such as Create, Alter, and Drop.
Some of the DDL Commands are listed below
CREATE: It is used for creating the table.
CREATE TABLE table_name
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
ALTER: The ALTER table is used for modifying the existing
table object in the database.
ALTER TABLE table_name
ADD column_name datatype
ALTER TABLE table_name
DROP COLUMN column_name
2) DML (Data
Manipulation Language): These statements are used to manipulate the data in
records. Commonly used DML statements are Insert, Update, and Delete.
The Select statement is used as partial DML statement that
is used to select all or relevant records in the table.
3) DCL (Data Control
Language): These statements are used to set privileges such as Grant and
Revoke database access permission to the specific user.
What are different
JOINS used in SQL?
·
Right Join
·
Outer Join
·
Full Join
·
Cross Join
·
Self Join
3. What is SQL
Injection?
SQL Injection is a type of database attack technique where
malicious SQL statements are inserted into an entry field of database such that
once it is executed the database is opened for an attacker. This technique is
usually used for attacking Data-Driven Applications to have an access to
sensitive data and perform administrative tasks on databases.
4. What is the
difference between DELETE and TRUNCATE?
The basic difference in both is DELETE is DML command and
TRUNCATE is DDL
DELETE is used to delete a specific row from the table
whereas TRUNCATE is used to remove all rows from the table
We can use DELETE with WHERE clause but cannot use TRUNCATE
with it
5. What is the
difference between DROP and TRUNCATE?
TRUNCATE removes all rows from the table which cannot be
retrieved back, DROP removes the entire table from the database and it cannot
be retrieved back.
6. What is Trigger?
Ans. Trigger allows us to execute a batch of SQL code when a
table event occurs (Insert, update or delete command executed against a
specific table)
A SQL trigger is a special type of stored procedure. It is
special because it is not called directly like a stored procedure. The main
difference between a trigger and a stored procedure is that a trigger is called
automatically when a data modification event is made against a table whereas a
stored procedure must be called explicitly.
7. Advantages of using
SQL triggers
SQL triggers provide an alternative way to check the
integrity of data.
SQL triggers provide an alternative way to run scheduled
tasks. By using SQL triggers, you don’t have to wait to run the scheduled tasks
because the triggers are invoked automatically before or after a change is made
to the data in the tables.
SQL triggers are very useful to audit the changes of data in
tables.
Types of Trigger
DDL Triggers
In SQL Server we can create triggers on DDL statements (like
CREATE, ALTER, and DROP) and certain system defined stored procedures that
perform DDL-like operations.
DML Triggers
In SQL Server we can create triggers on DML statements (like
INSERT, UPDATE, and DELETE) and stored procedures that perform DML-like
operations. DML Triggers are of two types
After Trigger (using
FOR/AFTER CLAUSE)
This type of trigger fires after SQL Server finish the
execution of the action successfully that fired it.
Instead of Trigger
(using INSTEAD OF CLAUSE)
This type of trigger fires before SQL Server starts the
execution of the action that fired it. This is differ from the AFTER trigger,
which fires after the action that caused it to fire. We can have an INSTEAD OF
insert/update/delete trigger on a table that successfully executed but does not
include the actual insert/update/delete to the table.
8. What are the
properties of a transaction?
ACID (an acronym for Atomicity, Consistency
Isolation, Durability) is a concept that Database Professionals generally look
for when evaluating databases and application architectures. For a reliable
database all these four attributes should be achieved.
Atomicity is an all-or-none proposition.
Consistency guarantees that a transaction never
leaves your database in a half-finished state.
Isolation keeps transactions separated from each
other until they’re finished.
Durability guarantees that the database will
keep track of pending changes in such a way that the server can recover from an
abnormal termination.
No comments:
Post a Comment
This is a User Friendly Blog.
Simple Interface and Simple Controls are used.
Post your comments so i can modify blog regarding your wish.