Accenture company ( call based 2016, 2017 batch )

Accenture company ( call based 2016, 2017 batch )
only call based
sql profile
drive date 7-5-2018

Prestige Technopolis, 1/8, Dr.MH Maregowda Road, Audugodi, Bengaluru, Karnataka 560029

FOR INTERVIEW QUESTION CHECK THESE LINKS

1. Compare SQL & PL/SQL
Criteria SQL PL/SQL
What it is Single query or command execution Full programming language
What it comprises Data source for reports, web pages Application language to build, format and display report, web pages
Characteristic Declarative in nature Procedural in nature
Used for Manipulating data Creating applications
2. What is BCP? When is it used?
It is a tool used to duplicate enormous quantity of information from tables and views. It does not facsimile the structures same as foundation to target.
BULK INSERT command helps to bring in a data folder into a record, table or view in a user-specific arrangement.

3. When is the UPDATE_STATISTICS command used?
This command is used, ones the processing of large data is done.
When we delete a large number of files, alteration or reproduction takes place in the tables, to be concerned of these changes we need to restructure the indexes This is done UPDATE_STATISTICS.

4. Explain the steps needed to Create the scheduled job?
Steps to create a Scheduled Job :

Connect to the database of SQL server in SQL Server Management Studio. On the SQL Server Agent, we will find a Jobs folder.
Right click on jobs and choose Add New.
A New Job window will come into view. Give an associated name for the same.
Click next on the “Steps” in the left list of options. An SQL job can have multiple steps either in the form of SQL declaration or a stored practice call.
Click on the “Schedules” in the left list of options. An SQL job can comprise of one or supplementary schedules. It is basically the instance at which SQL job will jog itself. We can spell out returning schedules also.
5. When are we going to use truncate and delete?
TRUNCATE is a DDL command, whereas DELETE is a DML command.
We can’t execute a trigger in case of TRUNCATE whilst with DELETE, we can accomplish a trigger.
TRUNCATE is quicker than DELETE, for the reason that when we use DELETE to delete the data, at that time it store the whole statistics in the rollback gap on or after where we can get the data back after removal. In case of TRUNCATE, it will not store data in rollback gap and will unswervingly rub it out. TRUNCATE do not recover the deleted data.
We can use any condition in WHERE clause using DELETE but it is not possible with TRUNCATE.5.If a table is referenced by any foreign key constraints, then TRUNCATE won’t work.
Go through this SQL tutorial to learn more about SQL commands.

6. Explain correlated query work?
It’s most important to be attentive of the arrange of operations in an interrelated subquery.
First, a row is processed in the outer doubt.
Then, for that exacting row, the subquery is executed – as a result for each row processed by the outer query, the subquery will also be processed. In correlated subquery, each time a line is worked for Emp1, the subquery will also make a decision on the exacting row’s value for Emp1.Salary and run. And the outer query will move on to the next row, and the subquery will execute for that row’s value of Emp1.Salary.
It will persist in anticipation of the “WHERE (1) = (… )” state is pleased.

Read this insightful tutorial to learn usage of SQL Clauses.

7. When is the Explicit Cursor Used ?
If the developer needs to perform the row by row operations for the result set containing more than one row, then he unambiguously declares a pointer with a name. They are managed by OPEN, FETCH and CLOSE.%FOUND, %NOFOUND, %ROWCOUNT and %ISOPEN characteristics are used in all types of pointers.

8. Find What is Wrong in this Query?
SELECT subject_code, AVG (marks) FROM students WHERE AVG(marks) > 75 GROUP BY subject_code; The WHERE clause cannot be used to restrict groups. Instead, the HAVING clause should be used.
SELECT subject_code, AVG (marks)
FROM students
HAVING AVG(marks) > 75
GROUP BY subject_code;
9. Write the Syntax for STUFF function in an SQL server?
STUFF (String1, Position, Length, String2)
String1 – String to be overwritten
Position – Starting location for overwriting
Length – Length of substitute string
String2- String to overwrite.
10. Name some commands that can be used to manipulate text in T-SQL code. For example, a command that obtains only a portion of the text or replace a text string, etc.
CHARINDEX( findTextData, textData, [startingPosition] ) – Returns the starting position of the specified expression in a character string. The starting position is optional.
LEFT( character_expression , integer_expression ) – Returns the left part of a character string with the specified number of characters.
LEN( textData ) – Returns integer value of the length of the string, excluding trailing blanks.
LOWER ( character_expression ) – Returns a character expression after converting uppercase character data to lowercase.
LTRIM( textData) – Removes leading blanks. PATINDEX( findTextData, textData ) – Returns integer value of the starting position of text found in the string.
REPLACE( textData, findTextData, replaceWithTextData ) – Replaces occurrences of text found in the string with a new value.
REPLICATE( character_expression , integer_expression ) – Repeats a character expression for a specified number of times.
REVERSE( character_expression ) – Returns the reverse of a character expression.
RTRIM( textData) – Removes trailing blanks. SPACE( numberOfSpaces ) – Repeats space value specified number of times.
STUFF( textData, start , length , insertTextData ) – Deletes a specified length of characters and inserts another set of characters at a specified starting point.
SUBSTRING( textData, startPosition, length ) – Returns portion of the string.
UPPER( character_expression ) – Returns a character expression with lowercase character data converted to uppercase.
11. What are the three ways that Dynamic SQL can be executed?
Writing a query with parameters.
Using EXEC.
Using sp_executesql.
Get a clear understanding of SQL in this riveting blog.

