Showing posts with label sql question and answer. Show all posts
Showing posts with label sql question and answer. Show all posts

Thursday, May 5, 2016

SQL question and answer for fresher

What is SQL?
SQL is stand for structured query language designed for communicating with database

What are the different types of SQL statement?
The SQL statement is given below:
DDL – DDL is stand for Data definition language used to define the data For example Create, Alter, Drop, truncate table.
DML – DML is stand for Data manipulation language is used to manipulate data itself for example insert, update, delete, retrieving data from table.
DCL – DCL is stand for data control language is used to control the visibility of data for example granting database access and set privileges and set privileges to create table. Grant, Deny, revoke commands are used in DCL.

What is a field in the database?
A field is an area where record is kept for a specific piece of data for example client name, client address etc.

What is a record in the database?
A record is the collection of fields for example salary of an employee

What is the table in database?
A table is the collection of record for example emp table, salary table etc.

What is the difference between clustered and Non-clustered index?
Clustered index physically sort all rows while Non clustered index does not sort.
One table contain only one clustered index while in Non-clustered index there is no such restriction
In clustered index the leaf level pages are the actual data pages of the table while in Non-clustered index does not contain data pages while it contain pointer to the data pages.

 What is the difference between primary key and unique Key and Foreign Key?
Primary key and unique key both enforce uniqueness of the column, primary key create a clustered index on the column while unique key create Non clustered index on the column, the major difference between the primary key and unique key is that  primary key does not allow Nulls, while unique key allows one NULL values.
Foreign key in one table points to the primary key to the another table .

What is the difference among delete and truncate and drop commands?
Truncate
Truncate removes all rows from a table but table structure, its column, constraints, indexes do not remove
Truncate cannot be rolled back
Truncate is DDL commands
Truncate reset identity of table
Delete
Delete is used to delete rows in the table also used where clause to remove the user if we don’t use where clause then all rows will be removed
Delete commands is used with or without where clause
Delete can be rolled back
Delete is DML commands
It does not reset identity of the table
Drop
Drop commands are used to remove object from the table by using drop commands all the rows deleted and also structure of the table from database is deleted

What is the difference between the having clause and where clause?
Having clause can be used only with the SELECT statement it is used in GROUP BY clause if we don’t use GROUP BY clause HABING work just like a Where Clause. Having clause is used only with the group by function while where clause is applied to each row.

What is check constraints?
The check constraints are used to enforce domain integrity and it is used to limit the value which is placed in the column.

What is NOT NULL constraints?
Not Null constraints is just like check constraints it enforce the column will does not accept  null values.

What is the stored procedure?
Stored procedure are the group of SQL statement which run all the SQL statement in a single unit it is precompiled object if we call to stored procedure then there is no need to compile again.

What is SQL injection?
This is the problem by injecting the SQL command illegal operation can be performed the solution of the problem is that use parameterized query.

What is transaction?
Transaction is used to proceed multiple SQL statement into single logical unit.