Single Post

Header

Saturday, August 1, 2015

Manual Testing – SQL Queries Interview Questions and Answers –Part 2 :


Manual Testing – SQL Queries Interview Questions and Answers –Part 2 :



Views :It is a Virtual Table
If we do any modifications in view table,then those changes automatically effected in view table & parent table and vice-versa
create view myview as select * from emp where deptno=10
insert into myview values(12,'venky',1000,10)
The above statement inserts the values into base table emp AND view table myview
insert into v values(12,'venky',1000,20)
The above statement inserts the values into only the base table emp not into myview table
create view myview as select * from emp where deptno=20 with check option
The above statement can not inserts the values into the base table emp and myview table
SP_HELPTEXT  myview   // Displays the definition of that view

Indexes:Used to improve the performance of queries
Indexes are generally created on the following columns :
Primary Key Column
Foreign Key Column
Columns which are frequently used in where clause
Can not create on :
columnscontaning duplicate or null values
columns which are not used frequently
Types of indexes :
Clustered Index
Only one index allowed per table.The order of values in a table and the order of values in index is also same
Non Clustered Index
The order of values in a table and the order of values in index is different
create clustered index myindex on emp(empno)
If we want maintain unique values then we can mention unique keyword
create unique clustered index myindex1 on emp(empno)
createnonclusted index myindex2 on emp(ename,sal)
SP_HELPINDEX EMP   // Display the list of indexex  under that table

T-SQL : (Transact SQL)
DECLARE @A INT,@N INT
SET @A=4
IF(@A>4)
PRINT ' A VALUE IS MORE THAN 4'
ELSE
PRINT 'A VALUE IS LESS THAN 4'
SET @N=1
WHILE(@N<4)
BEGIN
PRINT @N
SET @N=@N+1
END

User Defined Functions :
If the functions are created by the user,then it is user defined function
udf are same as user defined stored procedure but with a return type
create function function_name(@parameter1 datatype,@parameter2 datatype,......)
returnsdatatype
as
begin
declare @vardatatype
------
------
return @var
end
Calling to that function
selectdbo.function_name(value1,value2,...)
Ex:
create function avg(@a int,@b int)
returnsint
as
begin
declare @c int
set @c=(@a+@b)/2
return @c
end
selectdbo.avg(34,67)

User Defined Stored Procedures:
createproc[ecure] procedure_name(@parameter1 datatype,@parameter2 datatype,......)
as
begin
---------
---------
end
To call that stored procedure :
execprocedure_name [value1,value2,.....]
Ex1:
create procedure emp_details @a int
as
begin
select * from emp where empno=@a
end
execemp_details 10
Ex2:
create procedure emp_insert @a int,@b float,@cvarchar(20)
as
begin
insert into emp values(@a,@b,@c)
end
execemp_insert 56,12.4,'venkat'

Cursors:
Cursor is a logical area which is used to retrieve a particular n th record.
Types of Cursors:
1.Static Cursor
2.Dynamic Cursor
3.Forward_ONLY_Cursor
syntax:
declarecursor_name cursor cursor_type for select * from table_name
Syntax to open a cursor:
opencursor_name
Syntax to fetech the records from cursor
fetch {first/next/prior/last/absolute n/relative n} from cursor_name
syntax to close a cursor:
closecursor_name
syntax to deallocate a cursor
deallocatecursor_name
Ex:EMP
EMPNO   ENAME  ESAL
234    VENKAT  30000
123    KRIS    40000
678    RAM     20000
130    KASI    20000
declaremycursor cursor static for select * from emp
openmycursor
fetch first from mycursor
234 VENKAT 30000
fetch NEXT from mycursor
123    KRIS    40000
fetch PRIOR from mycursor
234 VENKAT 30000

fetch LAST from mycursor
130    KASI    20000
fetch ABSOLUTE 2 from mycursor
123    KRIS    40000
fetch ABSOLUTE -2 from mycursor
678    RAM     20000
updateemp set empno=100 where empno=234  
// Updations will be reflected only after closing the cursor
fetch first from mycursor
234 VENKAT 30000
fetch RELATIVE 2 from mycursor
678    RAM     20000
fetch RELATIVE -2 from mycursor
234    VENKAT  30000
closemycursor
openmycursor
fetch first from mycursor
100 VENKAT 30000
Dynamic Cursor:
declaremycursor cursor dynamic for select * from emp
fetch first from mycursor
100 VENKAT 30000
updateemp set empno=234 where empno=100   // Updations will be reflected
fetch first from mycursor
234 VENKAT 30000