12. In what version of SQL Server were synonyms released? How do synonyms work and explain its use cases? Synonyms were released with SQL Server 2005.
Synonyms enable the reference of another object (View, Table, Stored Procedure or Function) potentially on a different server, database or schema in your environment. In simple words, the original object that is referenced in the whole code is using a completely different underlying object, but no coding changes are necessary. Think of this as an alias as a means to simplify migrations and application testing without the need to make any dependent coding changes.
Synonyms can offer a great deal of value when converting underlying database objects without breaking front end or middle tier code. This could be useful during a re-architecture or upgrade project.
Become Master of SQL by going through this SQL training course.

Download SQL Interview Questions asked by top MNCs in 2018
GET PDF
13. If you are a SQL Developer, how can you delete duplicate records in a table with no primary key?
Use the SET ROWCOUNT command. For instance,
if you have 2 duplicate rows, you would SET ROWCOUNT 1, execute DELETE command and then SET ROWCOUNT 0.

14. Is it possible to import data directly from T-SQL commands without using SQL Server Integration Services? If so, what are the commands?
Yes, six commands are available to import data directly in the T-SQL language. These commands include :

BCP : The bulk copy (bcp) command of Microsoft SQL Server provides you with the ability to insert large numbers of records directly from the command line. In addition to being a great tool for command-line aficionados, bcp is a powerful tool for those seeking to insert data into a SQL Server database from within a batch file or other programmatic method.
Bulk Insert : The BULK INSERT statement was introduced in SQL Server 7 and allows you to interact with bcp (bulk copy program) via a script.
OpenRowSet : The OPENROWSET function can be referenced in the FROM clause of a query as if it were a table name. The OPENROWSET function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query might return multiple result sets, OPENROWSET returns only the first one.
OPENDATASOURCE : Provides ad hoc connection information as part of a four-part object name without using a linked server name.
OPENQUERY : Executes the specified pass-through query on the specified linked server. This server is an OLE DB data source. OPENQUERY can be referenced in the FROM clause of a query as if it were a table name.
Linked Servers : Configure a linked server to enable the SQL Server Database Engine to execute commands against OLE DB data sources outside of the instance of SQL Server. Typically linked servers are configured to enable the Database Engine to execute a Transact-SQL statement that includes tables in another instance of SQL Server, or another database product such as Oracle.
15. What is the native system stored procedure to execute a command against all databases?
The sp_MSforeachdb system stored procedure accepts the @Command parameter which can be exetecuted against all databases. The ‘?’ is used as a placeholder for the database name to execute the same command.
The alternative is to use a cursor to process specific commands against each database.
16. How can a SQL Developer prevent T-SQL code from running on a production SQL Server?
Use IF logic with the @@SERVERNAME function compared against a string with a RETURN command before any other logic.

17. How do you maintain database integrity where deletions from one table will automatically cause deletions in another table?
You can create a trigger that will automatically delete elements in the second table when elements from the first table are removed.

18. What port does SQL server run on?
1433 is the standard port for SQL server.

Go through this SQL Video to get clear understanding of SQL.

19. What is the SQL CASE statement used for? Explain with an example?
It allows you to embed an if-else like clause in the SELECT clause.

SELECT Employee_Name, CASE Location
WHEN ‘alex’ THEN Bonus * 2
WHEN ‘robin’ THEN Bonus *, 5
ELSE Bonus
END
“New Bonus”
FROM Intellipaat_employee;
Read this blog to learn why SQL Optimization has always been a important aspect of database management.

20. What are the risks of storing a hibernate-managed object in cache? How do you overcome the problems?
The primary problem here is that the object will outlive the session it came from. Lazily loaded properties won’t get loaded if needed later. To overcome the problem, perform cache on the object’s id and class and then retrieve the object in the current session context.

21. When is the use of UPDATE_STATISTICS command ?
Updating statistics ensures that queries compile with up-to-date statistics. However, updating statistics causes queries to recompile. We recommend not updating statistics too often because there is a performance tradeoff between improving query plans and the time it takes to recompile queries. The specific tradeoffs depend on your application. UPDATE STATISTICS can use tempdb to sort the sample of rows for building statistics.

