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

5890733369

The document outlines key differences between various SQL concepts, including Primary Key vs. Foreign Key, Candidate Key vs. Alternate Key, and DDL vs. DML. It also explains distinctions between commands like Delete vs. Drop, and functions like Count() vs. Count(*), among others. Each comparison highlights the unique characteristics and use cases of the SQL elements discussed.
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)
5 views4 pages

5890733369

The document outlines key differences between various SQL concepts, including Primary Key vs. Foreign Key, Candidate Key vs. Alternate Key, and DDL vs. DML. It also explains distinctions between commands like Delete vs. Drop, and functions like Count() vs. Count(*), among others. Each comparison highlights the unique characteristics and use cases of the SQL elements discussed.
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

Differences – SQL

1. Differentiate: Primary Key and Foreign Key

Primary Key Foreign Key

1. It is used to uniquely identify a tuple in a 1. It always matches the primary key


relation. column in another table.
2. The primary key column cannot store 2. It is a non-key attribute whose values
duplicate values. are derived from the primary key of
3. Ex: EmpID and Rollno. some other table.
3. Ex: P_ID

2. Differentiate: Primary Key and Candidate Key.

Primary Key Candidate Key

1. Primary Key is a set of one or more 1. All attribute combination inside a


attributes that can uniquely identify relation that can serve as primary key
tuples within the relation. are called as candidate key.
2. It cannot store duplicate values. 2. They are candidates for the primary
key position.

3. Differentiate: Candidate Key and Alternate Key

Candidate Key Alternate Key

1. All attribute combination inside a relation 1. A candidate key that is not the primary
that can serve as primary key are called as key is called Alternate key.
candidate key. 2. In a table two or more candidate keys,
2. They are candidates for the primary key only one of the server as primary key the
position. rest of them are alternate key.

4. Differentiate: DDL and DML

DDL DML

1. It allows performing task related to data 1. It allows manipulating data from the
definition. relation.
2. Using this command we can create, alter 2. Using this command we can manipulate
and drop the schema object (Table) the data from existing schema object
3. Ex: Create, Alter and Drop (Table).
3. Ex: Select, Insert, Update, Delete
5. Differentiate: Alter Command and Update Command.

Alter Command Update Command

1. It is used to add, delete and modify the 1. It is used to update the existing records
attributes (column) of a table. in a table.
2. It will perform the action on structure 2. It will perform the action on data level.
level. 3. It is used to change data into the table.
3. It is used to modify the structure of the 4. It is a DML command
table. 5. Ex: update stu set cs_mark=95 where
4. It is a DDL command. Rollno=105;
5. Ex: alter table stu add email
varchar(25);

6. Differentiate: Delete and Drop.

Delete Command Drop Command


1. Delete removes some or all the records from 1. Drop can remove the column,
the table. constraints or schema from the
2. Using where clause we can filter the records. database.
2. We cannot use where clause.
3. Action performed by delete can be roll- 3. Action performed by drop cannot be
backed. roll-backed.
4. Delete is a DML command. 4. Drop is a DDL command
5. Delete from stu where Rollno=103; 5. Ex: Drop table stu;

7. Differentiate: Count ( ) and Count (*).

Count ( ) Count (*)


1. Count (column name) returns the number 1. Count (*) returns all the rows including
of rows except null value row. column contains null value.
2. It count and returns number of records. 2. It counts the row with null, duplicate
3. Ex: select count(salary) from emp; and non-null values.
3. EX: select count(*) from emp;

8. Differentiate: Order by and Group by.

Order by Group by
1. It is used to sort the records either 1. It is used to group the records that have
ascending or descending order. identical values.
2. Not mandatory to use aggregate function. 2. It is mandatory to use aggregate
3. Result set is stored based on the column function in group by clause.
attribute values either ascending or 3. Grouping is done based on similar
descending order. values among the rows attribute values.
4. Ex: select Empname, Salary from emp 4. Ex: select city, max(salary) from emp
order by Salary desc; group by city;
9. Differentiate: Where Clause and Having Clause.

Where Having
1. It filters the individual rows. 1. It filters the groups of instead of one
2. We cannot use where clause with row at a time.
aggregate function because it works on 2. It works with aggregate functions.
individual row. 3. It handles the column operations to
3. It handles row operation. summarized groups.

10. Differentiate: Commit and Rollback.

Commit Rollback
1. A commit statement is used to save 1. A Rollback statement is used to undo
changes on the current transaction is all the changes.
permanent. 2. Rollback statement occurs when the
2. Commit statement is applied when the transaction is either aborted power
transaction is completed. failure.

11. Differentiate: Single Row Function and Multiple Row Function

Single Row Function Multiple Row Function


1. It works with a single row at a time. 1. It works with data of multiple
2. It returns a result for every row of a rows at a time.
queried table. 2. It returns aggregated value.

12. Differentiate: Char( ) and Varchar () in SQL.

Char ( ) Varchar ( )
1. It is fixed length fields. 1. It is variable length fields.
2. It occupies fixed number of bytes for 2. Length is determined separately for
every data elements. every data elements inside the field.
3. There is wastage of space. 3. There is no wastage of space.
4. Value is shorter than the length blanks 4. Every value stored in column exactly.
space added. 5. Ex: name varchar(20)
5. Ex: name char(10)

13. Differentiate: Primary Key Constraints and Unique Key Constraints.

Primary Key Constraints Unique Key Constraints


1. It is used to check unique values. 1. It is also used to check unique
2. It does not allow null value. values.
2. It allows null value.
14. Differentiate: Delete and Truncate.
Delete Command Truncate Command
1. It will allow for delete single or multiple 1. It will delete entire rows from a
records from the table. table.
2. It allows to filer record by using where clause. 2. It does not allow to use where
3. Ex: delete from emp where eid=102; clause.
3. Ex: truncate table emp;

15. Differentiate: Attribute and Domain.

Attribute Domain
1. An attribute is a column that represents an 1. Domain is a pool of values that can
entity. be assigned to an attribute.
2. It helps to describe an entity. 2. It helps to define the range of
values that set off a specific
attribute.

16. Differentiate: Fetchone ( ) and Fetchall ( )

Fetchone ( ) Fetchall ( )
1. In this method, it fetches only one record 1. In this method, it fetches all the
from the result set. record from the result set.
2. The return type is tuple. 2. The return type is list of tuple.

You might also like