Select chapter



Basics (2.papers)
Data Types (2.papers)
Table-designing (1.papers)
Queries-Commands (3.papers)
String functions (2.papers)
Subqueries (1.papers)
Joins (1.papers)
Constraints (1.papers)
Triggers (1.papers)
Hide

Sponsored Links


  

sql queries commands interview questions and answers

Please read the below given table for solving questions from 1 to 20
eidfnamelnameagesalarydeptdoj
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM
2sowmyakumari2319000db13-Nov-10 12:00:00 AM
3kishorekumar2736000android16-Oct-11 12:00:00 AM
4abimanyubiswal22nullandroid25-May-10 12:00:00 AM
5sonikumar2421800.net21-Jun-09 12:00:00 AM
6anu_singh2212000db23-Oct-10 12:00:00 AM
7_dineshmoh%anty2315000.net26-Aug-09 12:00:00 AM
8nischala_kumari2218000db19-Jul-08 12:00:00 AM
9gouravchourasia2420000android06-Oct-13 12:00:00 AM
Note: Assume table is present in a database named skillgun , the Schema name is dbo and the table name as Employees ;
1
What is the output of the following query?
Query: select distinct lname, dept from employees ;
  1. lnamedept
    _singhdb
    biswalandroid
    chourasiaandroid
    kumar.net
    kumarandroid
    kumaridb
    moh%anty.net
    sukla.net
  2. lnamedept
    _singhdb
    biswalandroid
    chourasiaandroid
    kumar.net
    kumarandroid
    kumaridb
    moh%anty.net
    kumaridb
    sukla.net
  3. Parsing error since a distinct keyword must be applied only on a single column
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
2
What is the output of the following query ?
Query: select distinct dept from employees order by  dept ;
  1. dept
    .net
    db
    android
  2. dept
    .net
    android
    db
  3. order by clause must not be used when the select list is having distinct keyword .
  4. None of the above .
Show Answer
Share Facebook gmail Twitter
3
What is the output of the following query ?
Query: select distinct dept from employees order by lname ;
  1. query will get compiled or parsed without any errors but will not give any result.
  2. in the result set deprtment names are displayed based on the ascending order of the lname coulmn values.
  3. Query will give error during execution but will not produce any error during parsing stating ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
4
How to copy data from one table into another table when the source table and the destination tables are existing in two different databases in the same server ?
  1. insert into destination-table-name select * from source-table-name 
  2. insert into database-name.destination-table-name select * from database-name.source-table-name 
  3. insert into database-name.dbo.destination-table-name select * from database-name.dbo.source-table-name 
  4. It is not possible to copy data from one table into another when both tables are existing in two different databases .
Show Answer
Share Facebook gmail Twitter
5
What is the output of the following query ?
Query: select fname,lname,salary into employees1 from employees .
Note: Assume table employees1 is not existing in the current database .
  1. The query results a parser error.
  2. The query will create a new table with the name employees1 with three columns named fname,lname and salary , 3 columns Data from employees table copied into employees1 table.
  3. The query will fail during execution.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
6
Identify the correct query or queries for displaying second highest salary ?
  1. select top 2 salary into toppaidemps from employees order by salary desc ;
    select top 1 salary from toppaidemps order by salary asc ;
  2. select top 2 max(salary) from employees order by max(salary) 
  3. select top 1 salary from employees 
    where salary > Any ( select top 1 salary from employees order by salary desc ) order by salary desc
  4. First and third queries will give the second highest salary
Show Answer
Share Facebook gmail Twitter
7
Which of the following query is used for removing the duplicate rows present in a given table ?
Note: assume table is not having primary or unique constraints .
  1. select distinct * into emps from employees ;
    truncate table employees;
    insert into employees select * from emps ;
  2. delete employees
  3. select distinct * into emps from employees ;
    drop table employees;
    insert into employees select * from emps ;
  4. None of the above .
Show Answer
Share Facebook gmail Twitter
8
Which of the following query yields better performance for getting entire data from employees table?
  1. select * from employees ;
  2. select eid,fname,lname,salary,dept,age,doj from employees ;
  3. select employees.eid,employees.fname,employees.lname,employees.salary,employees.dept,
    employees.age,employees.doj from employees ; 
  4. select db17.dbo.employees.eid,db17.dbo.employees.fname,db17.dbo.employees.lname,
    db17.dbo.employees.salary,db17.dbo.employees.dept,
    db17.dbo.employees.age,db17.dbo.employees.doj from db17.dbo.employees ;