Syntax

UPDATE STATISTICS table_or_indexed_view_name
[
{
{ index_or_statistics__name }
| ( { index_or_statistics_name } [ ,…n ] )
}
]
[ WITH
[
FULLSCAN
| SAMPLE number { PERCENT | ROWS }
| RESAMPLE
[ ON PARTITIONS ( { | } [, …n] ) ]
| [ ,…n ]
]
[ [ , ] [ ALL | COLUMNS | INDEX ]
[ [ , ] NORECOMPUTE ]
[ [ , ] INCREMENTAL = { ON | OFF } ]
] ;

::=
[ STATS_STREAM = stats_stream ]
[ ROWCOUNT = numeric_constant ]
[ PAGECOUNT = numeric_contant ]
22. What is SQL Profiler?
Microsoft SQL Server Profiler is a graphical user interface to SQL Trace for monitoring an instance of the Database Engine or Analysis Services. You can capture and save data about each event to a file or table to analyze later.

Use SQL Profiler to monitor only the events in which you are interested.

If traces are becoming too large, you can filter them based on the information you want, so that only a subset of the event data is collected. Monitoring too many events adds overhead to the server and the monitoring process and can cause the trace file or trace table to grow very large, especially when the monitoring process takes place over a long period of time.

23. What command using Query Analyzer will give you the version of SQL server and operating system?
SELECT SERVERPROPERTY (‘productversion’), SERVERPROPERTY (‘productlevel’), SERVERPROPERTY (‘edition’).

24. What does it mean to have QUOTED_IDENTIFIER ON? What are the implications of having it OFF?
When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.

25. What is the STUFF function and how does it differ from the REPLACE function in SQL?
Stuff function : – This function is used to replace string from the given start position, passed as 2nd argument with string passed as last argument. In Stuff function, 3rd argument defines the number of characters which are going to be replaced.
Syntax :-

STUFF ( character_expression , start , length , replaceWith_expression )
For example :-

Select Stuff (‘Intellipaat’, 3, 3, ‘abc’)
This query will return the string “Iabcllipaat”. In this example, Stuff function replaces the string “Intellipaat” onwards the 3rd position(‘nte’) with ‘abc’.
Replace Function :– Replace function is used to replace all occurrence of a specified with the string passed as last argument.
Syntax :-

REPLACE ( string_expression , string_pattern , string_replacement )
For example :-

Select Replace (‘Abcabcabc’, ‘bc’, ‘xy’)
This query will return the string Axyaxyaxy. In this example, Replace function replaces the occurrence of each ‘bc’ string with ‘xy’.
Learn SQL from Experts! Enrol Today

26. How to get @@ERROR and @@ROWCOUNT at the same time?
If @@Rowcount is checked after Error checking statement then it will have 0 as the value of @@Recordcount as it would have been reset. And if @@Recordcount is checked before the error-checking statement then @@Error would get reset. To get @@error and @@rowcount at the same time do both in same statement and store them in local variable.

SELECT @RC = @@ROWCOUNT, @ER = @@ERROR
27. What is de-normalization in SQL database administration? Give examples
De-normalization is used to optimize the readability and performance of the database by adding redundant data. It covers the inefficiencies in the relational database software.
De-normalization logical data design tend to improve the query responses by creating rules in the database which are called as constraints.
Examples include the following :

Materialized views for implementation purpose such as :
Storing the count of “many” objects in one-to-many relationship.
Linking attribute of one relation with other relations.
To improve the performance and scalability of web applications.
28. Can you explain about buffer cash and log Cache in SQL Server?
Buffer Cache : Buffer cache is a memory pool in which data pages are read. The ideal performance of the buffer cache is indicated as: 95% indicates that pages that were found in the memory are 95% of time. Another 5% is need physical disk access.
If the value falls below 90%, it is the indication of more physical memory requirement on the server.
Log Caches : Log cache is a memory pool used to read and write the log pages. A set of cache pages are available in each log cache. The synchronization is reduced between log and data buffers by managing log cache separately from the buffer cache.
29. Describe how to use Linked Server.
MS SQL Server supports the connection to different OLE DB on an ad hoc basis. This persistent connection is referred as Linked Server.
Following are the steps to use Linked Server for any OLE DB. You can refer this to use an MS-Excel workbook.

Open SQL Server Management Studio in SQL Server.
Expand Server Objects in Object Explorer.
Right-click on Linked Servers. Click on New Linked Server.
Select General page in the left pane and
Type any name for the linked server in the first text box.
Select the Other Data Source option.
Click on Microsoft Jet 4.0 OLE DB Provider from the Provider list.
Type the Excel as the name of the OLE DB data source.
Type the full path and file name of the Excel file in Data Source box.
Type the Excel version no. (7.0, 8.0 etc) in the Provider String. Use Excel 8.0 for Excel 2000, Excel 2002 or Excel 97.
To create a linked server click on OK.
30. How to find second highest salary of an Employee?
There are many ways to find second highest salary of Employees in SQ. You can either use SQL Join or Subquery to solve this problem.
Here is SQL query using Subquery :

Select MAX(Salary) from Intellipaat_emplyee WHERE Salary NOT IN ( select MAX(Salary) from Intellipaat_employee.
31. Explain how to send email from SQL database.
SQL Server has a feature for sending mails. Stored procedures can also be used for sending mail on demand. With SQL Server 2005, MAPI client is not needed for sending mails.
The following is the process for sending emails from database.

Make sure that the SQL Server Mail account is configured correctly and enable Database Mail.
Write a script to send an e-mail. The following is the script.
USE [YourDB]
EXEC msdb.dbo.sp_send_dbmail
@recipients = ‘xyz@intellipaat.com; abc@intellipaat.com;pqr@intellipaat.com’
@body = ‘ A warm wish for your future endeavor’,
@subject = ‘This mail was sent using Database Mail’ ;
GO
32. How to make remote connection in database?
The following is the process to make a remote connection in database :

Use SQL Server Surface Area Configuration Tool for enabling the remote connection in database.
Click on Surface Area Configuration for Services and Connections.
Click on SQLEXPRESS/Database Engine/RemoteConnections.
Select the radio button: Local and Remote Connections and select ‘Using TCP/IP only’ under Local and Remote Connections.
Click on OK button / Apply button
33. What is the purpose of OPENXML clause SQL server stored procedure?
OPENXML parses the XML data in SQL Server in an efficient manner. It’s primary ability is to insert XML data to the RDB. It is also possible to query the data by using OpenXML. The path of the XML element needs to be specified by using ‘xpath’.
The following is a procedure for retrieving xml data:

DECLARE @index int
DECLARE @xmlString varchar(8000)
SET @xmlString =’

abc
9343463943/PhoneNo>

xyz
9342673212


EXEC sp_xml_preparedocument @index OUTPUT, @xmlString
SELECT * FROM OPENXML (@index, ‘Persons/Person’) WITH (id varchar(10), Name varchar(100) ‘Name’ , PhoneNo varchar(50) ‘PhoneNo’)
EXEC sp_xml_removedocument @index
The above code snippet results the following:
15201 abc 9343463943
15202 xyz 9342673212
34. How to store pdf file in SQL Server?
Create a column as type ‘blob’ in a table. Read the content of the file and save in ‘blob’ type column in a table.
Or
Store them in a folder and establish the pointer to link them in the database.

35. Explain the use of keyword WITH ENCRYPTION. Create a Store Procedure with Encryption.
It is a way to convert the original text of the stored procedure into encrypted form. The stored procedure gets obfuscated and the output of this is not visible to

CREATE PROCEDURE Abc
WITH ENCRYPTION
AS
<< SELECT statement>>
GO
WITH ENCRYPTION indicates that SQL Server will convert the original text of CREATE PROCEDURE statement to an encrypted format. Users that do not have no access to system tables or database files cannot retrieve the encrypted text. However, the text will be available to privileged users.

Example:

CREATE PROCEDURE salary_sum
WITH ENCRYTION
AS
SELECT sum(salary)
FROM employee
WHERE emp_dept LIKE Develop

36. What is lock escalation?
Lock escalation is used to convert row locks and page locks into table locks thereby “escalating” the smaller or finer locks. This increases the system performance as each lock is nothing but a memory structure. Too many locks would mean more consumption of memory. Hence, escalation is used.
Lock escalation from SQL Server 7.0 onwards is dynamically managed by SQL Server. It is the process of converting a lot of low level locks into higher level locks.

37. What is Failover clustering overview?
Failover clustering is mainly used for data availability. Typically, in a failover cluster, there are two machines.

One machine provides the basic services and the second is available to run the service when the primary system fails.
The primary system is monitored periodically to check if it works. This monitoring may be performed by the failover computer or an independent system also called as cluster controller. In an event of failure of primary computer, the failover system takes control.
38. What is Builtin/Administrator?
The Builtin/Administrator account is basically used during some setup to join some machine in the domain. It should be disabled immediately thereafter. For any disaster recovery, the account will be automatically enabled. It should not be used for normal operations.

39. What XML support does the SQL server extend?
SQL Server (server-side) supports 3 major elements :

Creation of XML fragments: This is done from the relational data using FOR XML to the select query.
Ability to shred xml data to be stored in the database.
Finally, storing the xml data.
Client-side XML support in SQL Server is in the form of SQLXML. It can be described in terms of :

XML Views : providing bidirectional mapping between XML schemas and relational tables.
Creation of XML Templates : allows creation of dynamic sections in XML.
SQL server can return XML document using FOR XML clause. XML documents can be added to SQL Server database and you can use the OPENXML clause to display the data from the document as a relational result set. SQL Server 2000 supports XPath queries.

Question #1) What is SQL?

Structured Query Language is a database tool which is used to create and access database to support software application.

Question #2) What are tables in SQL?

The table is a collection of record and its information at a single view.

Question #3) What are different types of statements supported by SQL?

statements supported by SQL

There are 3 types of SQL statements

1) DDL (Data Definition Language): It is used to define the database structure such as tables. It includes three statements such as Create, Alter, and Drop.

Some of the DDL Commands are listed below

CREATE: It is used for creating the table.
1
CREATE TABLE&amp;amp;nbsp;table_name
2
column_name1 data_type(size),
3
column_name2 data_type(size),
4
column_name3 data_type(size),
ALTER: The ALTER table is used for modifying the existing table object in the database.
ALTER TABLE table_name
ADD column_name datatype

OR

ALTER TABLE table_name

DROP COLUMN column_name

2) DML (Data Manipulation Language): These statements are used to manipulate the data in records. Commonly used DML statements are Insert, Update, and Delete.