Interview - SQL queries


Company1:

create database temp1
use temp1
create table emp (id int,names varchar(20))
insert into emp values (25,'venkates')
select * from emp
select names from emp order by  names    /* by default ascending order */
select names from emp order by  names asc
select names from emp order by  names desc
select names from emp where names like 'v%'
select names from emp where names like '%s'
select names from emp where names like 'venkat%'
select names from emp where names!='venkat'

Company2:

create database employee
use employee

create table emp (emp_id int primary key,names varchar(20),sal money,join_date datetime)
insert into emp values(8113,'koti',15000,'01/08/2011')
drop table emp

/* by default order by asceding order .If we want in ascending order then order by names asc*/
select *from emp order by names desc
select names from emp where sal>=18000 order by names desc

update emp set sal=18000 where  names='ram'
select * from emp where sal>=18000
create table student(stu_id int unique,names nvarchar(20),branch varchar(20))
select * from student
insert into student values (162,'koti','cse') 
select e.names from emp e , student s where e.sal>16000 and s.branch='cse'
select e.names from emp e inner join student s on e.names=s.names and e.sal>16000 and s.branch='cse'

select names from emp where names like 'ven%'   /* it would display 'ven' record also' */
select max(sal) as max_salary from emp

select top 3 sal from emp order by sal desc
/* find nth highest salary */
select min(sal) from emp where sal in (select top 4 sal from emp order by sal desc) 

create table hcl1(id int,names varchar(20),salary int,address varchar(20))
insert into hcl1 values (1234,'',234,'bang')  /* want to give second parameter as blank */
insert into hcl1 values (81234,null,234,'bang')
insert into hcl1 values ('','venky',234,'bang') 
insert into hcl1 values (null,'venky',234,'bang') 
insert into hcl1 values (default,'venky',234,'bang') 
select names from hcl1 where names=null
select names from hcl1 where names is null
select names from hcl1 where names=''
select names from hcl1 where names=""
select * from hcl1
delete from hcl1
select e.names from emp e inner join student s on  e.names=s.names and e.sal>16000 and s.branch='cse'
select e.names from emp e left join student s on  e.names=s.names and e.sal>16000 and s.branch='cse'
select e.names from emp e right join student s on  e.names=s.names and e.sal>16000 and s.branch='cse'

select top 1 * from hcl1 order by id desc 
select * from emp
sElect * from eMp where names <> 'venkat'   /* sql is not case sensitive */

/*The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns. */
select * from student
select names from student group by branch  /* wrong */
select names,sum(sal) from emp group by names
/* The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions. */
select names,sum(sal) from emp group by names having sum(sal)>18000
select names,sum(sal) from emp where sum(sal)>18000  /* wrong */

CREATE DATABASE TEMP1

CREATE TABLE TEST1(ID INT PRIMARY KEY)
CREATE TABLE TEST2(NUM INT FOREIGN KEY REFERENCES TEST1(ID))

Company3:

create  database temp3
create table test3(id int,lastname varchar(20),firstname varchar(20))
insert into test3 values(2134,'nabcd','nbcde')
select * from test3 
select count(id) from test3
select distinct firstname,lastname from test3
select distinct firstname,count(firstname) from test3
group by firstname

create table college(id int ,branch varchar(20),name varchar(20)) 
insert into college values(12,'cse','venky')
insert into college values(32,'cse','koti')
insert into college values(28,'ece','raju')
select branch,count(branch) from college group by branch

Company4:

use employee

create table emp1 (ename varchar(20),sal int)
insert into emp1 values ('ravi',15000)
insert into emp1 values ('gopi',18000)
insert into emp1 values ('venky',25000)
insert into emp1 values ('kasi',15000)
insert into emp1 values ('praveen',25000)
insert into emp1 values ('koti',18000)
insert into emp1 values ('kasi',15000)
insert into emp1 values ('ravindra',15000)

select * from emp1
/* select sal and count of employee in descending order   */
select sal,count(ename) from emp1 group by sal order by sal desc

create table emp2 (ename varchar(20),gender char(1))
insert into emp2 values ('abcd','m')
insert into emp2 values ('bcde','m')
insert into emp2 values ('abcd','f')
insert into emp2 values ('abcd','f')
insert into emp2 values ('abcd','m')
insert into emp2 values ('abcd','f')
insert into emp2 values ('abcd','m')
delete  from emp2
select * from emp2

