Basic SQL Server

  Home  MS SQL Server  Basic SQL Server


“SQL Database Concepts frequently Asked Questions by expert members with experience in Basic SQL Database Concepts. These interview questions and answers on SQL Database Concepts will help you strengthen your technical skills, prepare for the interviews and quickly revise the concepts. So get preparation for the SQL Database Concepts job interview”



113 Basic SQL Server Questions And Answers

21⟩ Can you explain various data region available in SSRS with their use?

Data regions are report items used to display data from a single dataset. You can perform grouping, sorting and various aggregate functions on data in data region. In SSRS 2005, there were 4 data regions:-

1. Table

2. Matrix

3. List

4. Chart

While in SSRS 2008, there are one additional data region namely Gauge.

Let’s explain each one of them:

1. Table - Table Data region has fixed tabular structure i.e. fixed number of columns. It is useful for displaying data grouped by row. You can have maximum of 1 report item per cell. The size of table depends on number of rows dataset fetches i.e., if number of rows returned by dataset is more; it can expand to multiple pages.

2. Matrix – A matrix data region display data in pivot table format, hence also popularly known as pivot table or crosstab report. It has minimum of one row group and one column group. The size of matrix data region depends on columns and rows fetched.

3. List - A list data region is free layout. It is useful for complex reporting resign. The list can be used to display multiple table and matrix. Each getting data from different dataset.

4. Chart – This data region is for displays the data graphically i.e., in form of chart. A various chart types are available in SSRS 2008 namely line, pie chart, columns etc.

5. Gauge - This can be used in a table or matrix to show the relative value of a field in a range of values in the data region. You can also add a gauge to the design surface to show a single relative value.

 168 views

22⟩ Can you explain what are various ways to enhance the SSRS report?

There are various ways in which you can enhance your report:

1. Display your data in graphic format using Chart Region.

2. Use sorting.

3. If couple of reports are related, you can make them interactive using connect them using bookmark link, hyper link or drill through report link.

4. Adding sub-report. Sub-report is a stand-alone report which can be link to another report based on its content using parameter.

5. Add custom fields. Custom fields provide with same functionality as alias columns provide in SQL server query. It is the timing of the operation that differs from the alias columns. The calculation is performed on dataset by report server.

6. Using expression.

7. Using custom code. SSRS allows including custom code written in VB.Net. 8. Add document map (navigational links to report item once report is rendered) to report.

 193 views

24⟩ Explain how to integrate the SSRS reports in application?

There are 3 ways in which you can integrate reports into your application:-

1. Navigating to URL i.e. https:\servernamereportservernamereportname – This is simplest and most popular way. A separate login might be required since we are directly calling the report from report server. Address of report server gets expose to user.

2. Using IFrame, Browser control or Report Viewer Control – In this approach, we embed the URL of report server in our application, hence address of reportserver is not exposed. No separate window opens. A user does not come to know that he has moved to different server.

3. Programmatically sending a web request using SOAP to report server.

 179 views

25⟩ Can you explain what is the use of custom fields in report?

Custom fields can be defined as alias column of the report since the operation is performed on report server rather than on database server. The custom field is very useful for the data manipulation like adding some fields whose value can be calculated based on expression, text e.g. instead of CName fetched from database, I want the dataset to display Customer Name etc.

We can add custom fields as right click on dataset, select add in Dataset window. The New field dialog box will open, we can add name of custom field and also mention whether it is database field or calculated one. If it is calculated, then we can mention the computation in this window.

 174 views

26⟩ Tell me can we use custom code in SSRS?

Yes, we can. SSRS allows developer to add custom code in your report. You can write the code directly into embedded VB.Net and call it using property expression or you can write a custom class library and refer it in report server. The advantage of first method is that it is simple and easy to use but disadvantage is that it is available for that report only. While the second method has advantage of being available for multiple reports but it has much of configuration overhead.

To write custom code, right click on Report Designer outside report body and select Properties and go to Code tab and you can write custom code here.

To add custom class library, right click on Report Designer outside report body and select Properties and go to Reference tab and add the reference by browsing to the assembly of your class library. Note that you need to create class library and then compile it before referencing it in your SSRS report.

 175 views

27⟩ How SSRS maintain security?

Reporting services maintain role based security. When a user logs into reporting services, a Report Manager (whose duty is to maintain security of Reporting Services) first checks the identity of user and then determine what rights he have to perform on report.

Report Manager manages the security at 2 levels –

1. System-level – Administer the report server globally

2. Item-level – Security at report and dataset level

System-level roles are:-

1. System Administrator – can manage report server and report manager security

2. Site User - view basic information like report properties and schedules.

Item-level roles – User can use any of predefined item-level roles or create their own roles by using combination of predefined item-level roles.

Pre-defined Item-level roles are:-

1. Browser – can navigate to report and run them.

2. My Reports – these users’ rights is restricted to reports present in their MyReports folder. However, they can create, view and manage reports in their folder.

3. Publisher – As name suggest, publisher user has rights to publish reports to Reporting Server database.

4. Content Manager – has all permission at item-level.

 176 views

30⟩ Explain features and concepts of Analysis Services?