The Select statement is used as partial DML statement that is used to select all or relevant records in the table.

3) DCL (Data Control Language): These statements are used to set privileges such as Grant and Revoke database access permission to the specific user.

Question #4) How do we use DISTINCT statement? What is its use?

DISTINCT statement is used with the SELECT statement. If the records contain duplicate values then DISTINCT is used to select different values among duplicate records.

Syntax: SELECT DISTINCT column_name(s)
FROM table_name;

Question #5) What are different Clauses used in SQL?

Clauses used in SQL

WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill the given condition
Syntax: SELECT column_name(s)
FROM table_name
WHERE condition;

GROUP BY Clause: It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.
Syntax: SELECT column_name(s)
FROM table_name
GROUP BY column_name;

HAVING clause: This clause is used in association with GROUP BY clause. It is applied to the each group of result or the entire result as single group and much similar as WHERE clause, the only difference is you cannot use it without GROUP BY clause
Syntax: SELECT column_name(s)
FROM table_name
GROUP BY column_name
HAVING condition;

ORDER BY clause: This clause is to define the order of the query output either in ascending (ASC) or in descending (DESC) order. Ascending (ASC) is the default one but descending (DESC) is set explicitly.
Syntax: SELECT column_name(s)
FROM table_name
WHERE condition
ORDER BY column_name ASC|DESC;