BEGIN TRANSACTION
UPDATE emp2
SET gender = CASE  
WHEN gender = 'm' THEN 'f' ELSE 'm' END


create table emp3(ename varchar(20),dname varchar(20))
insert into emp3 values('abcd','cse')
insert into emp3 values('bcde','ece')
insert into emp3 values('cdef','eee')
insert into emp3 values('defg','cse')
insert into emp3 values('efgh','ece')
insert into emp3 values('fghi','ece')
select * from emp3
delete from emp3

create table dept(dname varchar(20),city varchar(20))
insert into dept values('ece','hyd')
insert into dept values('cse','bang')
insert into dept values('ece','hyd')
insert into dept values('cse','hyd')
select * from dept
select distinct e.ename,d.city from emp3 e inner join dept d on e.dname=d.dname and d.city='hyd'
select distinct e.ename,d.city from emp3 e left join dept d on e.dname=d.dname and d.city='hyd'
select distinct e.ename,d.city from emp3 e right join dept d on e.dname=d.dname and d.city='hyd'
select distinct e.ename,d.city from emp3 e full join dept d on e.dname=d.dname and d.city='hyd'

create table emp4(id int,ename varchar(20),sal int,dname varchar(20))
insert into emp4 values(234,'gopi',15000,'it')
select * from emp4

create procedure sample1(@newid int,@dname varchar(20))
as
begin
update emp4 set id=@newid where dname=@dname
end
execute sample1 345,'it'
execute sample 234,'it'

create procedure sample3(@newid int,@empname varchar(20),@esal int,@dname varchar(20))
as
begin
insert into emp4 values(@newid,@empname,@esal,@dname)
end
execute sample3 567,'venkat',1000,'cse'
execute sample3 '567','venkat','1000','cse'
select * from emp4
update emp4 set id=650 where sal=1000


Company5:

use employee

create table emp1 (ename varchar(20),sal int)
insert into emp1 values ('ravi',15000)
insert into emp1 values ('gopi',18000)
insert into emp1 values ('venky',25000)
insert into emp1 values ('kasi',15000)
insert into emp1 values ('praveen',25000)
insert into emp1 values ('koti',18000)
insert into emp1 values ('kasi',15000)
insert into emp1 values ('ravindra',15000)

select * from emp1
/* select sal and count of employee in descending order   */
select sal,count(ename) from emp1 group by sal order by sal desc

create table emp2 (ename varchar(20),gender char(1))
insert into emp2 values ('abcd','m')
insert into emp2 values ('bcde','m')
insert into emp2 values ('abcd','f')
insert into emp2 values ('abcd','f')
insert into emp2 values ('abcd','m')
insert into emp2 values ('abcd','f')
insert into emp2 values ('abcd','m')
delete  from emp2
select * from emp2

BEGIN TRANSACTION
UPDATE emp2
SET gender = CASE  
WHEN gender = 'm' THEN 'f' ELSE 'm' END

select * from emp2
create table emp3(ename varchar(20),dname varchar(20))
insert into emp3 values('abcd','cse')
insert into emp3 values('bcde','ece')
insert into emp3 values('cdef','ede')
insert into emp3 values('defg','cse')
insert into emp3 values('efgh','ese')
insert into emp3 values('fghi','ece')
select * from emp3
select ename from emp3 group by ename having count(ename)>1
select * from emp3 where ename in (select ename from emp3 group by ename having count(*)>1)
delete from emp3

create table dept(dname varchar(20),city varchar(20))
insert into dept values('ece','hyd')
insert into dept values('cse','bang')
insert into dept values('ece','hyd')
insert into dept values('cse','hyd')
select * from dept
select distinct e.ename,d.city from emp3 e inner join dept d on e.dname=d.dname and d.city='hyd'
select distinct e.ename,d.city from emp3 e left join dept d on e.dname=d.dname and d.city='hyd'
select distinct e.ename,d.city from emp3 e right join dept d on e.dname=d.dname and d.city='hyd'
select distinct e.ename,d.city from emp3 e full join dept d on e.dname=d.dname and d.city='hyd'

create table emp4(id int,ename varchar(20),sal int,dname varchar(20))
insert into emp4 values(234,'gopi',15000,'it')
select * from emp4

create procedure sample1(@newid int,@dname varchar(20))
as
begin
update emp4 set id=@newid where dname=@dname
end
execute sample1 345,'it'
execute sample 234,'it'

create procedure sample3(@newid int,@empname varchar(20),@esal int,@dname varchar(20))
as
begin
insert into emp4 values(@newid,@empname,@esal,@dname)
end

