Attn. Testers | Practice SQL Queries at Home without any paid tool


Those days are gone when there was demand of Manual testing only. Now the competition is very tough for testers. Its difficult to survive with Manual testing only. Now skills like SQL, Automation tools, etc are required to grow.

We have receive many queries from testers on how they can practice sql queries at home. This topic is for testers who want to practice SQL queries at home without any paid tool. We suggest testers to install MS SQL Server 2008 as it is very easy to install and it has an excellent sample database “AdventureWorks” available. AdventureWorks is small in size (58 MB) and it includes the schema diagrams as well with which one can easily understand the table relations. With AdventureWorks db, testers can practice all type of SQL queries.

Step 1: Install Microsoft SQL Server 2008 Management Studio Express – http://www.microsoft.com/en-in/download/details.aspx?id=7593
Step 2: Microsoft SQL Server 2008 Express with Tools – http://www.microsoft.com/en-us/download/details.aspx?id=22973
Step 3: Download Microsoft SQL Server Product Samples: AdventureWorks Database – Version 2008 http://msftdbprodsamples.codeplex.com/downloads/get/478218
Step 4: Attach the downloaded db (in step 3):

  1. Open the installed Microsoft SQL Server Management Studio, connect to a SQL Server instance.
  2. Right click Databases.
  3. Click Attach.
  4. Click the Add button.
  5. Locate the AdventureWorks database mdf file. For instance, AdventureWorks2008_Data.mdf.
  6. Click the OK button on the Locate Database Files dialog window.
  7. Click the OK button on the Attach Databases dialog window to attach the database.

Execute below statements:
USE AdventureWorks2008
SELECT * FROM INFORMATION_SCHEMA.TABLES

image

If above statements executed successfully then it means you have successfully attached AdventureWorks2008 db.


Database Testing Basics – How to test and what to test?


