GUI Testing is AKA User Interface Testing or Front end testing
Database Testing is AKA back-end testing or data testing.
GUI Testing deals with all the testable items that are open to the user to interaction such as Menus, Forms etc.
Database Testing deals with all the testable items that are generally hidden from the user.
The tester who is performing GUI Testing doesn’t need to know Structured Query Language
The tester who is performing Database Testing needs to know Structured Query Language
GUI Testing includes in validating the text boxes, check boxes, buttons, drop-downs, forms etc., majorly the look and feel of the overall application
Database Testing involves in verifying the integrity of data in the front end with the data present in the back end. It validates the schema, database tables, columns, indexes, stored procedures, triggers, data duplication, orphan records, junk records. It involves in updating records in database and verifying the same in the front end.
- DDL – Data Definition Language
- DML – Data Manipulation Language
- DQL – Data Query Language
- DCL – Data Control Language
- TCL – Transaction Control Language
- CREATE: To create databases and database objects
- ALTER: To alter existing database objects
- DROP: To drop databases and databases objects
- TRUNCATE: To remove all records from a table but not its database structure
- RENAME: To rename database objects
- SELECT: To select specific data from a database
- INSERT: To insert new records in a table
- UPDATE: To update existing records
- DELETE: To delete existing records from a table
- GRANT: To provide user access
- DENY: To deny permissions to users
- REVOKE: To remove user access
- COMMIT: To write and store the changes to the database
- ROLLBACK: To restore the database since a last commit
17. What is an Index?
CREATE VIEW view_name AS SELECT column_name1, column_name2 FROM table_name WHERE CONDITION;
19. What are the advantages of Views?
Some of the advantages of Views are
- Views occupy no space
- Views are used to simply retrieve the results of complicated queries that need to be executed often.
- Views are used to restrict access to the database or to hide data complexity.
20. What is a Subquery ?
A Subquery is a SQL query within another query. It is a subset of a Select statement whose return values are used in filtering the conditions of the main query.
21. What is a temp table?
Ans. A temp table is a temporary storage structure to store the data temporarily.
22. How to avoid duplicating records in a query?
SQL SELECT DISTINCT query is used to return only unique values. It eliminates all the duplicated vales.
SELECT DISTINCT Name from tblEmployee
23. What is the difference between Rename and Alias?
‘Rename’ is a permanent name given to a table or column
‘Alias’ is a temporary name given to a table or column.
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- OUTER JOIN
SQL constraints are the set of rules that enforced some restriction while inserting, deleting or updating of data in the databases.
Unique constraint is used to ensure that there are no duplication values in the field/column.
Composite PRIMARY KEY is a primary key created on more than one column (combination of multiple fields) in a table.
A table can have many FOREIGN KEY’s.
35. What is the difference between UNIQUE and PRIMARY KEY constraints?
There should be only one PRIMARY KEY in a table where as there can be any number of UNIQUE Keys.
PRIMARY KEY doesn’t allow NULL values whereas Unique key allows NULL values.
36. What is a NULL value?
A field with a NULL value is a field with no value. A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation. Assume, there is a field in a table is optional and it is possible to insert a record without adding a value to the optional field then the field will be saved with a NULL value.
37. How to Test for NULL Values?
A field with a NULL value is a field with no value. NULL value cannot be compared with another NULL values. Hence, It is not possible to test for NULL values with comparison operators, such as =, <, or <>. For this, we have to use the IS NULL and IS NOT NULL operators.
SELECT column_names FROM table_name WHERE column_name IS NULL; SELECT column_names FROM table_name WHERE column_name IS NOT NULL;
38. What is a NOT NULL constraint?
NOT NULL constraint is used to ensure that the value in the filed cannot be a NULL
39. What is a CHECK constraint?
CHECK constraint is used to limit the value that are accepted by one or more columns.
E.g. ‘Age’ field should contains only the value greater than 18.
CREATE TABLE EMP_DETAILS(EmpID int NOT NULL, NAME VARCHAR (30) NOT NULL, Age INT CHECK (AGE > 18), PRIMARY KEY (EmpID));
40. What is a DEFAULT constraint?
DEFAULT constraint is used to include a default value in a column when no value is supplied at the time of inserting a record.
41. What is Normalization?
Normalization is the process of table design to minimize the data redundancy. There are different types of Noramalization forms in SQL.
- First Normal Form
- Second Normal Form
- Third Normal Form
- Boyce and Codd Normal Form
42. What is Stored procedure?
A Stored Procedure is a collection of of SQL statements that has been created and stored in the database to perform a particular task. The stored procedure accepts input parameters and processes them and returns a single values such as a number or text value or a result set (set of rows).
43. What is a Trigger?
A Trigger is a SQL procedure that initiates an action in response to an event (Insert, Delete or Update) occurs. When a new Employee is added in a Employee_Details table, new records will be created in the relevant tables such as Employee_Payroll, Employee_Time_Sheet etc.,
44. Explain SQL Data Types?
In SQL Server, each column in a database table has a name and a data type. We need to decide what type of data to store inside each and every column of a table while creating a SQL table.
45. What are the possible values that can be stored in a BOOLEAN data field.
TRUE and FALSE
46. What is the largest value that can be stored in a BYTE data field?
The largest number that can be represented in a single byte is 11111111 or 255. The number of possible values is 256 (i.e. 255 (the largest possible value) plus 1 (zero), or 28).
47. What are Operators available in SQL?
SQL Operator is a reserved word used primarily in an SQL statement’s WHERE clause to perform operations, such as arithmetic operations and comparisons. These are used to specify conditions in an SQL statement.
There are three types of Operators.
- Arithmetic Operators
- Comparison Operators
- Logical Operators
48. Which TCP/IP port does SQL Server run?
By default its 1433
49. Describe SQL comments?
Single Line Comments: Single line comments start with two consecutive hyphens (–) and ended by the end of the line
Multi Line Comments: Multi-line comments start with /* and end with */. Any text between /* and */ will be ignored.
50. List out the ACID properties and explain?
Following are the four properties of ACID. These guarantees that the database transactions are processed reliably.
51. Define the SELECT INTO statement.
The SELECT INTO statement copies data from one table into a new table. The new table will be created with the column-names and types as defined in the old table. You can create new column names using the AS clause.
SELECT * INTO newtable FROM oldtable WHERE condition;
52. What is the difference between Delete, Truncate and Drop command?
The difference between the Delete, Truncate and Drop command are
- Delete command is a DML command, it is used to delete rows from table. It can be rolled back.
- Truncate is a DDL command, it is used to delete all the rows from the table and free the space containing the table. It cant be rolled back.
- Drop is a DDL command, it removes the complete data along with the table structure(unlike truncate command that removes only the rows). All the tables’ rows, indexes and privileges will also be removed.
53. What is the difference between Delete and Truncate?
The difference between the Delete, Truncate and Drop commands are
Delete statement is used to delete rows from table. It can be rolled back.
Truncate statement is used to delete all the rows from the table and free the space containing the table. It cant be rolled back.
We can use WHERE condition in DELETE statement and can delete required rows
We cant use WHERE condition in TRUNCATE statement. So we cant delete required rows alone
We can delete specific rows using DELETE
We can only delete all the rows at a time using TRUNCATE
Delete is a DML command
Truncate is a DDL command
Delete maintains log and performance is slower than Truncate
Truncate maintains minimal log and performance wise faster
We need DELETE permission on Table to use DELETE command
We need at least ALTER permission on the table to use TRUNCATE command
54. What is the difference between Union and Union All command?
This is one of the most important SQL Interview Questions
Union: It omits duplicate records and returns only distinct result set of two or more select statements.
Union All: It returns all the rows including duplicates in the result set of different select statements.
55. What is the difference between Having and Where clause?
Where clause is used to fetch data from database that specifies a particular criteria where as a Having clause is used along with ‘GROUP BY’ to fetch data that meets a particular criteria specified by the Aggregate functions. Where cluase cannot be used with Aggregate functions, but the Having clause can.
56. What are aggregate functions in SQL?
SQL aggregate functions return a single value, calculated from values in a column. Some of the aggregate functions in SQL are as follows
- AVG() – This functions returns the average value
- COUNT() – This functions returns the number of rows
- MAX() – This functions returns the largest value
- MIN() – This functions returns the smallest value
- ROUND() – This functions rounds a numeric field to the number of decimals specified
- SUM() – This functions returns the sum
57. What are string functions in SQL?
SQL string functions are used primarily for string manipulation. Some of the widely used SQL string functions are
- LEN() – It returns the length of the value in a text field
- LOWER() – It converts character data to lower case
- UPPER() – It converts character data to upper case
- SUBSTRING() – It extracts characters from a text field
- LTRIM() – It is to remove all white space from the beginning of the string
- RTRIM() – It is to remove all white space at the end of the string
- CONCAT() – Concatenate function combines multiple character strings together
- REPLACE() – To update the content of a string.
Practical SQL Interview Questions:
58. How to add a new Employee details in an Employee_Details table with the following details
Employee_Name: John, Salary: 5500, Age: 29?
INSERT into Employee_Details (Employee_Name, Salary, Age) VALUES (‘John’, 5500 , 29);
59. How to add a column ‘Salary’ to a table Employee_Details?
ALTER TABLE Employee_Details ADD (Salary);
60. How to change value of the field ‘Salary’ as 7500 for an Employee_Name ‘John’ in a table Employee_Details?
UPDATE Employee_Details set Salary = 7500 where Employee_Name = ‘Sonam Thakur’;
61. How to select all records from the table?
Select * from table_name;
62. How To Get List of All Tables From A DataBase?
To view the tables available on a particular DataBase
USE TestDB GO SELECT * FROM sys.Tables GO
63. Define SQL Delete statement.
The SQL Delete statement is used to delete records from a table.
DELETE FROM table_name WHERE some_column=some_value;
64. Write the command to remove all Players named Sachin from the Players table.
DELETE from Players WHERE Player_Name = ‘Santosh’
65. How to fetch values from TestTable1 that are not in TestTable2 without using NOT keyword?
-------------- | TestTable1 | -------------- | 11 | | 12 | | 13 | | 14 | --------------
-------------- | TestTable2 | -------------- | 11 | | 12 | --------------
By using the
SELECT * FROM TestTable1 EXCEPT SELECT * FROM TestTable2;
66. How to get each name only once from a employee table?
By using DISTINCT keyword, we could get each name only once.
SELECT DISTINCT employee_name FROM employee_table;
67. How to rename a column in the output of SQL query?
By using SQL AS keyword
SELECT column_name AS new_name FROM table_name;
68. What is the order of SQL SELECT ?
Order of SQL SELECT statement is as follows
SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.
69. How to display the current date in SQL.
By using below query
70. Write an SQL Query to find an Employee_Name whose Salary is equal or greater than 5000 from the below table Employee_Details.
| Employee_Name | Salary| ----------------------------- | John | 2500 | | Emma | 3500 | | Mark | 5500 | | Anne | 6500 | -----------------------------
SELECT Employee_Name FROM Employee_Details WHERE Salary>=5000;
| Employee_Name | Salary| ----------------------------- | Mark | 5500 | | Anne | 6500 | -----------------------------71. Write an SQL Query to find list of Employee_Name start with ‘E’ from the below table
| Employee_Name | Salary| ----------------------------- | John | 2500 | | Emma | 3500 | | Mark | 5500 | | Anne | 6500 | -----------------------------Syntax:
SELECT * FROM Employee_Details WHERE Employee_Name like 'E%';Output:
| Employee_Name | Salary| ----------------------------- | Emma | 3500 | -----------------------------72. Write SQL SELECT query that returns the FirstName and LastName from Employee_Details table.
SELECT FirstName, LastName FROM Employee_Details;73. How to rename a Table?
SP_RENAME TABLE 'SCOREBOARD', 'OVERALLSCORE'To rename Table Name & Column Name
sp_rename OldTableName,NewTableName sp_rename 'TableName.OldColumnName', 'NewColumnName'74. How to select all the even number records from a table?
To select all the even number records from a table:
Select * from table where id % 2 = 075. How to select all the odd number records from a table?
To select all the odd number records from a table:
Select * from table where id % 2 != 076. What is the SQL CASE statement?
SQL Case statement allows to embed an if-else like clause in the SELECT statement.
77. Can you display the result from the below table TestTable based on the criteria
M,m as M and F, f as F and Null as N and g,k,I as U
SELECT Gender from TestTable | Gender | ------------ | M | | F | | NULL | | m | | f | | g | | H | | i | ------------
By using the below syntax we could achieve the output as required.
SELECT Gender, case when Gender='i' then 'U' when Gender='g' then 'U' when Gender='H' then 'U' when Gender='NULL' then 'N' else upper(Gender) end as newgender from TestTable GROUP BY Gender
78. What will be the result of the query below?
select case when null = null then 'SQLServer' else 'MySQL' end as Result;
This query will returns “MySQL”. In the above question we could see null = null is no the proper way to compare a null value.
79. What will be the result of the query below?
select case when null is null then 'SQLServer' else 'MySQL' end as Result;
This query will returns “SQLServer”.
80. Can you display F as M and M as F from the below table TestTable.
| Name | Gender | ------------------------ | John | M | | Emma | F | | Mark | M | | Anne | F | ------------------------
By using the below syntax we could achieve the output as required.
UPDATE TestTable SET Gender = CASE Gender WHEN 'F' THEN 'M' ELSE 'F' END81. what is difference between stored procedure and function in sql server.
- Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).
- Functions can have only input parameters for it whereas Procedures can have input/output parameters .
- Functions can be called from Procedure whereas Procedures cannot be called from Function.
- Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.
- Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.
- Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.
- Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.
- Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.
- Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.
- We can go for Transaction Management in Procedure whereas we can't go in Function.