execute sample3 567,'venkat',1000,'cse'
execute sample3 '567','venkat','1000','cse'
select * from emp4
update emp4 set id=650 where sal=1000

create table emp5(ename varchar(20),sal int)
insert into emp5 values ('abcd',456)
insert into emp5 values ('abcd',1456)
insert into emp5 values ('abcd',4856)
insert into emp5 values ('abcd',2456)
insert into emp5 values ('abcd',4856)
insert into emp5 values ('abcd',4596)
select * from emp5
/* select max salary with number of employees */
select top 1 sal,count(ename) from emp5 group by sal order by sal desc 
/* select  salary with number of employees */
select sal,count(ename) from emp5 group by sal


/* Constraints in SQL */

create table checkemp(eid int check (eid>5000),enames varchar(50))
insert into checkemp values (12345,'venkt')
insert into checkemp values (2345,'venkt')
select * from checkemp

/* The NOT NULL constraint enforces a column to NOT accept NULL values.  */

create table notnullemp(eid int not null,enames varchar(50))
insert into notnullemp values (2345,'venkat')
insert into notnullemp values ('','venkat')
insert into notnullemp values (null,'venkat')
select * from notnullemp


create table nullemp(eid int ,enames varchar(50))
insert into nullemp values (2345,'venkat')
insert into nullemp values ('','venkat')
insert into nullemp values (null,'venkat')
select * from nullemp


/* practise */
create table emp5(ename varchar(20),sal int)
insert into emp5 values ('ravi',2345)
insert into emp5 values ('sdd',1234)
insert into emp5 values ('dff',3456)
insert into emp5 values ('BCDE',6789)
insert into emp5 values ('CDEF',5789)
select * from emp5
select max(sal) from emp5     /* works */
select ename,max(sal) from emp5   /* wrong */
select ename,max(sal)  from emp5 group by sal
select sal,count(ename) from emp5 group by sal

select sal,count(ename) from emp5 group by sal having  sal>2345 and count(ename)>1 order by sal desc 

select top 1 sal,count(ename) from emp5 group by sal order by sal desc

select min(sal)  from emp5 where sal in (select top 2 sal from emp5 order by sal desc)

create table emp6(id int primary key,ename varchar(20))
insert into emp6 values(34,'venkat')
insert into emp6 values(null,'venkat')
insert into emp6 values(345,'')
select * from emp6

create table emp7(id int unique,ename varchar(20))
insert into emp7 values(34,'venkat')
insert into emp7 values(null,'venkat')
insert into emp7 values(345,'')
select * from emp7
create table emp8(id1 int,ename1 varchar(20),sal1 int)
insert into emp8 values(34,'venkat',1234)
insert into emp8 values(38,'sfs',5675)
insert into emp8 values(56,'jkh',2424)
insert into emp8 values(344,'qwe',7897)
create procedure emp9(@id int,@ename varchar(20),@sal int)
as 
begin
select id1 from emp8 where id1=@id
end
execute emp9 568,'jh454k',244

truncate table emp8
select * from emp8
drop  table emp8
alter table emp8 add adrress varchar(20)


create database employee2
use employee2
create table emp1(eid int ,sal int)
create table emp2(eid int ,sal int)


insert into emp2 values (5678,18000)

insert into emp2 values (2345,15000)

insert into emp2 values (7890,20000)

select * from emp2

select emp1.ename,emp2.eid from employee.dbo.emp3 inner join employee1.dbo.emp2 on emp1.sal=emp2.sal











Testing Interview Questions - Examples

Manual Testing Interview Questions :

1.What is Regression Testing

2.Explain about SDLC and What are the different models

3.Which SDLC model you use in your project

4.What is the difference between sanity & smoke testing

5.What is Tracebility Matrix ,why we need that

6.Explain about Bug Life Cycle

7.Which defect tracking tool do you choose,What are fields you fill while raising bug

8.What is the difference between severity and priority

9.What are phases do the QA people involve in SDLC

10.What are the modules TestPlan contains

11.What is test scenario and testcase

12.Explain about ECP (Equivalence Class Partitioning)

13.Explain about BVA (Boundary Value Analysis)

14.What is the difference between Load & Performance testing

15.Explain about STLC

16.What is Test Strategy

17.What is Agile Methodology

18.What is the difference between verification and validation

19.How do you ensure all the requrements are covered

20.what does the mean of "differed" status in Bug Life Cycle