USING clause: USING clause comes in use while working with SQL Joins. It is used to check equality based on columns when tables are joined. It can be used instead ON clause in Joins.
Syntax: SELECT column_name(s)
FROM table_name
JOIN table_name
USING (column_name);

Question #6) Why do we use SQL constraints? Which constraints we can use while creating database in SQL?

Constraints are used to set the rules for all records in the table. If any constraints get violated then it can abort the action that caused it.

Constraints are defined while creating the database itself with CREATE TABLE statement or even after the table is created once with ALTER TABLE statement.

There are 5 major constraints are used in SQL, such as

NOT NULL: That indicates that the column must have some value and cannot be left null
UNIQUE: This constraint is used to ensure that each row and column has unique value and no value is being repeated in any other row or column
PRIMARY KEY: This constraint is used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one columns to identify the particular record with a unique identity.
FOREIGN KEY: It is used to ensure the referential integrity of data in the table and also matches the value in one table with another using Primary Key
CHECK: It is used to ensure whether the value in columns fulfills the specified condition
Question #7) What are different JOINS used in SQL?

SQL Joins

There are 4 major types of joins made to use while working on multiple tables in SQL databases

INNER JOIN: It is also known as SIMPLE JOIN which returns all rows from BOTH tables when it has at least one column matched
Syntax: SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON column_name1=column_name2;

Example

In this example, we have a table Employee with the following data

Employee table

The second Table is joining

joining

Enter the following SQL statement

1
SELECT Employee.Emp_id, Joining.Joining_Date
2
FROM Employee
3
INNER JOIN Joining
4
ON Employee.Emp_id = Joining.Emp_id
5
ORDER BY Employee.Emp_id;
There will be 4 records selected. These are the results that you should see

result of innerjoin

Employee and orders tables where there is a matching customer_id value in both the Employee and orders tables

LEFT JOIN (LEFT OUTER JOIN): This join returns all rows from a LEFT table and its matched
rows from a RIGHT table.
Syntax: SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON column_name1=column_name2;

Example

In this example, we have a table Employee with the following data:

Employee table

Second Table is joining

joining 1