[Note – This post is for beginners. More details on DB Testing are available here –
More on Database Testing –

What is Database Testing?
Database testing involves the tests to check the exact values which have been retrieved from the database by the web or desktop application. Data should be matched correctly as per the records are stored in the database.

How to Test Database?
Database testing is one of the major testing which requires tester to expertise in checking tables, writing queries and procedures. Testing can be performed in web application or desktop and database can be used in the application like SQL or Oracle. There are many projects like banking, finance, health insurance which requires extensive database testing. Below is the discussed point that how to test database: Database Testing

  • First of all, tester should make sure that he understands all the application totally and which database is being used with the testing application.
  • Figure out all the tables which exist for the application and try to write all the database queries for the tables to execute since there are many things which are really complex, so you can take the assistance of developers and figure out the queries. Test each and every table carefully for the data added. This is the best process for the testers to perform the DB testing, it can be done for any application and it does not matter application is small or big.
  • If things are really complex then tester can obtain the query from the developer to test the appropriate functionality.

Database is the spine of the application and tester should make sure to test very carefully. It requires skill, proficiency and sound knowledge.

What to Test in a Database?

  • Check all the functionality which is happening on every action performed in the application. Actions can include deletion, addition or save options. Check whether the added record is added in the DB with the exact value. Check the deleted record gets removed from the database. These are major roles which need to be monitored seriously.
  • Nowadays database is getting more complex due to the business logic which plays an important role for the applications. Tester should make sure that values have been added correctly after the implementation of the business rules.

Hence, these are the above mentioned basic things that how and what to test in a database. Database testing is really a complex task and it should always be performed if tester is much experienced in this field.

– Article by Mandeep Singh
More on Database Testing –

 


SQL For Testers – Part 2

After reading part 1, now you are aware of –

  • Why database testing is necessary?
  • Differences between backend testing and front end testing
  • Backend testing phases / Database Testing Phases
  • Backend test methodology / Database Testing methodology
  • Basics of SQL

Now lets put more focus on SQL Statements –
Section 1

1.1 Basics of the SELECT Statement
1.2 Conditional Selection
1.3 Relational Operators
1.4 Compound Conditions
1.5 IN & BETWEEN
1.6 Using LIKE

Section 2

2.1 Joins
2.2 Keys
2.3 Performing a Join
2.4 Eliminating Duplicates
2.5 Aliases & In/Sub-queries

Section 3

3.1 Aggregate Functions
3.2 Views
3.3 Creating New Tables
3.4 Altering Tables
3.5 Adding Data
3.6 Deleting Data
3.7 Updating Data

Section 4

4.1 Indexes
4.2 GROUP BY & HAVING
4.3 More Sub-queries
4.4 EXISTS & ALL
4.5 UNION & Outer Joins
4.6 Embedded SQL
4.7 Common SQL Questions
4.8 Nonstandard SQL
4.9 Syntax Summary

Download from here – SQL For Testers – Part 2 The author of this tutorial is Sir Jim Hoffman

Tutorial Database Testing using SQL | SQL for Testers

The demand for “all round” testers, i.e. being able to test the system’s functionality through traditional testing methods and being able to show some technical knowledge is growing.Basics of Database testing contains the following:

1. How to connect to the database?
2. Ability to write simple queries to retrieve data and manipulate the data using DML operations.
3. Functional flow should be very well known!
4. Good knowledge on table level, column level constraints, ability to understand and execute complex queries related to joins is added advantage.

Contents of this tutorial:
1. INTRODUCTION to Database Testing

  • 1.1 Why back end testing is so important
  • 1.2 Characteristics of back end testing
  • 1.3 Back end testing phases
  • 1.4 Back end test methods

2. STRUCTURAL BACK END TESTS
2.1 Database schema tests

  • 2.1.1 Databases and devices
  • 2.1.2 Tables, columns, column types, defaults, and rules
  • 2.1.3 Keys and indexes

2.2 Stored procedure tests

  • 2.2.1 Individual procedure tests
  • 2.2.2 Integration tests of procedures

2.3 Trigger tests

  • 2.3.1 Update triggers
  • 2.3.2 Insert triggers
  • 2.3.3 Delete triggers

2.4 Integration tests of SQL server
2.5 Server setup scripts
2.6 Common bugs
3. FUNCTIONAL BACK END TESTS

  • 3.1 Dividing back end based on functionality
  • 3.2 Checking data integrity and consistency
  • 3.3 Login and user security
  • 3.4 Stress Testing
  • 3.5 Test back end via front end
  • 3.6 Benchmark testing
  • 3.7 Common bugs

4. Testing The Nightly downloading and Distribution jobs

  • 4.1 Batch jobs
  • 4.2 Data downloading
  • 4.3 Data conversion
  • 4.4 Data distribution
  • 4.5 Nightly time window
  • 4.6 Common bugs

5. Testing the Interfaces to Transaction APIS

  • 5.1 APIs’ queries to back end
  • 5.2 Outputs of back end to APIs
  • 5.3 Common bugs

6. Other Database testing Issues

  • 6.1 Test tips
  • 6.2 Test tools
  • 6.2 Useful queries

Download the “SQL For Testers” tutorial from here

Before going through chapters 2 to 6, one should know the basics of SQL:

1. What are the difference between DDL, DML and DCL commands?

DDL is Data Definition Language statements. Some examples:

•CREATE – to create objects in the database
•ALTER – alters the structure of the database
•DROP – delete objects from the database
•TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
•COMMENT – add comments to the data dictionary
•GRANT – gives user’s access privileges to database
•REVOKE – withdraw access privileges given with the GRANT command

DML is Data Manipulation Language statements. Some examples:

•SELECT – retrieve data from the a database
•INSERT – insert data into a table
•UPDATE – updates existing data within a table
•DELETE – deletes all records from a table, the space for the records remain
•CALL – call a PL/SQL or Java subprogram
•EXPLAIN PLAN – explain access path to data
•LOCK TABLE – control concurrency

DCL is Data Control Language statements. Some examples:

•COMMIT – save work done
•SAVEPOINT – identify a point in a transaction to which you can later roll back
•ROLLBACK – restore database to original since the last COMMIT
•SET TRANSACTION – Change transaction options like what rollback segment to use

Download the “SQL For Testers” tutorial from here

Read SQL for Testers – Part 2

SQL interview questions for Testers


These SQL interview questions are very simple and mainly were used for interviewing software testers who is involved (or going to involve) in database SQL testing or grey box testing.
Apart from the below Questions, you can download more 53 SQL Interview questions document from here –  Click here to download.
Password of document – osst

Q. How do you select all records from the table?
Select * from table_name;

Q. What is a join?
Join is a process of retrieve pieces of data from different sets (tables) and returns them to the user or program as one “joined” collection of data.

Q. How do you add record to a table?
A. INSERT into table_name VALUES (‘ALEX’, 33 , ‘M’);

Q. How do you add a column to a table?
ALTER TABLE Department ADD (AGE, NUMBER);

Q. How do you change value of the field?
A. UPDATE EMP_table set number = 200 where item_munber = ‘CD’;
update name_table set status = ‘enable’ where phone = ‘4161112222’;
update SERVICE_table set REQUEST_DATE = to_date (‘2006-03-04 09:29’, ‘yyyy-mm-dd hh24:MM’) where phone = ‘4161112222’;

Q. What does COMMIT do?
A. Saving all changes made by DML statements

Q. What is a primary key?
A. The column (columns) that has completely unique data throughout the table is known as the primary key field.

Q. What are foreign keys?
A. Foreign key field is a field that links one table to another table’s primary or foreign key.

Q. What is the main role of a primary key in a table?
A. The main role of a primary key in a data table is to maintain the internal integrity of a data table.

Q. Can a table have more than one foreign key defined?
A table can have any number of foreign keys defined. It can have only one primary key defined.

Q. List all the possible values that can be stored in a BOOLEAN data field.
There are only two values that can be stored in a BOOLEAN data field: -1(true) and 0(false).

Q. What is the highest value that can be stored in a BYTE data field?
A. The highest value that can be stored in a BYTE field is 255. or from -128 to 127. Byte is a set of Bits that represent a single character. Usually there are 8 Bits in a Byte, sometimes more, depending on how the measurement is being made. Each Char requires one byte of memory and can have a value from 0 to 255 (or 0 to 11111111 in binary).

Q. Describe how NULLs work in SQL?
The NULL is how SQL handles missing values. Arithmetic operation with NULL in SQL will return a NULL.

Q. What is Normalization?
A. The process of table design is called normalization.

Q. What is Trigger?
A. Trigger will execute a block of procedural code against the database when a table event occurs. A2. A trigger defines a set of actions that are performed in response to an insert, update, or delete operation on a specified table. When such an SQL operation is executed, in this case the trigger has been activated.

Q. Can one select a random collection of rows from a table?
Yes. Using SAMPLE clause. Example:
SELECT * FROM EMPLOYEES SAMPLE(10);
10% of rows selected randomly will be returned.

Q. You issue the following query:
SELECT FirstName FROM StaffListWHERE FirstName LIKE ‘_A%‘
Which names would be returned by this query? Choose all that apply.
Allen
CLARK
JACKSON
David

Q. Write a SQL SELECT query that only returns each city only once from Students table? Do you need to order this list with an ORDER BY clause?
A. SELECT DISTINCT City FROM Students;

Q. What is DML and DDL?
DML and DDL are subsets of SQL. DML stands for Data Manipulation Language and DDL – Data Definition Language.
DML consist of INSERT, UPDATE and DELETE
DDL commands
CREATE TABLE, ALTER TABLE, DROP TABLE, RENAME TABLE, CREATE INDEX, ALTER INDEX, DROP INDEX.
CREATE/ALTER/DROP VIEW

Q. Write SQL SELECT query that returns the first and last name of each instructor, the Salary, and gives each of them a number.
A. SELECT FirstName, LastName, Salary, ROWNUM FROM Instructors;

Q. Is the WHERE clause must appear always before the GROUP BY clause in SQL SELECT ?
A. Yes. The proper order for SQL SELECT clauses is: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY. Only the SELECT and FROM clause are mandatory.

Q. Which of the following statements are Data Manipulation Language commands?
INSERT
UPDATE
GRANT
TRUNCATE
CREATE
Ans. A and B. The INSERT and UPDATE statements are Data Manipulation Language (DML) commands. GRANT is a Data Control Language (DCL) command. TRUNCATE and CREATE are Data Definition Language (DDL) commands

Question: Describe SQL comments.
A. SQL comments are introduced by two consecutive hyphens (–) and ended by the end of the line.

Q. Difference between TRUNCATE, DELETE and DROP commands?
A. The DELETE command is used to remove ‘some or all rows from a table.
TRUNCATE removes ALL rows from a table. The operation cannot be rolled back
The DROP command removes a table from the database. All the tables’ rows, indexes and privileges will also be removed.

Apart from these You can download more 53 SQL Interview questions document from here –> Click here to download.
Password of document – osst