Examples:

1.Write the testcases for Mobile

2.Write the testcases for Pen

3.Write the testcases for ATM

4.Write the testcases for Login Form



SQL Server Queries for Manual Test Engineers :

1.What are the different joins in sql

2.What are constraints (not null,unique,primary key,foriegn key,check,default)

3.Find the n th highest salary in a table

4.Explain about DDL,DML commands

5.Explain about views with syntax

6.Explain about procedures syntax

7.Write syntax for insert,update queries

8.Write query for swap 'm' and 'f' in the table

9.Write query for fetching records only having duplicates

10.By default order by <coloumnname> would display records in which order (ascending or descending)

11.What is the difference between unique key and primary key


Table is like below

ename sal

12.Display from high to low sal with number of employees count

13.Need max(sal) with number of employees


Programs for Manual Testers

1.Write factorial program

2.Swap 2 numbers without using 3rd variable

3.Write any sorting algorithm

4.Write matrix multiplication program

5.Write program for reverse string







Manual Testing – SQL Queries Interview Questions and Answers –Part 1 :


Manual Testing – SQL Queries Interview Questions and Answers –Part 1 :

1. What is the difference between “delete” , “truncate” and “drop” commands

Delete Command Truncate Command Drop Command
Delete Command Belongs to DML Truncate Command Belongs to DDL Drop Command Belongs to DDL
Can be Used to delete entire Table data Can be Used to delete entire Table data Can be Used to delete entire Table data and also the structure
Can be used to delete specific rows using where clause Can't be used to delete specific rows using where clause Can't be used to delete specific rows using where clause
Can be rolled back Can't be rolled back Can't be rolled back

2.What is the syntax for writing insert queries
We can write insert queries in two ways :
a.insert into <table-name> values (value1,value2,…..)
b.insert into <table-name> (col1,col2,……) values (value1,value2,…..)

3.What is the difference between primary key and unique key

Unique Key Primary Key
a.A table can contain more than one unique key a.A table can contain only one primary key (can be one/more columns)
b.Unique key allows one null value b.Primary key will not allow null values

4.What are DDL and DML commands .

DDL (DataDifinition Language) DML (Data Manipulation Language)
Create Select
Alter Insert
Truncate Update
Drop Deletet

5. What is the difference between sub queries and joins
a.Sub Queries :
To write sub queries between two or more tables, there is no need to be relation exist among those tables
b.Joins:
To write joins between two or more tables, there should be relation exist among those tables

6. What are the different  types of joins and explain them
Inner Join
Left Outer Join
Right Outer Join
Full Outer Join

7. Write  syntax for views and stored procedures
View Syntax:
Create view <view-name> as select <column names> from <table-name> where <condition>
Stored Procedure Sysntax:
Create procedure <procedure-name> as begin select <column names> from <table-name> end

Note: These are only sample examples, we can write in different ways also.

8. Relation between views and the their parent tables
If we modify the views table,it effects the parent tables and vice versa

9. Write syntax for update query
Update <table-name> set some_co1l=value1, some_col2=value2 where some_col3=value3

10.What are the different constraints available in sql and Explain
Not Null      -> enforces a column to Not accept Null values
Unique       -> uniquely identifies each record in a database table
Primary Key -> uniquely identifies each record in a database table and it cannot contain NULL values.
Foreign Key -> A Foreign Key in one table points to a PRIMARY KEY in another table.
Check         -> It is used to limit the value range that can be placed in a column.
Default       -> It is used to insert a default value into a column.

11.By default how the column data would display if use order by <column>
By default the order by would display the data in ascending order
Syntax:
a. select <col-names> from <table-name> order by <col-names>
It will display the results in ascending order
select <col-names> from <table-name> order by <col-names> desc
It will display the results in descending order
select <col-names> from <table-name> order by <col-names> asc
It will display the results in ascending order

12.What is the operator in sql to find pattern match
Like
Select <colnames> from <table-name> where <col> like <pattern>
Ex:
a.
Select ename from emp where ename like ‘v%’
It will display all the names which are start with ‘v’
b.
Select ename from emp where ename not like ‘v%’
It will display other than all the names which are start with ‘v’


13. What is the purpose of ‘distinct’ in sql
Distinct is used to display only the different values

Ex:
Select distinct <col-names> from <table-name>
Select distinct ename from emp

14. What is the difference between union and union all
The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL
Select <col-names> from <table1> union select <col-names> from <table2>
Select <col-names> from <table1> union all select <col-names> from <table2>