Enter the following SQL statement

1
SELECT Employee.Emp_id, Joining.Joining_Date
2
FROM Employee
3
LEFT OUTER JOIN Joining
4
ON Employee.Emp_id = Joining.Emp_id
5
ORDER BY Employee.Emp_id;
There will be 4 records selected. These are the results that you should see:

result of LEFT OUTER JOIN

RIGHT JOIN (RIGHT OUTER JOIN): This joins returns all rows from the RIGHT table and its matched rows from a LEFT table.
Syntax: SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON column_name1=column_name2;

Example

In this example, we have a table Employee with the following data

Employee table

The second Table is joining

joining 1

Enter the following SQL statement

1
SELECT Employee.Emp_id, Joining.Joining_Date
2
FROM Employee
3
LEFT OUTER JOIN Joining
4
ON Employee.Emp_id = Joining.Emp_id
5
ORDER BY Employee.Emp_id;
There will be 4 records selected. These are the results that you should see

result of RIGHT OUTER JOIN

FULL JOIN (FULL OUTER JOIN): This joins returns all when there is a match either in the RIGHT table or in the LEFT table.
Syntax: SELECT column_name(s)
FROM table_name1
FULL OUTER JOIN table_name2
ON column_name1=column_name2;

Example

In this example, we have a table Employee with the following data:

Employee table

Second Table is joining

joining 1

Enter the following SQL statement:

1
SELECT Employee.Emp_id, Joining.Joining_Date
2
FROM Employee
3
FULL OUTER JOIN Joining
4
ON Employee.Emp_id = Joining.Emp_id
5
ORDER BY Employee.Emp_id;
There will be 8 records selected. These are the results that you should see

result of FULL OUTER JOIN

Question #8) What are transaction and its controls?

A transaction can be defined as the sequence task that is performed on databases in a logical manner to gain certain results. Operations performed like Creating, updating, deleting records in the database comes from transactions.

In simple word, we can say that a transaction means a group of SQL queries executed on database records.

There are 4 transaction controls such as

COMMIT: It is used to save all changes made through the transaction
ROLLBACK: It is used to roll back the transaction such as all changes made by the transaction are reverted back and database remains as before
SET TRANSACTION: Set the name of transaction
SAVEPOINT: It is used to set the point from where the transaction is to be rolled back
Question #9) What are properties of the transaction?

Properties of transaction are known as ACID properties, such as

Atomicity: Ensures the completeness of all transactions performed. Checks whether every transaction is completed successfully if not then transaction is aborted at the failure point and the previous transaction is rolled back to its initial state as changes undone
Consistency: Ensures that all changes made through successful transaction are reflected properly on database
Isolation: Ensures that all transactions are performed independently and changes made by one transaction are not reflected on other
Durability: Ensures that the changes made in database with committed transactions persist as it is even after system failure
Question #10) How many Aggregate Functions are available there in SQL?

SQL Aggregate Functions calculates values from multiple columns in a table and returns a single value.

There are 7 aggregate functions we use in SQL

AVG(): Returns the average value from specified columns
COUNT(): Returns number of table rows
MAX(): Returns largest value among the records
MIN(): Returns smallest value among the records
SUM(): Returns the sum of specified column values
FIRST(): Returns the first value
LAST(): Returns Last value
Question #11) What are Scalar Functions in SQL?

Scalar Functions are used to return a single value based on the input values. Scalar Functions are as follows

UCASE(): Converts the specified field in upper case
LCASE(): Converts the specified field in lower case
MID(): Extracts and returns character from text field
FORMAT(): Specifies the display format
LEN(): Specifies the length of text field
ROUND(): Rounds up the decimal field value to a number
Question #12) What are triggers?

Triggers in SQL is kind of stored procedures used to create a response to a specific action performed on the table such as Insert, Update or Delete. You can invoke triggers explicitly on the table in the database.

Action and Event are two main components of SQL triggers when certain actions are performed the event occurs in response to that action.

Syntax: CREATE TRIGGER name {BEFORE|AFTER} (event [OR..]}
ON table_name [FOR [EACH] {ROW|STATEMENT}]
EXECUTE PROCEDURE functionname {arguments}

Question #13) What is View in SQL?

A View can be defined as a virtual table that contains rows and columns with fields from one or more table.

Syntax: CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

Question #14) How we can update the view?

SQL CREATE and REPLACE can be used for updating the view.

Following query syntax is to be executed to update the created view

Syntax: CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

Question #15) Explain the working of SQL Privileges?

SQL GRANT and REVOKE commands are used to implement privileges in SQL multiple user environments. The administrator of the database can grant or revoke privileges to or from users of database object like SELECT, INSERT, UPDATE, DELETE, ALL etc.

GRANT Command: This command is used provide database access to user apart from an administrator.