Show Answer
Share Facebook gmail Twitter
9
Which of the following query used for updating salary and doj of employee id 4 with 27600 and 20th february 2010?
  1. update table employees where salary=27600 and doj='20th feb 2010' where eid=4
  2. update employees set salary=27600,doj='02-20-2010' where eid=4
  3. update table employees set salary=27600 and doj=02-20-2010 where eid=4
  4. update employees set salary=27600,doj=02-20-2010 where eid=4
Show Answer
Share Facebook gmail Twitter
10
Which of the following query is used for deleting all rows present in employees table ?
  1. delete * from employees ;
  2. delete from employees ;
  3. delete employees ;
  4. Both Second and third queries are correct .
Show Answer
Share Facebook gmail Twitter
11
What is the use of truncate statement in SQL?
  1. truncate statement is a logged operation which is used for deleting table structure as well as data.
  2. truncate statement is used for deleting 
    table data when the where condition is not specified .
  3. truncate statement is used for deleting complete table data but not the structure, truncate is not a logged operation.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
12
What is the difference between a delete statement without where clause and truncate statement ?
  1. Both statements will delete all data present in the table.
  2. delete is a logged operation and truncate is not a logged operation.
  3. delete is a reversible operation and truncate is not a reversible operation.
  4. All the statements are correct.
Show Answer
Share Facebook gmail Twitter
13
What is the difference between delete statement without where clause and drop statements?
  1. delete statement will delete all the records present in the given table drop deletes table structure and the data . But drop will not delete associated indexes .
  2. delete statement will delete all the records present in the given table drop deletes table structure and the data . Drop statements alos deletes all asociated triggers , indexes including stored procedures which are using the current table .
  3. delete statement will delete all the records present in the given table. drop deletes table structure and the data . Drop statements also deletes the associated views,triggers and indexes .
  4. delete statement will delete all the records present in the given table. drop deletes table structure and the data. Drop statements also deletes the associated triggers and indexes .
Show Answer
Share Facebook gmail Twitter
14
What is the difference between truncate and drop statements?
  1. truncate statement will delete complete data present in the table, drop statement will delete table structure as well as data.
  2. Both are same.
  3. We can use where clause on truncate but not on drop statement .
  4. All the statements are incorrect .
Show Answer
Share Facebook gmail Twitter
15
What is the output of the following query ?
Query: update employees set salary=20000 ;
  1. Query results a parsing error ;
  2. All employees salaries are updated with salary 20000.
  3. Query results an exception during execution time.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
16
What is an identity column in SQL?
  1. An identity column makes a table data unique, only one identity property is allowed per table.
  2. Identity column is just like an auto numbered column.
  3. Both first and second options are valid.
Show Answer
Share Facebook gmail Twitter
17
What is the out put of the following query when it is alone  executed against the sample-table definition ?
Table syntax: create table sample-table ( sid int identity(1,1) , sname varchar(40) )
Query: insert into sample-table values ('rajeev') ;
  1. Query will produce a parser error.
  2. Query will get compiled but is not executed and database engine will throw an exception.
  3. A row is inserted with 1,'rajeev' as sid and sname values respectively.
  4. A row is inserted with null and rajeev as values into sid and sname respectively.
Show Answer
Share Facebook gmail Twitter
18
What is the out put of the following query when it is alone  executed against the sample-table definition ?
SampleTable: create table sample-table ( sid int identity(1,1) , sname varchar(40) )
Query: insert into sample-table values (1,'rajeev') ;
  1. Query will produce a parser error.
  2. Query will get compiled but is not executed and database engine will throw an exception.
  3. A row is inserted with 1,'rajeev' as sid and sname values respectively.
  4. A row is inserted with 2 and rajeev as values into sid and sname respectively.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
Which of the following is a correct syntax for truncate table syntax (for deleting all data present in a table)?
  1. truncate table table-name
  2. truncate table-name
  3. truncate all from table-name
  4. truncate * from table-name
Show Answer
Share Facebook gmail Twitter
Read more papers :