SSRS or SQL Server Reporting Services is one of the tools available in Microsoft SQL Server Data Tools. It is a server-based reporting platform that you can use to create and manage tabular, matrix, graphical, and free-form reports that contain data from relational and multidimensional data sources. SSRS is a set of readymade tools, that helps you to create, deploy and manage reports. SSRS allows are reports to be exported in various formats (Excel, PDF, word ,CSV ,XML etc) SSRS allows reports to be delivered via emails or dropped to a share location. Advantages of using SSRS Supports a variety of file formats Facility to drill down to different levels of data Helpful and perceptive reporting Access to enterprise-level features Simplistic implementation owing to a centralized server Why SSRS? Here, are prime reasons for using SSRS tool: SSRS is an enhanced tool compared to Crystal Reports Faster processing of reports on both relational and multidimensional data Allows better and more accurate Decision-making mechanism for the users Allows users to interact with information without involving IT professionals It provides a World Wide Web-based connection for deploying reports. Hence, reports can be accessed over the internet SSRS allows reports to be exported in different formats. You can deliver SSRS reports using emails SSRS provides a host of security features, which helps you to control, who can access which report Working and Architecture The main components of SSRS are the following: Report Builder -This component is basically used as a drag and drop utility which can be used to pick any functionality or tables and drag it as per usage. It runs on the client computer. Report Designer - This component is used to develop reports. Complex reports can be developed with ease using this component. It is a publishing tool which is hosted in SSDT (SQL Server Data Tools) or visual studio. Report Manager -To access any web-based reports, we can make use of Report Manager. Report Server - This component is used to store SQL server Engine metadata. Server Database Report - This component is used to store security settings, report definitions, metadata, delivery data, etc. Data Sources - The reporting service components retrieve data from data sources like multidimensional, relational or traditional data sources. Reporting Life Cycle Report Authoring: In this phase, the report author defines the layout and syntax of the data. The tools used in this process are the SQL Server Development Studio and SSRS tool. Management: This phase involves managing a published report which is mostly part of the websites. In this stage, you need to consider access control over report execution. Delivery: In this phase, you need to understand when the reports need to be delivered to the customer base. Delivery can be on-demand or pre-defined schedule. You can also add an automation feature of subscription which creates reports and sends to the customer automatically. What is RDL? Report Definition Language (RDL) is an XML representation of a SQL Server Reporting Services report definition. A report definition contains data retrieval and layout information for a report. Create RDL Report You can create a RDL reports using any of the following reporting tools, Syncfusion Web Report Designer: Provides intuitive user interface to create or edit report online. Microsoft Report Builder: You can create a RDL report using the Microsoft stand-alone Report Builder. Visual Studio Report Server project template: To create a RDL report in Visual Studio, a Report Server project is required where you can save your report definition (.rdl) file. How To create a report server project From the File menu, select New > Project. In the left-most column under Installed, select Reporting Services Select the Report Server Project icon Creating a report definition file (RDL) In the Solution Explorer pane, right-click on the Reports folder. If you don't see the Solution Explorer pane, select View menu > Solution Explorer. Select Add > New Item. In the Add New Item window, select the Report icon. Type "PatientDetail.rdl" into the Name text box. Select the Add button on the lower right side of the Add New Item dialog box to complete the process. Report Designer opens and displays the Patient Detail report file in Design view. Setup Connection In the Report Data pane, select New > Data Source. If the Report Data pane isn't visible, then select View menu > Report Data OR (ctrl + Alt + D). The Data Source Properties dialog box opens with the General section displayed. In the Name text box, type “PatientDetail". Select the Embedded connection radio button. In the Type dropdown selection box, select "Microsoft SQL Server". In the Connection string text box, type the following string: Data source=Magnusminds; initial catalog=Patient Select the Credentials tab, and under the section Change the credentials used to connect to the data source, select the Use Windows Authentication (integrated security) radio button. Select OK to complete the process. Define a Dataset for the Table Report In the Report Data pane, select New > Dataset.... The Dataset Properties dialog box opens with the Query section displayed. In the Name text box, type "GetPatientDetails". Below that, select the Use a dataset embedded in my report radio button. From the Data source dropdown box, select PatientDetail. For the Query type, select the Text radio button and Type Query into the Query text box. Select OK to exit the Dataset Properties dialog box. The Report Data pane displays the AdventureWorksDataset dataset and fields. Add a Table to the Report Select the Toolbox tab in the left pane of the Report Designer. With your mouse, select the Table object and drag it to the report design surface. Report Designer draws a table data region with three columns in the center of the design surface. If you don't see the Toolbox tab, select View menu >Toolbox. In the Report Data pane, expand the AdventureWorksDataset to display the fields. Drag the field from the Report Data pane to the first column in the table. Preview Your Report Select the Preview tab. Report Designer runs the report and displays it in the Preview view. The following diagram shows part of the report in Preview view. Deployment of An RDL Report File in SQL Report Server By Uploading RDL file in Report Server. Open SSRS Server from webportal URL. There, you will see the upload button. Click the upload option and browse the rdl file of the report from the location. It uploads your report to the report server. Click on the uploaded file it runs the report in the browser, hence, you can view it in the browser.
In this article, we will review on DELETE AND UPDATE CASCADE rules in SQL Server foreign key with different examples. DELETE CASCADE: When we create a foreign key using this option, it deletes the referencing rows in the child table when the referenced row is deleted in the parent table which has a primary key. UPDATE CASCADE: When we create a foreign key using UPDATE CASCADE the referencing rows are updated in the child table when the referenced row is updated in the parent table which has a primary key. We will be discussing the following topics in this article: Creating DELETE CASCADE and UPDATE CASCADE rule in a foreign key using T-SQL script Triggers on a table with DELETE or UPDATE cascading foreign key Let us see how to create a foreign key with DELETE and UPDATE CASCADE rules along with few examples. Creating a foreign key with DELETE and UPDATE CASCADE rules Please refer to the below T-SQL script which creates a parent, child table and a foreign key on the child table with DELETE CASCADE rule. Insert some sample data using below T-SQL script. Now, Check Records. Now I deleted a row in the parent table with CountryID =1 which also deletes the rows in the child table which has CountryID =1. Please refer to the below T-SQL script to create a foreign key with UPDATE CASCADE rule. Now update CountryID in the Countries for a row which also updates the referencing rows in the child table States. Following is the T-SQL script which creates a foreign key with cascade as UPDATE and DELETE rules. To know the update and delete actions in the foreign key, query sys.foreign_keys view. Replace the constraint name in the script. The below image shows that a DELETE CASCADE action and UPDATE CASCADE action is defined on the foreign key. Let’s move forward and check the behavior of delete and update rules the foreign keys on a child table which acts as parent table to another child table. The below example demonstrates this scenario. In this case, “Countries” is the parent table of the “States” table and the “States” table is the parent table of Cities table. We will create a foreign key now with cascade as delete rule on States table which references to CountryID in parent table Countries. Now on the Cities table, create a foreign key without a DELETE CASCADE rule. If we try to delete a record with CountryID = 3, it will throw an error as delete on parent table “Countries” tries to delete the referencing rows in the child table States. But on Cities table, we have a foreign key constraint with no action for delete and the referenced value still exists in the table. The delete fails at the second foreign key. When we create the second foreign key with cascade as delete rule then the above delete command runs successfully by deleting records in the child table “States” which in turn deletes records in the second child table “Cities”. Triggers on a table with delete cascade or update cascade foreign key An instead of an update trigger cannot be created on the table if a foreign key on with UPDATE CASCADE already exists on the table. It throws an error “Cannot create INSTEAD OF DELETE or INSTEAD OF UPDATE TRIGGER ‘trigger name’ on table ‘table name’. This is because the table has a FOREIGN KEY with cascading DELETE or UPDATE.” Similarly, we cannot create INSTEAD OF DELETE trigger on the table when a foreign key CASCADE DELETE rule already exists on the table. Conclusion In this article, we explored a few examples on DELETE CASCADE and UPDATE CASCADE rules in SQL Server foreign key. In case you have any questions, please feel free to ask in the comment section below.
What is table partitioning in SQL? Table partitioning is a way to divide a large table into smaller, more manageable parts without having to create separate tables for each part. Data in a partitioned table is physically stored in groups of rows called partitions and each partition can be accessed and maintained separately. Partitioning is not visible to end-users, a partitioned table behaves like one logical table when queried. Data in a partitioned table is partitioned based on a single column, the partition column often called the partition key. Only one column can be used as the partition column, but it is possible to use a computed column. The partition scheme maps the logical partitions to physical filegroups. It is possible to map each partition to its own filegroup or all partitions to one filegroup.
Have you ever attempted to set up an automated backup of your SQL Server Express Edition and found that there’s no SQL Server Agent where you can schedule the job which will took a backup of your database. Alas, the world does not end there and you don't need to pay extra bucks just to have the back up via an SQL Agent which is available only to Standard and Enterprise editions. There are many options to automate the backup job which runs on a specific time and does not require manual intervention. Here, we will learn how to do it via SQL Command using batch file and Windows in-build Task Scheduler. Hope, you may find this useful. Create a BAT(batch) file to execute the command to take a backup of Database and save it. echo off :: -------------------------------------------------- :: clear console cls :: -------------------------------------------------- :: Define variables set SERVERNAME=YOUR_SERVER_NAME set DATABASENAME=DATABASE_NAME set MyTime=%TIME: =0% set MyDate=%DATE:~-4%.%DATE:~7,2%.%DATE:~4,2%.%MyTime:~0,2%.%MyTime:~3,2%.%MyTime:~6,2% set FileName=%DATABASENAME%_%MyDate%.bak set BAK_PATH=DIRECTORY_PATH set DEST_FILE=%BAK_PATH%%FileName% :: -------------------------------------------------- :: BACKUP Database sqlcmd -E -S %SERVERNAME% -d master -Q "BACKUP DATABASE [%DATABASENAME%] TO DISK = N'%DEST_FILE%' WITH INIT , NOUNLOAD , NAME = N'%DATABASENAME% backup', NOSKIP , STATS = 10, NOFORMAT" :: -------------------------------------------------- :: Optional Part :: -------------------------------------------------- :: Zip file 7z a -tzip "%DEST_FILE%.zip" "%DEST_FILE%" :: -------------------------------------------------- :: Delete unziped file DEL "%DEST_FILE%" “SERVERNAME” is the name of SQL Server physical machine. “DATABASENAME” is the database which will be backup. “FileName” sets as a database name and append date which has .bak extension “BAK_PATH” is the path in which a database backup file will be saved. “DEST_FILE” is use backup path and file name. After defining all the variables database backup will be generated and save as zip file in “DEST_FILE” path and at the end, the unzipped file will be deleted from “DEST_FILE” Now, it's time to schedule this created batch file in #1 Start Menu -> Task Scheduler -> Run as administrator Click on Create Task... from the right bar and configure it with Triggers and Actions