Syntax: GRANT privilege_name
ON object_name
TO {user_name|PUBLIC|role_name}
[WITH GRANT OPTION];

In above syntax WITH GRANT OPTIONS indicates that the user can grant the access to another user too.

REVOKE Command: This command is used provide database deny or remove access to database objects.

Syntax: REVOKE privilege_name
ON object_name
FROM {user_name|PUBLIC|role_name};

Question #16) How many types of Privileges are available in SQL?

There are two types of privileges used in SQL, such as

System Privilege: System privileges deal with an object of a particular type and specifies the right to perform one or more actions on it which include Admin allows a user to perform administrative tasks, ALTER ANY INDEX, ALTER ANY CACHE GROUP CREATE/ALTER/DELETE TABLE, CREATE/ALTER/DELETE VIEW etc.
Object Privilege: This allows to perform actions on an object or object of another user(s) viz. table, view, indexes etc. Some of the object privileges are EXECUTE, INSERT, UPDATE, DELETE, SELECT, FLUSH, LOAD, INDEX, REFERENCES etc.
Question #17) What is SQL Injection?

SQL Injection is a type of database attack technique where malicious SQL statements are inserted into an entry field of database such that once it is executed the database is opened for an attacker. This technique is usually used for attacking Data-Driven Applications to have an access to sensitive data and perform administrative tasks on databases.

For Example: SELECT column_name(s) FROM table_name WHERE condition;

Question #18) What is SQL Sandbox in SQL Server?

SQL Sandbox is the safe place in SQL Server Environment where untrusted scripts are executed. There are 3 types of SQL sandbox, such as

Safe Access Sandbox: Here a user can perform SQL operations such as creating stored procedures, triggers etc. but cannot have access to the memory and cannot create files.
External Access Sandbox: User can have access to files without having a right to manipulate the memory allocation.
Unsafe Access Sandbox: This contains untrusted codes where a user can have access to memory.
Question #19) What is the difference between SQL and PL/SQL?

SQL is a structured query language to create and access databases whereas PL/SQL comes with procedural concepts of programming languages.

Question #20) What is the difference between SQL and MySQL?

SQL is a structured query language that is used for manipulating and accessing the relational database, on the other hand, MySQL itself is a relational database that uses SQL as the standard database language.

Question #21) What is the use of NVL function?

NVL function is used to convert the null value to its actual value.

Question #22) What is the Cartesian product of table?

The output of Cross Join is called as a Cartesian product. It returns rows combining each row from the first table with each row of the second table. For Example, if we join two tables having 15 and 20 columns the Cartesian product of two tables will be 15×20=300 Rows.

Question #23) What do you mean by Subquery?

Query within another query is called as Subquery. A subquery is called inner query which returns output that is to be used by another query.

Question #24) How many row comparison operators are used while working with a subquery?

There are 3-row comparison operators which are used in subqueries such as IN, ANY and ALL.

Question #25) What is the difference between clustered and non-clustered indexes?

One table can have only one clustered index but multiple nonclustered indexes.
Clustered indexes can be read rapidly rather than non-clustered indexes.
Clustered indexes store data physically in the table or view and non-clustered indexes do not store data in table as it has separate structure from data row
Question #26) What is the difference between DELETE and TRUNCATE?

The basic difference in both is DELETE is DML command and TRUNCATE is DDL
DELETE is used to delete a specific row from the table whereas TRUNCATE is used to remove all rows from the table
We can use DELETE with WHERE clause but cannot use TRUNCATE with it
Question #27) What is the difference between DROP and TRUNCATE?

TRUNCATE removes all rows from the table which cannot be retrieved back, DROP removes the entire table from the database and it cannot be retrieved back.

Question #28) How to write a query to show the details of a student from Students table whose
name starts with K?

SELECT * FROM Student WHERE Student_Name like ‘%K’;

Here ‘like’ operator is used for pattern matching.

Question #29) What is the difference between Nested Subquery and Correlated Subquery?

Subquery within another subquery is called as Nested Subquery. If the output of a subquery is depending on column values of the parent query table then the query is called Correlated Subquery.

SELECT adminid(SELEC Firstname+’ ‘+Lastname FROM Employee WHERE
empid=emp. adminid)AS EmpAdminId FROM Employee

This query gets details of an employee from Employee table.

Question #30) What is Normalization? How many Normalization forms are there?

Normalization is used to organize the data in such manner that data redundancy will never occur in the database and avoid insert, update and delete anomalies.

There are 5 forms of Normalization

First Normal Form (1NF): It removes all duplicate columns from the table. Creates table for related data and identifies unique column values
First Normal Form (2NF): Follows 1NF and creates and places data subsets in an individual table and defines relationship between tables using primary key
Third Normal Form (3NF): Follows 2NF and removes those columns which are not related through primary key
Fourth Normal Form (4NF): Follows 3NF and do not define multi-valued dependencies. 4NF also known as BCNF
Question #31) What is Relationship? How many types of Relationship are there?

