Sei sulla pagina 1di 3

Below are the must practice questions on database testing interview

Lists
------
1.subqueries
query nested inside another query ,which is termed as inner query and outer quer
y.basically the inner query returns a value which is used by outer query,
in correlated subquery both the inner and outer are interdependent,where for eac
h row returned by outer query the inner query exeuted.
2.different joins and examples on that
innerjoin
left
right
full
self
cross
3.database statements like create database,create table and drop table etc
4.concepts of primary key,foreign key,unique key and view and index,identity key
primary key:used to uniquely identify each row in the table
doesnt allow null,1 primary key per table
composite primary key: is made of 2 or more columns
foreignkey : foreign key in one table points to a primary key in another table.
prevents invalid data being entered into the foreign key column
enforce database integrity
values you enter into the foreign key has to be the value from the table it poin
ts to
default constraint : insert default values into a column if no value given (but
if null is given it ll take null)
unique key: constraint ,defines uniqueness of the column,column shouldnt allow a
ny duplicate values.(though acts same as primary key)
but we can use multiple unique keys,and unique key allows one null wheras primar
y key doesnt allow null.
identity :
if a column is identified as identitiy col. then value for the col is automatica
lly generated when row is inserted
no need to give explicit value for the col > or error ll occur
seed and increment is used> but optional if not used then value is increased by
1

5.Examples of Select, Insert, Delete, Alter and Update SQL statements.


6.Stored procedure basics with and without parameter
7.practie basic queries and
8.Min and maximum salary and 2nd 3rd min salary etc
9.how did you test database
10.how data integrity you checked?
11.updata query and the usage like data creation we did in our testing most of t
he time
12.peaked into the stored procedure to check for error messages and try to test
to recreate the same error message
in the application
13.self join is asked multiple times
14.union and union all
15.some example table name you can be asked to tell to check whether you have wo
rked or not
16.

primary key
---------------
In SQL Server (Transact-SQL), a primary key is a single field or combination of
fields that
uniquely defines a record.
None of the fields that are part of the primary key can contain a null value. A
table can
have only one primary key.
CREATE TABLE employees
( employee_id INT PRIMARY KEY,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
salary MONEY
);
or
CREATE TABLE employees
( employee_id INT,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
salary MONEY,
CONSTRAINT employees_pk PRIMARY KEY (employee_id)
);
or
CREATE TABLE employees
( last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
salary MONEY,
CONSTRAINT employees_pk PRIMARY KEY (last_name, first_name)
);

foreign key
-----------------
WHAT IS A FOREIGN KEY IN SQL SERVER?
A foreign key is a way to enforce referential integrity within your SQL Server d
atabase.
A foreign key means that values in one table must also appear in another table.
The referenced table is called the parent table while the table with the foreign
key is
called the child table. The foreign
key in the child table will generally reference a primary key in the parent tab
le.
Both PRIMARY KEY and UNIQUE KEY enforces the Uniqueness of the values (i.e. avoi
ds duplicate values)
on the column[s] on which it is defined.
Also these key s can Uniquely identify each row in database table
primary key: doesnt contain null,only one pk per table,adds a clustered index
unique key: contain only one null value,more than one unique key per table,adds
a unique non clustered index
delete vs drop vs truncate:
----------------------------
https://sqlwithmanoj.com/2009/02/22/difference-between-truncate-delete-and-drop-
commands/
http://chiragadalja.blogspot.in/2013/11/difference-between-truncate-delete-and.h
tml
1.SQL query to get all records where the column is match with required string (i
.e. abc). Here we need to handle the case sensitivity.
Ans: where columnname like '%abc%' COLLATE SQL_Latin1_General_CP1_CS_AS
https://www.codeproject.com/Articles/772478/How-To-do-Case-Sensitive-String-Matc
h-in-SQL-Serve
2.SQL query to find all duplicate records in a table and delete the same.
using 'group by' and 'having' we can find duplicate records in a table
http://www.tech-recipes.com/rx/49959/finding-duplicate-records-using-group-by-in
-sql-server/

Potrebbero piacerti anche