SSRS Reporting Tutorials

Share Embed Donate


Short Description

SSRS Reporting Tutorial for sql server 2008...

Description

Lesson 0 : SSRS Tutorials - An Introduction In this set of tutorials, we will be learning microsoft sql server 2008 reporting services. As far as possible we will use the adventure works database, which is available here. We will also walk through various ms sql server 2008 tools. This set of tutorials, is designed for anyone with absolutely no experience in business intelligence SSRS or sql server reporting services. We will also walk through sql reporting services configuration, creating your first report, deploying, security etc.

Basic course outline -Lesson 1: What is SSRS? -Lesson 2: How to Install SSRS -Lesson 3: Installing sql server 2008 sample database -Lesson 4 : Creating your first SSRS report. -Lesson 5: Knowing your development environment -Lesson 6: Making your first SSRS report (non-wizard) method -Lesson 7: Creating an SSRS parameterized report -Building your first report (formatting/calculations) -Understanding the SSRS toolbox -How to group and sort -Understanding datasources -More about Reporting Services security

-Use Reporting services API's -Manage reports using caching/snapshots/subscription -More about report Builder

Lesson 1 : What is SSRS?

Goto Introduction Page | Previous Lesson | Next Lesson           

SSRS or SQL server Reporting Services which is also called Microsoft SQL reporting, is a component of the Microsoft BI stack. The Microsoft Business Intelligence Stack mainly consists of SQL Database Engine, SSRS, SSAS, SSIS and other tools SSRS is a set of readymade tools, that helps you to create, deploy and manage reports. You can extend reporting functionality using C# and VB as programming languages. Microsoft SSRS or Business Intelligence SSRS, lets you create very rich reports (Tabular/Graphical/Interactive/free-form) from various datasources with rich data visualization (Charts, Maps, sparklines). All these reports can be viewed via a web browsers. SSRS allows are reports to be exported in various formats (Excel, PDF, word etc) SSRS allows reports to be delivered via emails or dropped to a share location in an automated fashion. SSRS provides a host of security features, in order to control, who sees which reports etc. You can download some samples from here. Next, lets look at how to install SSRS and get you started.

Lesson 2 : SQL Server Reporting Services Installation

Goto Introduction Page | Previous Lesson | Next Lesson

Lets move forward with getting to know how to install sql server 2008 reporting services. Please note, most of the steps are the same for installing sql server reporting services 2005. Below are the steps to install SQL reporting services 2008 with express Database. Step 1 : Download the 64 bit or 32 bit version of SQL 2008 Express with advances services from here . Step 2: Right Click on the downloaded file and "Run as Administrator".

Step 3: The files will extract itself.

Step 4: In case you get a pop-up saying "This program has compatibility issues", click Run Program.

Step 5: You should be getting a progress screen.

Step 6: The SQL server Installation Center should fire up.

Step 7 : Select installation on right hand tab and click on "New SQL server stand -alone installation"

Step 8: SQL server will load the setup files.

Step 9 : Click OK, it should take you to next page.

Step 10 : Click Install.

Step 11: Click next, then again next.

Step 12 : Click next

Step 13 : In feature selection, make sure you select 'Database Engine Services' and 'Reporting Services'

Step 14 : Next, select Named Instance and give it any name (you can also choose Default instance) Step 15 : Click next

Step 16 : Select Mixed Mode --> enter in any password --> and specify SQL server admins.

Step 17 : Click next, and select 'Install, but do not configure under Reporting Services configuration.

Step 18 : Click Next

Step 19 : Click Next

Step 20 : Click Install.

Step 21: After Installation is done, click next

Step 22 : Click Next.

