0% found this document useful (0 votes)
35 views4 pages

SQL Differences

Difference between
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

SQL Differences

Difference between
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL - DIFFERENTIATIONS

PRIMARY KEY UNIQUE KEY


The unique key serves as a unique
The primary key uniquely identifies
identifier for records when a
each record in the table.
primary key is absent.
Does not allow NULL values Allows NULL values
Multiple unique keys can exist in a
Only one primary key per table
table

COMMIT ROLLBACK
COMMIT permanently saves the
ROLLBACK undo the changes made
changes made by the current
by the current transaction.
transaction.
The transaction can not undo Transaction reaches its previous
changes after COMMIT execution. state after ROLLBACK.

ALTER Command(DDL) UPDATE Command(DML).


Alter command will perform the
Update command will perform on
action on structure level and not
the data level.
on the data level.
ALTER Command is used to add, UPDATE Command is used to
delete, modify the attributes of the update existing records in a
relations (tables) in the database. database.
This command make changes This command makes changes
with table structure. with data inside the table.
DELETE DROP
DROP Command removes named
DELETE Command removes some
elements of schema like
or all tuples/records from a
relations/table, constraints or
relation/table
entire schema.
DELETE is a DML command. DROP is a DDL command.
WHERE clause is used to add
No WHERE clause is available.
filtering.

CHAR VARCHAR
The CHAR is a data type with fixed The VARCHAR is a data type with
length. variable length.
The CHAR uses the entire declared
The VARCHAR does not use the
length even if fewer characters are
entire declared length.
stored in the variable.
The VARCHAR uses only the length
The CHAR loads empty spaces
loaded with characters.

DDL DML

(Data definition language) (Data Manipulation Language)


DDL helps to define the database DML allows you to manage the
structure or schema data stored in the database.
DDL statements affect the whole DML commands only affect one or
table more rows.
Examples: CREATE, ALTER, DROP, Examples: INSERT, UPDATE,
etc. DELETE, etc.
PRIMARY KEY FOREIGN KEY
A foreign key is a column or group
A primary key is used to ensure
of columns in a relational database
data in the specific column is
table that provides a link between
unique
data in two tables.
Only one primary key is allowed in more than one foreign key is
a table. allowed in a table.
It does not allow NULL values. It can also contain NULL values.

CANDIDATE KEY ALTERNATE KEY


All attribute combinations inside a
relation that can serve as primary
A Candidate key that is not primary
key are candidate key as these are
key, is called an alternate key.
candidates for primary key
position
A table may have more than one The alternate Key should be
candidate key. unique.

HAVING WHERE
HAVING Clause can be used with WHERE Clause can be used without
GROUP BY Clause GROUP BY Clause
WHERE Clause can be used with
HAVING Clause can only be used
SELECT, UPDATE, DELETE
with SELECT statement.
statement.
HAVING Clause implements in WHERE Clause implements in row
column operation operations
NATURAL JOIN EQUI JOIN

It joins the tables based on the It joins the tables based on the
same column names and their data equality or matching column values
types. in the associated tables.
It can return all attributes of both
It always returns unique columns tables along with duplicate
in the result set. columns that match the join
condition.

cursor.fetchall() cursor.fetchmany(size)
Fetches all rows from the query Fetches a specified number of rows
result set at once. (size) at a time.
List of tuples (each tuple is a row). List of tuples (each tuple is a row).
Up to size rows; subsequent calls
All rows available from the query.
fetch the next set.

You might also like