SQL interview questions and answers for freshers : Set-1

SQL interview Preparations ::

What is an integrity constraint?

Integrity constraint is a rule that restricts values to a column in a table.

What is referential integrity constraint?

Maintaining data integrity through a set of rules that restrict the values of one or more columns of the tables based on the values of primary key or unique key of the referenced table.

What is the usage of SAVEPOINTS?
SAVEPOINTS are used to subdivide a transaction into smaller parts. It enables rolling back part of a transaction. Maximum of five save points are allowed.

When ON DELETE CASCADE is specified Oracle maintains referential integrity by automatically removing dependent foreign key values if a referenced primary or unique key value is removed.

What are the data types allowed in a table?

What is between CHAR and VARCHAR2? What is the maximum SIZE allowed for each type?
CHAR pads blank spaces to the maximum length.
VARCHAR2 does not pad blank spaces.
For CHAR the maximum length is 255 and 2000 for VARCHAR2.

How many LONG columns are allowed in a table? Is it possible to use LONG columns in WHERE clause or ORDER BY?
Only one LONG column is allowed. It is not possible to use LONG column in WHERE or ORDER BY clause.

What are the pre-requisites to modify datatype of a column and to add a column with NOT NULL constraint?
– To modify the datatype of a column the column must be empty.
– To add a column with NOT NULL constrain, the table must be empty.

Where the integrity constraints are stored in data dictionary?
The integrity constraints are stored in USER_CONSTRAINTS.

How will you activate/deactivate integrity constraints?
The integrity constraints can be enabled or disabled by ALTER TABLE ENABLE CONSTRAINT / DISABLE CONSTRAINT.

If unique key constraint on DATE column is created, will it validate the rows that are inserted with SYSDATE?
It won’t, Because SYSDATE format contains time attached with it.

What’s an injection?
SQL Injection is when form data contains an SQL escape sequence and injects a new SQL query to be run.

What is difference between TRUNCATE & DELETE ?
TRUNCATE commits after deleting entire table i.e., cannot be rolled back. triggers do not fire on TRUNCATE
DELETE allows the filtered deletion. Deleted records can be rolled back or committed. Database triggers fire on DELETE.

What is a join? Explain the different types of joins?
Join is a query, which retrieves related columns or rows from multiple tables.
Self Join – Joining the table with itself.
Equi Join – Joining two tables by equating two common columns.
Non-Equi Join – Joining two tables by equating two common columns.
Outer Join – Joining two tables in such a way that query can also retrieve rows that do not have corresponding join value in the other table.

What is the sub-query?
Sub-query is a query whose return values are used in filtering conditions of the main query.

What is correlated sub-query?
Correlated sub-query is a sub-query, which has reference to the main query.

What is a database link?
Database link is a named path through which a remote database can be accessed.

How to access the current value and next value from a sequence? Is it possible to access the current value in a session before accessing next value?
Sequence name CURRVAL, sequence name NEXTVAL. It is not possible. Only if you access next value in the session, current value can be accessed.

Be the first to comment

Leave a Reply

Your email address will not be published.