Your installation is almost complete. In order to start using SSRS, you need to perform a few more steps. Step 23: Click Start --> All programs --> Microsoft SQL 2008 --> Configuration Tools --> Reporting Services Configuration --> select your instance Step 24 : Click web service URL on the left hand side and click the apply button. Step 25 : Click database on the left hand side, select change database --> create a new report server database and complete the steps. Step 26 : Click report manager URL and click apply (Note down the URL displayed. It should be of the form http://machinename/reports) Step 27: open IE and hit the noted down URL

Step 28 : You should get a screen like this.

That's all. We are all set. Let's install some sample databases and get started learning SSRS 2008 This video in YouTube, describes with a brief demo:

Lesson 3: Installing Sample databases (Adventure Works) Goto Introduction Page | Previous Lesson | Next Lesson Next, lets install some sample databases for us to work with. One of the most commonly used databases is the SQL adventureworks database. SQL server adventureworks database download is available here. Once you download the database, lets look at how to setup sql database.

Step 1: Install your downloaded database (sql server 2008 sample databases download), by choosing the correct instance name.

Step 2: After installation, open SSMS --> your instance name, then check if the below databases are visible.

Step 3: You can also install some sample reports from here

This video, gives a brief demo :

Lesson 4 : Creating your first SSRS report.

Goto Introduction | Previous Lesson | Next Lesson Now that you are all set with installing SSRS 2008 and some SQL server adventure works database, Let us proceed with creating our first SSRS report, deploying the same and viewing in the web browser. For report development , we will use Microsoft Business Intelligence Development studio. Quite often people ask me, how to install Business intelligence Development studio. Installing

business intelligence Development studio, is as simple as adding components to an existing SQL installation. Just run the SQL setup again, and choose add features to an existing installation, and choose select the required features you need. Lets follow a step by step process to create your first Business Intelligence Report. Step 1: Open Business Intelligence Development Studio (BIDS) (Start --> Microsoft SQL server 2008 --> SQL server Business Intelligence studio Step 2: Click File --> New project --> Report Server Project Wizard. Give any name and location.

Step 3: Once you click OK, you will be presented with the following screen.

Step 4 : Click Next. Now configure your connection string. I have chosen the type as 'Microsoft SQL server'

Step 5 : In this step, you need to enter the query for the data, that you need the SSRS report to be populated with. You can also use the query builder.

Step 6 : Click on query builder, and click on the right most top icon, to add tables

Step 7: Select the necessary table, and verify your query, then click the (!) icon to see the result of the query after execution.

Step 8: If everything looks good, click on Next

Step 9 : Click Next

Step 10: Add the fields, as shown in the below screenshot.

Step 11 : Click next

Step 12 : Choose a style, and click next.

Step 13 : Choose a deployment location. It will be in the form (http://machinename/Reportserver)

Step 14 : Click Next.

Step 15 : You can preview the report in Business Intelligence Development Studio.

Step 16 : Now, Right click the project , and click deploy.

Step 17 : After successfully deploying the project, open up IE, and hit http://machinename/reports

Step 18 : Click on your report to open it.

Congratulations! You have made your first SSRS report.

You can find an interesting video here -

Lesson 5: Knowing your development env. (BIDS) Goto Lesson 0 Alright, now we have published our first simple SSRS report using the Reporting Wizard. We deployed the report, and viewed it via a web browser. Next, we will understand, how to develop reports, without the custom report creation wizard. This will give much better control, over developing custom reports. (Eg. you need to add custom calculations, embed maps etc. When you fire up, Microsoft Business Intelligence Development studio - it looks like this.

The Left side portion, is where you set up your data connections, what parameters your report should use, the queries, that return data for your report etc.

The middle portion, is where you actually develop the report. Eg. Setup tabular reports, matrix reports or embed maps, graphics etc The Right side portion, is called the solution explorer. It lists down all reports (also called RDL's or report definition language) to be displayed. Report definition languages are pure XML file. Pressing control+Alt+X brings up the toolbox.

Here you see a number of tools, that aid you in your report development. You simply need to drag and drop the tools, that you need in your report, and then configure it accordingly. We will have a look at some of them in the coming lessons.

Lesson 6: Making your first SSRS report (non-wizard) method Lets proceed towards making a simple SSRS report. This time, we will not be using the wizard to create our report, but we will make use of the toolbox, and report designer to create our report. Most of the report development that you do using Microsoft SQL server reporting services, would be using the non-wizard method. This allows more flexibility to your report development. Step 1: Open Microsoft Business Intelligence studio, and create a report server project. Step 2: Next lets configure the datasources and datasets.

Step 3: right click on the "Data sources" folder and add a new data source. Set the connection string to point to your new adventure works database. Step 4: Once that is done, right click on the datasets folder, to add a dataset. This is basically the place, where you will configure your query that returns some data, that you want to be displayed in the report.

Select the datasource, that you just created and type in a query. You could also use the "Query Designer" if you want.

After eveything is done, click ok Step 5: Now from the toolbox, drag and drop a table control.

Step 6: From the "Report Data", drag and drop the columns defined in the dataset, that you want in the report.

Step 7: That's it, click on the preview tab and congratulations, you have made your first Microsoft SQL server report using a non-wizard method.

Lesson 7: Creating an SSRS parameterized report Lets proceed towards making a simple SSRS report with parameters. This lesson, should give you an idea, as to how to control the data in the reports using parameters. Lets consider the same report, that we made in Lesson 6. We are going to expose the postal code as a parameter. This means, we will see the address of only the entered postal code. Step 1: Modify the query in the dataset, to make PostalCode as a parameter

Step 2: Once you click OK, go to the parameters folder in "Report Data" - you will find that @postalcode automatically appears in the "Parameters" Fields.

Step 3: Lets explore more about the parameter. Double click on @postalcode. This is place, where you configure, how your parameter should behave - should it allow blank values or null values etc. You can configure the visibility, data-types, default values etc. Lets leave it as it is for now.

Step 4: Click preview, and enter in a postal code (91370 for example)

Note: Observe that the parameter appears as a text box here. If you want pre-configured values (in a dropdown), double click on the parameter in "ReportData" --> Parameters (here, @postalcode) and click "Available Values"/"Default value" and click "Get values from a query". You can choose your dataset and corresponding column. Create multiple datasets to suffice your parameter value requirements.

Lesson 8: SSRS Expressions Next, lets move on to creating expressions in SQL server reports. Expressions can be used for a number of things. The best part is that it operates on a cell by cell basis.

Hence, you can write expressions to manipulate the data, or change the properties of cell etc. Even if you are dealing with graphs and maps, many of the properties, you can control using expressions (like color of graph, some values etc). Basically you would want to write expressions, if you need to manipulate properties/data at runtime

Lets look at a very simple example.

Step 1: Create a report server project and connect to Adventure Works Database. Step 2: Add the SalesOrderDetail table with a couple of columns to the Report.

Step 3: In the toolbox, add the table control to the report.

Step 4: Add 3 columns to the report - SalesOrderID, SalesOrderDetailID, OrderQty, LineTotal.

Step 5: Now lets write some expressions. We will display anything in LineTotal cell as Green, if the number is above 2000, else we will display in Red. Right click on the cell , and select text-box properties.

Step 6: Next to the colr dropdown, there is an Fx button. Write the below expression.

Step 7 : Click OK and then on the Preview button. You should be getting the final output as displayed below.

Step 8: Now lets write some expressions to manipulate some data. Right click on the OrderQuantity Cell and click on expressions. Enter the below expression and click OK.

Step 9: Click on the preview tab, you should get the below output.

I have demonstrated a very simple use of expressions. However , you can write very complex expressions depending on your business needs. For instance, you can write expressions, to calculate the standard deviation of so and so , and manipulate results accordingly. Many time, you need to write expressions to deal with Dates and times For information on: http://msdn.microsoft.com/en-us/library/ms157328.aspx Thanks for reading my post, and let me know of your feedback

Lesson 9: Creating a SSRS tabular report

Creating SSRS tabular reports, is one of the simplest and easiest task. Tabular reports implies, just simple data representation using tables. SSRS makes creating tabular report super simple - just drag and drop data elements. It gives you the ability to add totals etc, as we do in excel. Lets look at some basic steps to create a SSRS tabular report. Step 1: Create an SSRS report server project. Step 2: Next add a blank report to your project. Step 3: Next we need to create a Dataset. In the Report data tab, right click on Datasets and complete the wizard. I am using Adventure works database for this demo.

Step 4: Add a query to get some data to your report.

Step 5: Now drag and drop a table control from the tool box (Left hand pane) In the table control, drag and drop some fields from your dataset. Once done, your Design pane should look something like this.

Step 6: Click on the preview tab, and you should be able to see a very basic tabular report. Step 7: You could also add some totals to your report. In order to add totals, right click on the cell where you would like to add the totals, click on 'Add Total'. Click preview and you should be able to see a tabular report with totals.

Lesson 10: Formatting an SSRS report. In this tutorial, lets look at how to format an SSRS report. SSRS, just like Microsoft word or any other text tool, provides some WYSIWYG editor. That means at design you can format the text (make it bold, italicize etc). SSRS also has some ways where-in you can format the display of dates, currency etc. Lets look at some of them in this tutorial. Step 1: Create a basic tabular report, using Adventure works database. The report would look something like this.

Making the headings bold, Italics, underlined. Step 2: In the design view, select the cells in the report, where you want to apply the formatting. You could either use any of the shortcut keys (like cntrl + B, cntrl + I, cntrl + U) on you can use the icons in the toolbar.

Similarly try adding some background color or text color. Play around with bullets and numbering. The same toolbar, also allows you to set the alignment of text. Step 3: Some of the features are given in the screenshot below.

Step 4: Lets explore some other formatting features. Lets create a report, which has some dates and some currency. Preferably you can use the following query from AdventureWorks database.

SELECT

TOP (100) *

FROM

Sales.SalesOrderDetail

Step 5: Once you create a report, using the above query, your report would look something like this.

Step 6: Now lets play around with some Currency formatting and date formatting. Right click on the unit price cell. Click on text box properties. On the left hand pane, click Number --> Currency

Step 7: Now lets do some formatting for dates. Right click on ModifiedDate --> Number --> Date

Step 8: After choosing your money and date format, click preview and report should look something like this.

Lesson 11: SSRS grouping and totals Many times we need to group the data in order to drill down further. To put it simply, imagine you have a report which gives you sales amount for each of the continent. You might want to drill down into each of these continents and see the sales amount for each country in the continent. Next, you might want to drill down further to see the sales amount for each state in a country. Next you might want to drill down from yearly sales to say quaterly...and so on a so forth. This is where we introduce Groups and drill downs If you have used the Group By clause, for aggregation, you might know, what I am talking about. In any case, lets take an example from the adventure works database. Lets consider 4 tables from AdventureWorks 2008 R2 1. Fact Internet Sales 2. DimDate 3. DimSalesTerritory 4. DimProduct 5. DimCustomer. If you run the below query in SQL Server, you will get the following: Query:

SELECT D.CalendarYear AS [Year] ,D.CalendarQuarter AS [Quarter] ,D.EnglishMonthName AS [Month] ,D.FullDateAlternateKey AS [Date] ,B.EnglishProductName AS [ProductName] ,C.FirstName + ' ' + LastName AS [CustomerName] ,ST.SalesTerritoryRegion AS [SalesRegion] ,ST.SalesTerritoryCountry AS [SalesCountry]

,A.SalesOrderNumber AS [OrderNumber] ,A.SalesAmount FROM FactInternetSales A JOIN DimProduct B ON B.ProductKey = A.ProductKey JOIN DimCustomer C ON C.CustomerKey = A.CustomerKey JOIN DimDate D ON D.DateKey = A.OrderDateKey JOIN DimSalesTerritory ST ON ST.SalesTerritoryKey = A.SalesTerritoryKey

Now we have some data with us to work with. Lets use this data in our report and group the data. Then we will introduce drill through in our reports. Step 1: Make a report, with a table control by dragging and dropping CustomerName, OrderNumber and SalesAmount. Hit preview - Your report should look something like this.

Step 2: Now lets Add a product name, and lets put the customer Name, order number and Sales Amount under it. Right click on the grouping area --> Add group --> Parent Group --> Group by 'Product Name' (Also Add a group header)

Hit preview. Your report should look something like this.

So lets add more groupings. Year--Quarter--Month--Date--SalesRegion--SalesCountry--ProductName-Details So your design view should look something like this:

And your output should look something like this:

Lesson 12: Using SSRS web services SSRS exposes all functionality of reporting services through Web service. Its bascially a XML web service and has a SOAP API. It provides 2 endpoints: 1. Report execution 2. Report Management Mainly there are 2 ways to use the SSRS web services: 1. Using Microsoft.NET Framework 2. Using RS.exe Lets look at an example to use SSRS web services using Microsoft C#. Step 1: Create a Visual studio 2010 console application (you can use any Visual Studio version) I am calling the application MyFirstSSRSWebService. Step 2: Next click add service reference:

Step 3: Click advanced--> add web reference -- url - http://localhost/reportserver/reportservice2005.asmx (replace localhost with your report server name). Then click add reference

Step 4: You should be seeing the SSRS webservice that you just added, in the solution explorer:

Step 5 : I have created a report called MyFirstReport in my local, and given it a small description.

Step 6: Now lets try to programmatically display this report name and the description Copy paste the following c# code:

using System; using MyFirstSSRSWebService.myPC; namespace MyFirstSSRSWebService { class Program { static void Main(string[] args) { ReportingService2005 rs = new ReportingService2005(); rs.Credentials = System.Net.CredentialCache.DefaultCredentials; rs.Url = "http://localhost/reportserver_SSRSexpress/reportservice2005.asmx"; Property name = new Property(); name.Name = "Name";

Property description = new Property(); description.Name = "Description"; Property[] properties = new Property[2]; properties[0] = name; properties[1] = description; try { Property[] returnProperties = rs.GetProperties( "/HelloWorld/MyFirstReport", properties); foreach (Property p in returnProperties) { Console.WriteLine(p.Name + ": " + p.Value); } Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } } } }

Step 7: Run the code, you should be seeing the following output

Likewise, I would encourage you to explore other methods of this web service as well. One common activity people do, is to programmatically render a report in excel/pdf etc

Lesson 13: SSRS Subsriptions - Email Based Subscriptions are delivery mechanisms for delivering a report to an user. Subscriptions allow us to schedule a report, to be run and delivered in many formats (Excel/PDF etc) as an email or to be dropped in a file share at any pre-defined time. There are mainly 2 types of subscriptions: 1.Standard 2.Data-Driven Subscription. It also has 2 delivery mechanisms: 1.Email based 2.File Share based. Lets discuss the email based subscription. This demo is based on SSRS 2008 R2 Step 1:After I navigate to my ReportServer page, I should be seeing something like this:

Step 2: Select the report, and click subscribe.

Step 3: if the credentials are not stored, you will get the following error message.

Navigate again to the report and click manage:

Goto the data sources tab, and enter the credentials:

Click on apply and then click on subscriptions tab. You should be seeing a screen something like this:

Click on New subscription. you should be presented with a screen like this:

Select delivered by: Email Type in To, CC, BCC

Select a report rendering format. Select a schedule. Click OK The report should be available in your inbox, at your specified time.

Lesson 15: SSRS Matrix Reports Tablix is a new feature introduced in SSRS 2008. Tablix combines the features of a tabular report and cross tab features. A tablix report, display the report data in rows and columns, and allows us to organize the data in aggregated groups. It also allows us to add drill down features to get into details of a report. Tablix = Table + Matrix. So essentially it allows to add pivot like features to our SSRS reports. Lets take an example. Step 1. Create a blank report Step 2. Add a connection to the Adventure works database Step 3. Create a dataset with the following query: SELECT Sales.SalesTerritory.Name as Region, Sales.SalesTerritory.CountryRegionCode, Sales.SalesTerritory.[Group] as Territory, Year(Sales.SalesOrderHeader.DueDate) as Year, Month(Sales.SalesOrderHeader.DueDate) as Month, Sales.SalesOrderHeader.TotalDue FROM Sales.SalesTerritory INNER JOIN Sales.SalesOrderHeader ON Sales.SalesTerritory.TerritoryID = Sales.SalesOrderHeader.TerritoryID

Step 4: Drag and drop the Matrix control from the ToolBox.

Step 5: Drag and drop the territory to the rows and Year to the column:

Step 6: ON clicking Preview, you should be able to get something like this:

Step 7: However the report, does not have any aggregated data. So lets drag and drop the TotalDue field to the 'Data' area in the report.

Step 8: On clicking preview, you should be able to see the aggregated report as below:

Go ahead and add some currency formatting to the data. Lets look at groupings and drilldowns in the next tutorial.

Lesson 16: Drilldown Matrix Reports In the last tutorial, we saw how to create a matrix report. Matrix reports are very useful, and it allows total flexibility too. For instance we could easily convert a matrix report to tabular. In this tutorial, lets see how to add the drill down feature to an existing matrix report. Lets take the same matrix report, which we created in the last tutorial. This is how it looked:

Lets add some child groupings to this report, and explore some visibility toggling features. Step 1: Right click on the Territory field and add a child group:

Step 2: Choose 'CountryRegionCode' to group by:

Step 3: Your design view would look something like this:

Step 4: Hit preview.

Congratulations - your matrix report is ready. Lets proceed to see some visibility toggling features Step 5: Click on the row groups - 'CountryRegionRegion' and select the group properties:

Step 6: In the visibility pane, check 'Hide' for 'When the report is initially run' Also, check the 'display can be toggled by this report item' for Territory

Step 7: Select OK and hit preview. You should be able to toggle the report.

Lesson 17: SSRS Subreports SSRS Subreports are extremely helpful, when we need to embed multiple reports in a single report. The main report serves as a container for multiple sub-reports. SSRS gives us complete control over what parameters to be passed to the sub report. Many times this is useful in matrix reports too. Lets look at an example of a sub-report. We are going to create a main report with 1 parameter. As soon as someone selects a parameter, relevant data is displayed + the sub report is also filtered and displayed in the main report itself. Step 1: Create a main report (Steps to create a basic report can be found in the previous tutorials) I have the following dataset: SELECT [TerritoryID] ,[Name] ,[CountryRegionCode] ,[Group] ,[SalesYTD] ,[SalesLastYear] ,[CostYTD] ,[CostLastYear] ,[rowguid] ,[ModifiedDate] FROM [AdventureWorks].[Sales].[SalesTerritory] Where CountryRegionCode = @CRC

Step 2: Create a parameter called CRC. Step 3: Your Main report would look something like this.

Step 4: Now lets add a sub-report and pass in the same parameter to it. Drag and drop a sub-report control from the toolbox.

Step 5: Now click on the sub-report properties.

Step 6: Lets us the previous tablix report that we created as our sub-report.

Step 7: Choose the parameters tab, and configure the parameters

Step 8: click OK and hit preview. You should be able to see the main and the sub-report.

Lesson 18: Managing SSRS Security As soon as you install SSRS 2008 R2, in your server and hit http:///reports, by default the the system administrators get access to the report manager. But if you wish to let other people see the reports that you deploy, you need to explicitly provide access to these reports. Providing access to reports is very simple and can be done at an item level( report level) or a folder level. Lets look at a very simple example. I have installed a SSRS 2008 R2 report server, on my local machine and have created a folder called Sandbox, in which i have added a report called Hello World.

By Default all admins in the system can access this report. Lets say, we add more reports to this folder and we need to grant access to these reports. This can be done, by clicking on Folder Settings and then clicking on security

Click on New role assignment. This is the place where you define your role assignments.

If you need to grant all users of your domain access, then you may need to add 'Domain\DomainUSERS' and assign appropriate roles. There are mainly 5 types of roles, that you can assign to an user or a group. These roles are: a. Browser b. Content Manager c. My Reports d. Publisher e. Report Builder. Descriptions for each of these roles are provided in the UI itself. If you wish to add just a particular user of your domain for your report, type the username and select the appropriate role for the same. Click OK, and your security is set.

Lesson 19: SQL/SSRS Interview questions I thought of blogging some SQL/SSRS interview questions. Below are some. I will add more, when I complete the compilation

1. What is OLTP(Online Transaction Processing)?

OLTP stands for Online Transaction Processing. It is mainly used, when you have frequent inserts/deletes/updates. OLTP will have normalized tables.

OLAP stands for Online Analytical processing. OLAP is used, when we need historical data to be preserved and do not have frequent updates/deletes/inserts. Tables are denormalized, and are used for multi-dimensional analysis/modelling. OLAP forms the basis for data mining and knowledge discovery

2. What is normalization and what are the different forms of normalization?

Normalization is a way to arrange data in your database. Primary goal being to reduce redundancy of data. There are 6 normal forms (http://en.wikipedia.org/wiki/Database_normalization) Generally most of the databases are normalised upto 3 NF (NF – normal form) First Normal Form (1NF): No repeating columns or groups of columns Second Normal Form (2NF): No partial dependencies on a concatenated key.

Third Normal Form (3NF): No dependencies on non-key attributes Fourth normal Form (4NF) : Isolate independant multiple relationships Fifth normal Form (5NF): Isolate semantically related multiple relationships

3.What are views?

A view is a kind of virtual table or a stored query. The result set of the SELECT statement forms the virtual table returned by the view.

Example:

CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition Example: http://www.youtube.com/watch?v=to_0_bODY2Y

4. What are indexed views?

A view with a unique clustered index is an indexed view.

Example:

CREATE TABLE sample_table( A B int

INT PRIMARY KEY,

) GO

CREATE VIEW sample_view WITH SCHEMABINDING AS SELECT A, B FROM dbo.sample_table GO

CREATE UNIQUE CLUSTERED INDEX idx_MyView ON sample_view(B)

5. What are stored procedures?

Stored procedures are group of SQL statements that are created previously and stored. Stored procedures can accept parameters, and also have output parameters. Permisions can be modifed for stored procedures.

Example:

CREATE PROCEDURE sp_Sample @param varchar(10) AS SELECT A, B FROM sometable

WHERE B = @param

EXECUTE sp_Sample ‘ABC’

Example: http://www.youtube.com/watch?v=jx63oKvU8Iw

6. Give an example for Stored Procedures with parameters and output parameters. CREATE PROCEDURE GetImmediateManager @employeeID INT, @managerID INT OUTPUT AS BEGIN SELECT @managerID = ManagerID FROM HumanResources.Employee WHERE EmployeeID = @employeeID END

7.What is xml data type? The xml data type lets you store XML documents and fragments in a SQL Server database.

Example: http://www.youtube.com/watch?v=OO-AnA_52Og

8. Explain filestream with an Example. FILESTREAM integrates the SQL Server Database Engine with an NTFS file system by storing varbinary(max) binary large object (BLOB)

data as files on the file system. Transact-SQL statements can insert, update, query, search, and back up FILESTREAM data.

Example: http://www.youtube.com/watch?v=ONYjKN21aIw

9.Explain stored procedure, function and the difference between them? Stored procedures are group of SQL statements that are created previously and stored. User defined function is a database object which has one or more sql statements , which can accept zero or more parameters and return either a value or table.

Difference: 1. Stored Procedure can have output parameters – UDF ‘s cannot. 2. Stored Procedures return integers – UDF’s can return scalar or tables. 3. Stored procedures can have Insert/Delete/update Statement – UDF’s cannot 4. Stored Procedures are compiled at compile time – UDF’s are compiled at runtime. 5. Stored procedure cannot be used in the select/where/having clause – UDF’s can be

Example: Stored procedures: https://www.youtube.com/watch?v=jx63oKvU8Iw User Defined Functions: https://www.youtube.com/watch?v=vBg216_AODA

10. When do we use a having clause and when do we use a where clause? Having Clause applies to groups – hence used with groupby clause. Where is applied row by row

Example: SELECT A, AVG(B) FROM some_table GROUP BY A HAVING AVG(B) >10

11.Explain user defined functions and the difference forms of UDF https://www.youtube.com/watch?v=vBg216_AODA

12. What are recursive stored procedures? Stored Procedures calling itself in a repetative fashion are called Recursive stored procedures.

13.What are the different error handling techniques? https://www.youtube.com/watch?v=PUYlJHMhoAs

14. Write a query to find the second/third/nth largest Salary in a table: Emp(EmpID, EmpName, Salary) SELECT TOP 1 salary FROM (SELECT DISTINCT TOP 2 salary FROM employee ORDER BY salary DESC) a ORDER BY salary

15. What is a trigger? What are the different types of them? Answer: A trigger is an event (set of DDL statements) that is automatically fired when some sort of an insert/delete/update occurs on a database. Triggers can be nested.

Types of triggers: DDL trigger DML trigger (instead of/after trigger)

Example: CREATE TRIGGER T1 ON TABLE_NAME AFTER INSERT AS BEGIN ROLLBACK TRANSACTION END GO 16.Explain linked server with an example. A Linked Server is a connection to an external data source. The remote data source can be DB2, Oracle, Access or any other data source that uses an OLE DB provider.

Example:

sp_addlinkedserver [ @server = ] ‘server‘ [ , [ @srvproduct = ] ‘product_name‘ ] [ , [ @provider = ] ‘provider_name‘ ] [ , [ @datasrc = ] ‘data_source‘ ] [ , [ @location = ] ‘location‘ ] [ , [ @provstr = ] ‘provider_string‘ ] [ , [ @catalog = ] ‘catalog‘ ]

17.Explain collation and collation sensitivity Collation: Collation controls the way string values are sorted. The default collation sorts alphabetically using the standard Latin character set. Other collations will sort in different orders Collation sensitivity:

Width sensitivity:When a single-byte character (half-width) and the same character when represented as a double-byte character (full-width) are treated differently then it is width sensitive

Accent sensitivity: If a and á, o and ó are treated in the same way, then it is accent-insensitive.

Case sensitivity: If A and a, B and b, etc. are treated in the same way then it is case-insensitive. SQL distinguishes using ASCII values of A(65) and a(97)

Kana Sensitivity: When Japanese kana characters Hiragana and Katakana are treated differently, it is called Kana sensitive 18.What is primary key/Unique Key and difference between them?

Primary key: The key of a relational table that uniquely identifies each record in the table. Primary Key doesn’t allow NULLS Clustered Indexes are created on Primary Keys.

Unique Key: Unique Key enforces uniqueness of the column on which they are defined. Unique Key allows one NULL value Non-Clustered indexes are created on Unique Keys. 19.Explain 1:1, 1:m, m:m relationships1:1 -In a one-to-one relationship, a row in table A can have no more than one matching row in table B, and vice versa. A one-to-one relationship is created if both of the related columns are primary keys or have unique constraints.

1:many – In 1:many type of relationship, a row in table A can have many matching rows in table B, but a row in table B can have only one matching row in table A.

many:many: In a many-to-many relationship, a row in table A can have many matching rows in table B, and vice versa. 20.Explain delete and truncate statement and the differenceDelete: The DELETE Statement is used to delete rows from a table. DELETE is a logged operation on a per row basis Example: DELETE FROM table_name [WHERE condition];

Truncate: The TRUNCATE command is used to delete all the rows from the table and free the space containing the table

21.Explain the merge statement with an example. Merge Statements perform insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table. 22.What is an index? What are the different types of indexes? what is the difference between them?

An index can be created in a table to find data more quickly and efficiently. it is a structure within SQL that is used to quickly locate specific rows within a table.

CLUSTERED INDEX: Clustered indexes define the logical order of the table. The leaf level of the clustered index has the actual data pages of the table. Because of this there can only be one clustered index per table. A table that does not have a clustered index is referred to as a heap

NON-CLUSTERED INDEX: Here, the leaf level of a nonclustered index has a pointer as part of each index row. That pointer is either the clustered index key in the cases where the base table has a clustered

index or the Row Identifier in the cases where the table is a heap 23.Difference between char and nvarchar / char and varchar data-type?

char [ ( n ) ] : Fixed-length, non-Unicode string data. n defines the string length and must be a value from 1 through 8,000. The storage size is n bytes. varchar [ ( n | max ) ] : Variable-length, non-Unicode string data. n defines the string length and can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). nvarchar [ ( n | max ) ] : Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). 24.What are joins? What are the different types of joins? Joins are used to query data from more than 2 tables, based on a relationship between columns in these tables.

JOIN: Return rows when there is at least one match in both tables. LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table FULL JOIN: Return rows when there is a match in one of the tables

Lesson 20: SSRS Charts and Graphs SSRS 2008R2 provides a rich set of visualization tools. Some of them are charts / graphs. These are available in 3D formats to add a rich effects to your reports. SSRS charts and graphs helps to summarize the data in visual format. It enables to represent very large datasets as aggregated information available at a glance. SSRS 2008 R2 also added sparklines to the visualization tools. In addition, SSRS 2008 R2 also supports guages/Databasrs/Sparkline/Indicators. One of the most exciting features of SSRS being, usage of Maps. It allows an awesome representation of Geagraphic data using maps.

Lets look at some basic graphs and shapes. Step 1: As usual, lets create a blank report, connecting to adventure works database with dataset:

SELECT Sales.SalesTerritory.Name as Region, Sales.SalesTerritory.CountryRegionCode, Sales.SalesTerritory.[Group] as Territory, Year(Sales.SalesOrderHeader.DueDate) as Year, Month(Sales.SalesOrderHeader.DueDate) as Month, Sales.SalesOrderHeader.TotalDue FROM Sales.SalesTerritory INNER JOIN Sales.SalesOrderHeader ON Sales.SalesTerritory.TerritoryID = Sales.SalesOrderHeader.TerritoryID

Step 2: Now lets drag and drop a chart control from the toolbox. As soon as you do that , you get a pop-up, displaying various image shapes for the chart control.

Step 3: These are the set of shapes provided by SSRS for visualization purposes. Let's choose the first shape. You should be getting something like this on your scree:

Step 4: This is a blank chart,with no data in it. You can click on the headings/text in the axis and change accordingly. Alternatively , you can also write SSRS expressions to change text/descriptions dynamically. Please refer my previous tutorial, on SSRS expressions.

Step 5: In the above example, i have changed the chart title to 'My First Chart' Now drag and drop TotalDue to the summation of values, CountryRegionCode to the CategoryGroups and year to the series Groups. Something like this...

Step 6: Hit Preview, and you be getting something like this:

Step 7: Try these steps, with a number of other shapes and graphs/Sparklines/Indicators.

Lesson 21: SSRS 2008 R2 Document Maps A document map in an SSRS report, provides pointers/links to certain report items in your report. If you have a document map in your report, it will appear in the left most pane. Clicking on any of the links, in the document pane, jumps the users directly to the report item. It is similar to the table of contents. Please note that clicking on the document map links, refreshes the report. Lets look at an example for a document map. Step 1: Create a blank report by connecting to Adventure works database. I have used the following query to create my dataset:

SELECT Sales.SalesTerritory.Name as Region, Sales.SalesTerritory.CountryRegionCode, Sales.SalesTerritory.[Group] as Territory, Year(Sales.SalesOrderHeader.DueDate) as Year, Month(Sales.SalesOrderHeader.DueDate) as Month, Sales.SalesOrderHeader.TotalDue FROM Sales.SalesTerritory INNER JOIN Sales.SalesOrderHeader ON Sales.SalesTerritory.TerritoryID = Sales.SalesOrderHeader.TerritoryID Order by Sales.SalesTerritory.CountryRegionCode

Your design view after creating the report should look something like this.

Please observe the Row groups. Adding Territory as a group is necessary here, else SSRS will repeat the Territory values in the document map. You can hide one of the territory column (the non-group one) in the report. Next, goto the Territory column, and select the properties. Go ahead and choose Territory in the DocumentMaps Property:

Now hit preview, and you should be ale to see the follow SSRS 2008 R2 report with a document map:

Select any one Territory in the document map, and the report will jump to the appropriate page.

Lesson 22: SSRS report execution and performance enhancements

SSRS 2008 R2 allows us to execute reports in 3 modes: 1. On Demand. 2. From Cache 3. From Snapshots On demand:

This is normal approach that we follow, by hitting a report server URL. Each time a report is run, data is returned from the database server and rendered to the report. This approach ensures that our report is update and fresh. The downside of this approach is that, if n users open up this report on their browsers, queries on the report are executed n times. Thus this approach at times might slow down the server. Cache

One of the performance enhancements techniques is to cache a report when it is initially run. This means that if another user requests for the report, the same report is served to the user from the cache This avoids people querying the database server from each report rendering. To make sure that people do not receive too much stale data, we can set a time to invalidate a cache. This is a good performance enhancement technique for slow running reports. Snapshots:

Report snapshots are created at a particular schedule for certain parameters. Please note that parameters cannot be changes on snapshot reports. SSRS 2008 R2 allows to schedule the snapshot creation times.

Users can directly render a report from a snapshot. However please note that not all reports can have snapshots, especially the ones that prompt users for credentials.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF