Professional Documents
Culture Documents
1 CHAR datatype is used to store character VARCHAR datatype is used to store character string
string of fixed length of variable length
2. In CHAR, If the length of string is less than In VARCHAR, If the length of string is less than set
set or fixed length then it is padded with or fixed length then it will store as it is without
extra memory space. padded with extra memory spaces.
4. Storage size of CHAR datatypes is equal to Storage size of VARCHAR datatype is equal to the
n bytes i.e. set length actual length of the entered string in bytes.
5. We should use CHAR datatype when we We should use VARCHAR datatype when we expect
expect the data values in a column are of the data values in a column are of variable length.
same length.
6. CHAR take 1 byte for each character VARCHAR take 1 byte for each character and some
extra bytes for holding length information
1. The DELETE command is used to delete While this command is used to delete all the rows
specified rows(one or more). from a table.
3. There may be WHERE clause in DELETE While there may not be a WHERE clause in the
command in order to filter the records. TRUNCATE command.
4. In the DELETE command, a tuple is While in this command, data page is locked before
locked before removing it. removing the table data.
5. The DELETE statement removes rows TRUNCATE TABLE removes the data by
one at a time and records an entry in the deallocating the data pages used to store the table data
transaction log for each deleted row. and records only the page deallocations in the
transaction log.
6. DELETE command is slower than While TRUNCATE command is faster than DELETE
TRUNCATE command. command.
7. To use Delete you need DELETE To use Truncate on a table we need at least ALTER
permission on the table. permission on the table.
8. Identity of column retains the identity Identity of the column is reset to its seed value if the
after using DELETE Statement on table. table contains an identity column.
9. The delete can be used with indexed Truncate cannot be used with indexed views.
views.
Clustered index requires less memory for Non-Clustered index requires more memory for
operations. operations.
In clustered index, index is the main data. In Non-Clustered index, index is the copy of data.
A table can have only one clustered index. A table can have multiple non-clustered index.
Clustered index has inherent ability of Non-Clustered index does not have inherent ability of
storing data on the disk. storing data on the disk.
Clustered index store pointers to block not Non-Clustered index store both value and a pointer to
data. actual row that holds data.
In Clustered index leaf nodes are actual data In Non-Clustered index leaf nodes are not the actual
itself. data itself rather they only contains included columns.
In Clustered index, Clustered key defines In Non-Clustered index, index key defines order of data
order of data within table. within index.
1. The DROP command is used to remove table Whereas the TRUNCATE command is used to
definition and its contents. delete all the rows from the table.
2. In the DROP command, table space is freed While the TRUNCATE command does not free
from memory. the table space from memory.
4. In the DROP command, view of table does not While in this command, view of table exist.
exist.
5. In the DROP command, integrity constraints While in this command, integrity constraints will
will be removed. not be removed.
6. In the DROP command, undo space is not While in this command, undo space is used but
used. less than DELETE.
7. The DROP command is quick to perform but While this command is faster than DROP.
gives rise to complications.
1. WHERE Clause is used to filter the records HAVING Clause is used to filter record from
from the table based on the specified condition. the groups based on the specified condition.
2. WHERE Clause can be used without GROUP HAVING Clause cannot be used without
BY Clause GROUP BY Clause
4. WHERE Clause cannot contain aggregate HAVING Clause can contain aggregate
function function
5. WHERE Clause can be used with SELECT, HAVING Clause can only be used with
UPDATE, DELETE statement. SELECT statement.
6. WHERE Clause is used before GROUP BY HAVING Clause is used after GROUP BY
Clause Clause
7. WHERE Clause is used with single row function HAVING Clause is used with multiple row
like UPPER, LOWER etc. function like SUM, COUNT etc.
Aggregate
Aggregate functions are used to operates on data sets of a column of a table in SQL Database and
return a result.
26. Pattern matching operators
Like
Basic In SQL you can execute a single In PL/SQL you can execute a block of code at a
query or a command at a time. time.
Purpose It is like a source of data that is to be It is language that creates an application that
displayed. display's the data acquired by SQL.
Writes In SQL you can write queries and In PL/SQL you can write block of code that has
command using DDL, DML procedures, functions, packages or variables, etc.
statements.
Use Using SQL, you can retrieve, modify, Using PL/SQL, you can create applications or
add, delete, or manipulate the data in server pages that display's the information obtained
the database. from SQL in a proper format.
Embed You can embed SQL statement in You can not embed PL/SQL in SQL
PL/SQL.
Local variable:
● A user declares the local variable.
● By default, a local variable starts with @.
● Every local variable scope has the restriction to the current batch or procedure within any
given session.
Global variable:
31. The system maintains the global variable. A user cannot declare them.
32. The global variable starts with @@
33. It stores session related information.
REPLACE: As the function name replace indicates, the replace function replaces all occurrences
of a specific string value with another string.
Dml commands-
Dcl-
Tcl-
NULL value acceptance Cannot accept NULL values. Can accepts NULL values.
Number of keys that can be Only one primary key More than one unique key
defined in the table
A function has a return type and returns a value. A procedure does not have a return type. But it
returns values using the OUT parameters.
You cannot use a function with Data Manipulation You can use DML queries such as insert,
queries. Only Select queries are allowed in functions. update, select etc… with procedures.
A function does not allow output parameters A procedure allows both input and output
parameters.
You cannot manage transactions inside a function. You can manage transactions inside a
procedure.
You cannot call stored procedures from a function You can call a function from a stored
procedure.
You can call a function using a select statement. You cannot call a procedure using select
statements.
The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(),
AVG()) to group the result-set by one or more columns.
54. Diff between views and table
1. A table is used to organize data in the form of Views are treated as a virtual/logical table
rows and columns and displayed them in a used to view or manipulate parts of the table.
structured format. It makes the stored information It is a database object that contains rows and
more understandable to the human. columns the same as real tables.
2. Table is a physical entity that means data is The view is a virtual entity, which means data
actually stored in the table. is not actually stored in the table.
3. It is used to store the data. It is used to extract data from the table.
6. Table allows us to perform DML operations. The view will enable us to perform DML
operations.
7. It is not an easy task to replace the table directly It is an easy task to replace the view and
because of its physical storage. recreate it whenever needs.
8. It occupies space on the systems. It does not occupy space on the systems.