The relationship can be defined as the connection between more than one tables in the database.

There are 4 types of relationships

One to One Relationship
Many to One Relationship
Many to Many Relationship
One to Many Relationship
Question #32) What do you mean by Stored Procedures? How do we use it?

A stored procedure is a collection of SQL statements which can be used as a function to access the database. We can create these stored procedures previously before using it and can execute these them wherever we require and also apply some conditional logic to it. Stored procedures are also used to reduce network traffic and improve the performance.

Syntax: CREATE Procedure Procedure_Name
(
//Parameters
)
AS
BEGIN
SQL statements in stored procedures to update/retrieve records
END

Question #33) State some properties of Relational databases?

In relational databases, each column should have a unique name
Sequence of rows and columns in relational databases are insignificant
All values are atomic and each row is unique
Question #34) What are Nested Triggers?

Triggers may implement data modification logic by using INSERT, UPDATE, and DELETE statement. These triggers that contain data modification logic and find other triggers for data modification are called Nested Triggers.

Question #35) What is Cursor?

A cursor is a database object which is used to manipulate data in a row-to-row manner.

Cursor follows steps as given below

Declare Cursor
Open Cursor
Retrieve row from the Cursor
Process the row
Close Cursor
Deallocate Cursor
Question #36) What is Collation?

Collation is set of rules that check how the data is sorted by comparing it. Such as Character data is stored using correct character sequence along with case sensitivity, type, and accent.

Question #37) What do we need to check in Database Testing?

Generally, in Database Testing following thing is need to be tested

Database Connectivity
Constraint Check
Required Application Field and its size
Data Retrieval and Processing With DML operations
Stored Procedures
Functional flow
Question #38) What is Database White Box Testing?

Database White Box Testing involves

Database Consistency and ACID properties
Database triggers and logical views
Decision Coverage, Condition Coverage, and Statement Coverage
Database Tables, Data Model, and Database Schema
Referential integrity rules
Question #39) What is Database Black Box Testing?

Database Black Box Testing involves

Data Mapping
Data stored and retrieved
Use of Black Box techniques such as Equivalence Partitioning and Boundary Value Analysis (BVA)
Question #40) What are Indexes in SQL?

The index can be defined as the way to retrieve the data more quickly. We can define indexes using CREATE statements.

Syntax: CREATE INDEX index_name
ON table_name (column_name)

Further, we can also create Unique Index using following syntax;

Syntax: CREATE UNIQUE INDEX index_name
ON table_name (column_name)

******************

UPDATE: Added more questions for your practice.

Q#41. What does SQL stand for?
Ans. SQL stands for Structured Query Language.

Q#42. How to select all records from the table?
Ans. To select all the records from the table we need to use the following syntax:

Select * from table_name;

Q#43. Define join and name different types of joins?
Ans. Join keyword is used to fetch data from related two or more tables. It returns rows where there is at least one match in both the tables included in the join. Read more here.
Type of joins are:

Right Join
Outer Join
Full Join
Cross Join
Self Join.
Q#44. What is the syntax to add a record to a table?
Ans. To add a record in a table INSERT syntax is used.

Ex: INSERT into table_name VALUES (value1, value2..);

Q#45. How do you add a column to a table?
Ans. To add another column in the table following command has been used.

ALTER TABLE table_name ADD (column_name);

Q#46. Define SQL Delete statement.
Ans. Delete is used to delete a row or rows from a table based on the specified condition.
The basic syntax is as follows:

DELETE FROM table_name

WHERE

Q#47. Define COMMIT?
Ans. COMMIT saves all changes made by DML statements.

Q#48. What is a primary key?
Ans. A Primary key is a column whose values uniquely identify every row in a table. Primary key values can never be reused.

Q#49. What are foreign keys?
Ans. When a one table’s primary key field is added to related tables in order to create the common field which relates the two tables, it called a foreign key in other tables.
Foreign Key constraints enforce referential integrity.

Q#50. What is CHECK Constraint?
Ans. A CHECK constraint is used to limit the values or type of data that can be stored in a column. They are used to enforce domain integrity.

Q#51. Is it possible for a table to have more than one foreign key?
Ans. Yes, a table can have many foreign keys and only one primary key.

Q#52. What are the possible values for the BOOLEAN data field?
Ans. For a BOOLEAN data field, two values are possible: -1(true) and 0(false).

Q#53. What is a stored procedure?
Ans. A stored procedure is a set of SQL queries which can take input and send back output.

Q#54. What is identity in SQL?
Ans. An identity column in the SQL automatically generates numeric values. We can define a start and increment value of identity column.