Analysis Services is a middle tier server for analytical processing, OLAP, and Data mining. It manages multidimensional cubes of data and provides access to heaps of information including aggregation of data One can create data mining models from data sources and use it for Business Intelligence also including reporting features.

Some of the key features are:

Ease of use with a lot of wizards and designers.

Flexible data model creation and management

Scalable architecture to handle OLAP

Provides integration of administration tools, data sources, security, caching, and reporting etc.

Provides extensive support for custom applications

 182 views

31⟩ Do you know what is SQL Injection?

SQL Injection is an attack in which attacker take the advantage of insecure application over internet by running the SQL command against the database and to steal information from it that too using GUI of the website.

This attack can happen with the applications in which SQL queries are generated in the code.

The attacker tries to inject their own SQL into the statement that the application will use to query the database.

For example suppose the below query string is used for a search feature in a website and a user may have the inserted “Arpit” as the keyword to search. If in the code behind the keyword is directly used into the SQL statement, it will be like.

String sql = “Select EmpName, City from EmployeeMaster where EmpName like ‘%” + txtSearch.Text + “%’”;

But the attacker might enter the keyword like

‘ UNION SELECT name, type, id from sysobjects;--

This way attacker can get details of all the objects of the application database and using that attacker can steal further information.

 184 views

32⟩ Explain what is Analysis service repository?

Each server running analysis service has a repository to store objects of the computer running Analysis Services an Analysis service repository stores the information about the cubes, dimensions and other objects of the analysis server. By default the repository is an .mdb database on the server computer where the analysis service is installed..

 187 views

33⟩ Explain what is DBCC?

DBCC stands for Database Consistency Checker.

These commands are used to check the consistency of the database like validation tasks, maintenance and status checks.

For example –

1. DBCC CHECKALLOC – It is used to check that all pages are correctly allocated in database.

2. DBCC CHECKDB – It is used to check that

3. DBCC SQLPERF – It generates a report for the current usage of

4. DBCC SQLFILEGROUP – It used to check all the tables file group for any design.

 161 views

34⟩ Do you know what is SQL service broker?

Service Broker allows internal and external processes to send and receive guaranteed, asynchronous messaging. Messages can also be sent to remote servers hosting databases as well. The concept of queues is used by the broker to put a message in a queue and continue with other applications asynchronously. This enables client applications to process messages at their leisure without blocking the broker. Service Broker uses the concepts of message ordering, coordination, multithreading and receiver management to solve some major message queuing problems. It allows for loosely coupled services, for database applications.

 179 views

35⟩ Tell me what is difference between View and Materialized view?

View result set doesn’t save anywhere on disk and executes the query definition whenever they are called, while materialized view are disk based and its result set table is updated periodically.

Materialized view is similar to regular views but the output of select query has been saved to a table.

View shows the latest data all the time while the materialized view only shows the fresh data after its result table is updated either by setting a schedule or based on the change in the underlying tables.

The performance of the view depends on how good the selected statement the view has. If the select statement has too many joins then it the view will perform poorly.

While in the case of materialized view, we are querying a table, which may also be indexed, that increase its performance.

 169 views

36⟩ Do you know what is user defined datatypes and when you should go for them?

User defined data types are based on system data types. They should be used when multiple tables need to store the same type of data in a column and you need to ensure that all these columns are exactly the same including length, and nullability.

Parameters for user defined datatype:

Name

System data type on which user defined data type is based upon.

Nullability

For example, a user-defined data type called post_code could be created based on char system data type.

 167 views

37⟩ Explain what is CTE (Common Table Expression)?

When a complex SQL statement has number of joins then it can be made easier by using Common Table Expression.

Consider the following SQL statement.

SELECT * FROM (

SELECT emp.EmpName,dept.Department,emp.Gender FROM Employee emp

left join Department dept on emp.DeptID = dept.DeptID) E

WHERE E.Gender = ‘Male’

ORDER BY T.EmpName

The syntax of CTE is as follow

- The CTE Name (followed by WITH keyword)

- The Column List (Optional)

- The Query (Appears within parentheses after the AS keyword)

If we write the above messy query using CTE it would be like

With E(EmpName, Department, Gender)

AS

(

SELECT emp.EmpName,dept.Department,emp.Gender FROM Employee emp

left join Department dept on emp.DeptID = dept.DeptID

)

SELECT * FROM E

WHERE E.Gender = ‘Male’

ORDER BY E.EmpName

This way the query can be made more readable and easy to understand.

 184 views

39⟩ Do you know what is blocking?

Blocking happens when one connection from an application holds a lock and a second connection requires a conflicting lock type. This forces the second connection to wait, blocked on the first..

 153 views

40⟩ Tell me what is difference between clustered and non clustered index?

A table can have only one Clustered Index at a time which is generally created on primary key and can have more than one non clustered indexes (maximum up to 999)

The leaf level of clustered index is actual data pages of the table. Whereas in case of non-clustered index the leaf level is a pointer to the data.

Non-clustered index is faster than clustered index because when we use DML statement on clustered index, performance issues may occurred since it has to update the index every time a DML statement is executed.

Syntax of creative clustered / non clustered index is as follow

CREATE [CLUSTERED | NON CLUSTERED] INDEX index_name

ON <object> (column [ASC | DESC] [,…n])

 170 views