In SQL Server 2000 Data transformation Services (DTS) it was a bit of a hack to be able to loop over files of a given type in a certain directory and import them into your destination. It involved a lot of "Glue Code" and a certain amount of fooling the package into going back to a previous task because it still had work to do. Well thankfully in SQL Server 2005 Integration Services (SSIS) that has all changed and this article is going to show you how.
The image below shows us how incredibly simple and clean the package will look when finished. There are some things worth pointing out at this stage. In the centre of the screen we see the Foreach Enumerator container and inside that we see the Data Flow task which houses the pipeline. At the bottom in the Connection Managers tray we see our Flat File Connection Manager (My Source File) and our OLEDB Connection Manager (My Destination). The Flat File Connection Manager is the one in which we are most interested for this article. Both of these managers are used in the Data Flow behind the DataFlow task. We will not be detailing the pipeline behind the DataFlow task in this article but it consists of a Flat File Source moving data to an OLEDB destination.
Let's begin then by opening up the Foreach enumerator and moving straight to the Collection node in the tree on our left. Below we see our information already populated.
What we see on the screen is pretty self explanatory but let's go through it anyway. We have chosen to enumerate over a file collection and ths is indicated by the value next to the Enumerator property at the top. We need to specify a folder over which to loop and for which type of files to look and we do that in the centre of the form. We are given three options as to what is returned when the loop finds a file in the folder at the bottom of the form. We can return the whole filename including extension and path, the name and extension or simply the name of the file found. Because our connection manager is going to need to know exactly where to find the file and it's name we have hosen the first option. The final thing we see on this screen is the ability to traverse subfolders. In our example we do not need to do this.
When the Foreach enumerator finds a file it needs to tell us about what it found and it does this by populating a variable. Click on to the Variable Mappings node now. Our package currently has no variables able to accept the name of the file so we are going to create a new one.
The next screen we see allows us to set the values of the variable. As we can see variables can be scoped in SSIS to certain executables in the package or to the package itself.
Here is how our variable looks with all its properties set.
Because the enumerator will only return us at most one value on every iteration we map our variable to an index of 0.
We have now configured everything as far as the Foreach enumerator is concerned. We now need to set the rpoerties of the Flat File Connection Manager. Highlight the manager in the tray at the bottom, right click and choose properties.
The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column drop the list down and choose ConnectionString
Now hit the ellises button to the right and we are taken through to the expression editor where we will build the actual expression itself
Our requirements are pretty simple here and all we want to do is to retrieve the variable we defined earlier. To do this simply drag the variable from the list at the top to the expression text box at the bottom. Property Expressions can become very complex and we shall no dount be seeing more of them in future articles. After you have chosen the variable click OK
We now see that our expression is mapped to our ConnectionString property. Click OK
Finally we can now see our File Manager's Connection string property being mapped to an expression in the properties of the manager.
When the enumerator finds a file matching our requirements it will set the correct property on the connection manager and this will be used by the pipeline at runtime.
Learning about Sql server2005/2008,SSIS,SSRS and SSAS
Monday, 25 October 2010
SQL Server Integration Services(SSIS)
SSIS Tasks Explained
Data Flow Task
•Data Flow Task: This task extracts data from a source, allows for transformations of that data, and then the data is loaded into a target data destination.
Data Preparation Tasks
•File System Task: This task allows the user to copy/move/delete files and directories on a file system.
•FTP Task: This task allows the user to copy/move/delete files and directories over FTP.
•Web Service Task: This task allows the user to execute a Web service method and store the results
•XML Task: This task is used to work with XML data. XSLT can be used along with XPath to validate, compare and merge documents. The results of this can then be stored.
•Data Profiling Task: This task can be used for checking and validating data quality. Profiles can be set up and checked for varius data quality issues such as, column length issues, column patterns, column statics, etc.
Workflow Tasks
•Execute Package Task: This task will run other SQL Server Integration Services packages.
•Execute Process Task: This task will execute an application or batch file.
•Message Queue Task: This task allows you to send and receive messages between SSIS packages, or to send messages to an application via an application queue. This task uses Message Queuing (MSMQ)
•Send Mail Task: This task allows for email messages to be created and sent using an SMTP server.
•WMI Data Reader Task: This task allows a Package to query, using WQL, computer systems (local and remote) for information regarding that computer.
•WMI Event Watcher Task: This task watches for WMI events that have occurred on a computer system, and allows the package to take an action if certain criteria are met.
Scripting Tasks
•Script Task: This task can be used to program functions that are not available in the standard SSIS tasks or transformations. In SSIS 2005 this task can be programmed in VB .NET. In SSIS 2008 VB .NET and C# can be used to program a Script Task.
SQL Server Maintenance Tasks
•Back Up Database Task: This task will allow you to backup a one or many SQL Server databases.
•Check Database Integrity Task: This task will allow you to check the integrity of all the objects in one or many SQL Server databases.
•Execute SQL Server Agent Job Task: This task allows for the execution of a SQL Server Agent job.
•Execute T-SQL Statement Task: This task is similar to the Execute SQL Task, however it only supports Transact SQL Statements. It should be used for SQL Server specific SQL statements.
•History Cleanup Task: This task allows for the cleanup of historical activity data. It will cleanup the history for database maintenance plans, backup activites, restore activities and SQL Server agent jobs.
•Maintenance Cleanup Task: This task allows for the cleanup of backup files, and the reports of maintenance plans.
•Notify Operator Task: This task allows SSIS to notify SQL Server Agent operators. They can be notifies by email, pager, or netsend.
•Rebuild Index Task: This task will rebuild an index or indexes on one or many databases.
•Reorganize Index Task: This task will reorganize an index or indexes on one or many databases.
•Shrink Database Task: This task will shrink the size of the SQL Server database data and database log files.
•Update Statistics Task: This task will update the statistics for one of many tables in one or many databases.
SQL Server Tasks
•Bulk Insert Task: This task offers an efficient way to copy large volumes of data.
•Execute SQL Task: This task allows the execution of a SQL statement. If the statement returns results, they can be stored in a variable.
•Transfer Database Task: This task will copy or move a SQL Server database between two instances of SQL Server. It can even be used to make a copy of a database on the same server. Databases can be copied either online or offline.
•Transfer Error Messages Task: This task will transfer a single or multiple SQL Server user defined error messages between SQL Server instances. It can be setup to transfer specific user messages or all error messages.
•Transfer Jobs Task: This task will transfer a single or multiple SQL Server Agent jobs between SQL Server instances.
•Transfer Logins Task: This task will transfer a single or multiple SQL Server logins between SQL Server instances.
•Transfer Master Stored Procedures Task: This task will transfer a single or multiple SQL Server Master database stored procedures between SQL Server instances.
•Transfer SQL Server Objects Task: This task will transfer a single or multiple SQL Server database objects between SQL Server instances. Most of SQL Servers DDL objects can be copied with this task.
Analysis Services Tasks
•Analysis Services Execute DDL Task: This task will run data definition language statements on Analysis Services. This allows for the create, drop, alter of cubes, dimensions and mining models.
•Analysis Services Processing Task: This task will process Analysis Services Cubes, Dimensions, and Mining Models.
•Data Mining Query Task: This task will run a DMX (Data Mining Extensions) query that create a prediction based on new data that is run against a Analysis Services data mining model.
Posted by Ravi at 5:59 AM 0 comments
Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz
Thursday, August 26, 2010
Checkpoints,ErrorHandiling, and Transactions in SSIS
Error Handling:
To use error paths, you will need to configure the error output. There are three error-handling options for handling errors in the data flow components:
• Setting the error output to Fail Transformation will cause the data flow to fail if an error is encountered.
• Using the Ignore Failure option will allow the row to continue out the normal green data path, but the value that resulted in the error is changed to a NULL in the output.
• Setting the error output to Redirect Row will send the error row out the red error path; this is the only way to handle errors with separate components.
Check Points:
What does it do?
With Checkpoints enabled on a package it will save the state of the package as it moves through each step or task and place it in a XML file upon failure of the package. If your package does fail you can correct the problem in your package and rerun from the point of the tasks that did not successfully run the first time. Once the package completes successfully the file is no longer needed and automatically discarded.
How does this benefit you?
Just imagine your package is loading a table with 10 million records. Your package passes the Data Flow that performs this huge load without any problem (Other than the fact that it took two hours to load). The next task in your package is a Send Mail Task and for some reason fails.
You correct the problem in the Send Mail Task, but without using Checkpoints your package would still have to run that Data Flow that loads the 10 million records again (taking another two hours) even though you’ve already done it once. If you had enable Checkpoints on this package you could simply correct the problem in the Send Mail Task and then run the package again starting at the Send Mail Task. Sounds great right?
How do I configure it?
This example will run you through very basic package using Checkpoints. To see these instructions with screenshots go to my regular blog http://blogs.pragmaticworks.com/devin_knight/2009/06/enabling-checkpoints-in-your-ssis-packages.html
Example Overview
• Use Three Execute SQL Task using the AdventureWorks2009 (It can really be any database for this example) database as a connection manager.
• Configure the package to handle Checkpoints
• Configure the individual tasks to handle Checkpoints
Step 1: Configure Execute SQL Tasks
• Drag three Execute SQL Tasks on your Control Flow.
• Use any database for the Connection property on all three tasks
• Configure Execute SQL Task SQLStatement property: Select 1
• Configure Execute SQL Task 1 SQLStatement property: Select A (Set to intentionally fail)
• Configure Execute SQL Task 2 SQLStatement property: Select 1
Step 2: Configure Package to enable Checkpoints
• Open the properties menu at the package level (Just open properties in the Control Flow without any task or connection manager selected)
• Change the properties CheckpointFileName: c:\Checkpoint.xml (Feel free to use the .txt extension when naming the checkpoint if you want to open it in notepad and look at it!)
• Change the properties CheckpointUsage: IfExists
• Change the properties SaveCheckpoints: True
Step 3: Configure Each Task
• Select each task individually and open the properties menu at the task level (Just click the task once then hit F4)
• Change the FailPackageOnFailure property to True
Step 4: Run the Package
• Run the package and you will see the package fail on the second task
• This also created the file c:\Checkpoints.xml. Feel free to open it and take a look! I use the tool XML Notepad to view XML Files. It’s Free.
• You could also save this file with the.txt extension and just view in regular notepad and it still works as a Checkpoint.
• If you run the package a second time it will skip the first task that was successful and start right at the second task
Step 5: Correct the Problem and Rerun Package
• Open the Execute SQL Task 2 and configure the SQLStatement property: Select 1
• The package has now completed and skipped the first step which already succeeded. Imagine if that first step would normally take two hours to run!
Defining Package and Task Transaction Settings
You can set package transactions at the entire package level or at any control flow container level or task level. Transactions in SSIS use the Windows Distributed Transaction Coordinator (DTC); the DTC service needs to be started on the machine for transactions to work. Any service or program that is enabled to work with the DTC can be part of a transaction in SSIS.
To enable a transaction within a package, you need to set the TransactionOption property of the task or container to Required. Figure 5-1 highlights the properties of a package at the control flow level, which means they apply to the package as a whole. The TransactionOption property is the same on any control flow object.
Figure:1 A task's or container's TransactionOption property must be set to Required to enable a transaction within a package.
When deciding whether and how to implement a transaction, follow these guidelines:
• For transactions to be enabled in SSIS, you need to turn on the DTC service, and the tasks that you want to be part of the transaction must work with the DTC service natively.
• If a series of tasks must be completed as a single unit, in which either all the tasks are successful and committed or an error occurs and none of the tasks are committed, then place the tasks within a Sequence Container, and then set the TransactionOption property of the container to Required.
• A task can inherit the transaction setting of its parent when the TransactionOption property is set to Supported, which is the default setting when creating a task or container.
• You can prevent a task from participating in a transaction by setting its TransactionOp-tion setting to NotSupported.
• Transactions work at the control flow level and not within a data flow. This means that you can turn on a transaction for a data flow task, but you cannot turn it on separately for selected components within the data flow; either the entire data process will be successful or it will be rolled back.
Implementing Restartability Checkpoints
At times, especially if you are working with complicated or long-running packages, you will want the ability to restart a package if it fails and have it start at the point of failure. In other words, you might not want the tasks that were already successful to be run again if the package is restarted. This can be done by enabling checkpoints in the package.
Enabling restartability within a package requires, first, enabling a package to use checkpoints, and, second, setting the specific tasks and containers to write checkpoints. To turn on checkpoints within a package, follow these steps:
1. Within the package, open the Properties window, and then select the Control Flow tab, which will reveal the properties of the package.
2. Set the SaveCheckpoints property at the package level to True. This allows checkpoints to be saved during package execution.
3. In the CheckpointFileName property, provide a valid path and file name to a checkpoint file. Packages use files to maintain their state information, so if a package fails and is then restarted, the package can read the checkpoint file to determine where it left off and to track the state information at the last successful task.
4. Set the CheckpointUsage to IfExists, which causes the package to run from the beginning if the file is not present or to run from the identified point if the file exists.
Practice: Implementing Package and Task Transactions
In this practice, you will turn on transactions at the container level and observe the results when a task fails within the container.
Exercise 1: Enabling Transactions
1. Navigate to the Control Panel/Administrative Tools/Services console, and then start the Distributed Transaction Coordinator service.
2. Open the SSIS project that you created in Chapter 4, and then open the package called MyPackage.dtsx. Or you can use the 'Start Here' project in the Source\Ch 05 folder in the installed practice files.
3. From the View menu in the menu bar, open the Properties window, and then click the pushpin in the Properties window to lock the window in the open position.
4. In the Control Flow Designer, select the Sequence Container (by clicking on it), and then note the Sequence Container properties listed in the Properties window.
5. Set the TransactionOption to Required using the drop-down list.
6. Save the package by clicking the Save icon in the toolbar.
Exercise 2: Observing a Transaction Rollback
1. With the package from Practice 1 still opened, expand the Sequence Container, and drag and drop a new Execute SQL Task to the bottom of the Sequence Container workspace.
2. Connect the green precedence arrow from the Data Flow to the new Execute SQL Task by dragging the green arrow from the bottom of the Data Flow onto the Execute SQL Task.
3. Edit the Execute SQL Task by double-clicking on the task. In the Execute SQL Task Editor, change the Connection property to the AdventureWorks connection.
4. Change the Name property within the Execute SQL Task Editor to Force Failure.
5. Select OK in the Execute SQL Task Editor to return to the Control Flow.
6. With the Force Failure Execute SQL Task still selected, open the Properties window and change the ForceExecutionResult property to Failure. By setting this property to Failure, you are specifying that the task should fail intentionally, which is something you might do for testing purposes.
7. Open a new database query, in SSMS, against the AdventureWorks database.
8. Run the following SQL statement and observe the results: SELECT COUNT(*) FROM Sales_Summary
9. In the Business Intelligence Development Studio (BIDS), execute the SSIS package you just modified, which will intentionally fail at the last step.
10. Stop the package execution, and rerun the query from step 8.
11. Observe that even though the data flow was successful, the data was rolled back because the Sequence Container was configured with a transaction, and the last task within the Sequence Container failed.
Quick Check
1. You add a sequence container to a package that contains several tasks, one of which calls a command on a legacy system and another of which a Data Flow Task imports data into SQL Server. Even with DTC started and transactions turned on, your sequence container fails before the tasks even run. What is the problem?
2. What do you need to set in order to use checkpoint properties at the package level, after you have turned the checkpoint properties on?
Quick Check Answers
1. The transactions featured in SSIS use the DTC service. However, not all systems support DTC, and a transaction cannot be forced on a non-compliant system, so the container will fail. You should remove the legacy task from the sequence container that has the transaction.
2. You need to set the FailPackageOnFailure property to True for tasks to write to the checkpoint file. However, if you want to rerun any successful tasks that occur before the failure task, you need to use a sequence container around the group of related tasks that require transactions.
Handling Package Errors with Event Handlers
In the data flow, using data viewers provides the ability to easily debug problems while processing data. The control flow, however, is different because the focus is on workflow and execution rather than on data and transformations. Leveraging the capabilities in Visual Studio, the control flow supports visual debugging and breakpoint features. Let's first look at the event handlers that SSIS provides; then we will explore the debugging capabilities in the control flow.
Event Handlers
SSIS provides the ability to listen for certain execution events and perform other operations when an event happens (depending on the execution event). For example, if an error happens, the error event handler can send an alert or potentially fix a data problem. Event handlers use the control flow paradigm for workflow processing, which includes all the same control flow tasks and containers that are found in the toolbox of the control flow.
You can define zero, one, or more than one event handler for a package. To add an event handler to a package, you need to select the Event Handler tab in the package designer. Creating a new package event handler requires that you select the executable and the event handler event, as Figure 2 shows.
Figure:2 Selecting the executable and event handler event for a package
The executable is the task or container scope that the event will fire. You can also choose the package itself (the highest-level container) as the executable for an event. The event handler event is the actual event that causes the event workflow to execute. The following table includes the package event handler types:
In addition, event handlers assigned to an executable scope will propagate down to child events when the event fires. If an event is assigned to a container, the child executables include the tasks and containers that are embedded within the parent container. This means that if you assign an OnError event to the package and an OnError event occurs at a task, the event handler would fire for both the task and the package (and for any containers in between). You would use an event handler for tracking error details, for sending failure messages in emails, and for implementing manual rollback logic.
BEST PRACTICES Capturing error information with the OnError event
Each package contains a set of system variables that are updated for the various levels in the package during the package execution. With event handlers, you can capture these variables and values, which provide contextual information, such as the ErrorCode, ErrorDescription, and SourceName (the task), when the event fires.
Using event handlers is a great way to track package execution; they can be used to audit the execution, capturing the errors that occur in a task. In addition, the event handler Send Mail Task can be used for notification; for example, it can notify an administrator of a certain predefined condition that requires a special response.
Exam Tip
Event handlers can be turned off for any task or container by setting the Disable-EventHandlers property of the Task or Container to True. In other words, if you have an event handler defined, but you specifically do not want it to be invoked for a specific task, then you can turn off event handlers for that task only.
Debugging the Control Flow with Breakpoints
Package debugging lets you know what is going on during the execution of a package in the designer so that you can troubleshoot or validate processing logic. Control flow debugging involves setting breakpoints in the package, which will pause the control flow execution so that you can observe the execution state. SSIS takes advantage of the breakpoint functionality that comes with Visual Studio, which means you have the capabilities to view execution information about the package when you execute a package in the designer.
BEST PRACTICES Breakpoints work in control flow only
Breakpoints function in the control flow but not in the data flow. For scripting, this means that you can set breakpoints only in a control flow Script Task and not in a data flow Script Component.
To set a breakpoint, highlight the task or container, and either press F9 or navigate to the Debug/Toggle Breakpoint menu. You can set multiple breakpoints in a package, and you can embed a breakpoint within a Script Task at a line of code. Figure:3 shows a package that is running but is paused at execution.
Figure:3 A package that is running but paused
In this screen, the arrow next to the breakpoint icon indicates which task the package is currently waiting to run. When you are paused in the debug environment, you can do the following things to help troubleshoot your package:
• Open the Locals window to see all the variable values and the package status. You can find this window in the Debug toolbar, next to the package execution selections. If you have several variables in a package that you actively use to control logic and precedence, you can use a breakpoint to pause the execution, allowing you to troubleshoot variable values handling before the package execution completes.
• When you have completed working during a pause and are in a Script Task, you can continue the execution of the script and package to the next breakpoint by either clicking the Continue button in the Debug toolbar or by pressing F5. Alternatively, you can stop the package from continuing by clicking the Stop button on the toolbar. Breakpoints in a Script Task are very useful because they help you validate the code logic and branching that you are performing with the script.
• When the package is paused on a task (as opposed to within the code of a Script Task as described in the prior bullet) in the control flow, you can also continue running the package to completion (or to the next breakpoint) by selecting the Continue button on the Debug toolbar or by pressing F5.
• Stopping the package during execution, whether the package is paused at a breakpoint or executing, is handled by clicking the Stop button in the toolbar or by pressing the Shift and F5 keys at the same time.
In all, breakpoints are powerful tools for resolving errors and validating functionality. Combined with data views in the data flow, they provide comprehensive debugging support during your package development.
Practice: Identifying Data Flow Errors
In this practice, you will add an error flow path and then identify the error by observing the rows in the output through a data viewer.
Exercise: Adding Error Flow Paths
1. In SSMS, create a new database query connected to the AdventureWorks sample database and run the following code:
USE [AdventureWorks] GO
TRUNCATE TABLE dbo.Sales_Summary GO
ALTER TABLE dbo.Sales_Summary WITH CHECK ADD CONSTRAINT [CK_Summary_ProductLine]
CHECK ((upper([ProductLine])='R' OR upper([ProductLine])='M' OR upper([ProductLine])='T')) GO
2. The above code uses the Sales_Summary table that you created in Chapter 4.
3. Open the package that you modified in the previous practices in this chapter.
4. Navigate to the Data Flow designer and open the OLE DB Destination adapter.
5. In the Data Access Mode drop-down list, change the selection to Table Or View, and then verify that the Sales_Summary table is still selected in the Name Of The Table Or The View drop-down list.
6. Click OK in the OLE DB Destination Editor to return to the package designer.
7. Right-click in the Data Flow workspace, and then choose Execute Task from the drop-down list to run the Data Flow Task. Before stopping the package, navigate to the Progress tab and observe that the OLE DB Destination failed because of a constraint violation.
8. Stop the package to return to design mode.
9. From the SSIS menu in the menu bar, select Variables; this will open the Variable window.
10. Select the leftmost icon in the Variable window toolbar to create a new variable for the package and name the variable ErrorCount.
11. Open the toolbar, and then drag a Row Count transformation onto the Data Flow work-space.
12. Highlight the OLE DB Destination adapter, and then drag the red error output path and drop it on the Row Count transformation.
13. When the Configure Error Output window appears, change the value in the Error Column drop-down list to Redirect Row, and then click OK to return to the Data Flow designer.
14. Open the Row Count transformation, and then change the VariableName property to
15. User::ErrorCount.
16. Click OK in the Row Count Editor to return to the Data Flow.
17. Right-click the red error path, and then select Data Viewers from the drop-down list. 16. Choose Add in the Data Flow Path Editor, highlight Grid, and click OK in the Configure
18. Data Viewer window and OK in the Data Flow Path Editor.
19. Right-click in the Data Flow designer workspace, and select Execute Task from the drop-down list.
20. A new Data Viewer will appear, which will reveal the OLE DB Destination Error Output.
21. Observe that the ProductLine column for all the error rows is S, which violates the defined constraint that you created in step 1.
22. Select Detach in the Data Viewer window, and then stop the package execution.
23. In SSMS, run the following database query, which adds S as a valid value of the Pro-ductLine column in the Sales_Summary table:
USE [AdventureWorks] GO
ALTER TABLE dbo.Sales_Summary
DROP CONSTRAINT [CK_Summary_ProductLine] GO
ALTER TABLE dbo.Sales_Summary WITH CHECK ADD CONSTRAINT [CK_Summary_ProductLine]
CHECK ((upper([ProductLine])='R' OR upper([ProductLine])='M' OR upper([ProductLine])='T' OR upper([ProductLine])='S')) GO
24. Return to BIDS and rerun the Data Flow, observing that the OLE DB Destination is now successful, with no rows being routed to the error path output or data viewer.
Quick Check
1. A Data Conversion transformation is failing in the middle of the data flow execution, and you need to determine what is causing the error. How should you proceed?
2. Your package contains a string variable that you are updating, using a Script Task, to be a file path and file name. Your package is failing at a File System Task that is configured to use the variable to move the file to a different folder on the server. How do you troubleshoot the package?
3. You would like to log all the package errors to a custom database table you have created for auditing purposes. How can you accomplish this task?
Quick Check Answers
1. To determine what is causing the error, configure the Data Conversion transformation error path to Flat File so that any rows that are failing conversion are sent out to a file. Then, create a data viewer on the error path, and run the package in BIDS. This technique will capture the errors in a file and display the rows in the designer for troubleshooting.
2. Because the Script Task can contain embedded breakpoints in the code, set a breakpoint in the script so that you will be able to execute the package and step through the lines of code, observing the value of the variable to check the code and accuracy.
3. By using the OnError event handler assigned to the package level, you can also use an Execute SQL Task that calls a stored procedure, passing in the SourceName and ErrorDescription variable values. The procedure can then track these details into a metadata storage table for auditing.
Posted by Ravi at 11:54 PM 0 comments
Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz
Thursday, August 19, 2010
Looping over files with the Foreach Loop Container
In SQL Server 2000 Data transformation Services (DTS) it was a bit of a hack to be able to loop over files of a given type in a certain directory and import them into your destination. It involved a lot of "Glue Code" and a certain amount of fooling the package into going back to a previous task because it still had work to do. Well thankfully in SQL Server 2005 Integration Services (SSIS) that has all changed and this article is going to show you how.
The image below shows us how incredibly simple and clean the package will look when finished. There are some things worth pointing out at this stage. In the centre of the screen we see the Foreach Enumerator container and inside that we see the Data Flow task which houses the pipeline. At the bottom in the Connection Managers tray we see our Flat File Connection Manager (My Source File) and our OLEDB Connection Manager (My Destination). The Flat File Connection Manager is the one in which we are most interested for this article. Both of these managers are used in the Data Flow behind the DataFlow task. We will not be detailing the pipeline behind the DataFlow task in this article but it consists of a Flat File Source moving data to an OLEDB destination.
Let's begin then by opening up the Foreach enumerator and moving straight to the Collection node in the tree on our left. Below we see our information already populated.
What we see on the screen is pretty self explanatory but let's go through it anyway. We have chosen to enumerate over a file collection and ths is indicated by the value next to the Enumerator property at the top. We need to specify a folder over which to loop and for which type of files to look and we do that in the centre of the form. We are given three options as to what is returned when the loop finds a file in the folder at the bottom of the form. We can return the whole filename including extension and path, the name and extension or simply the name of the file found. Because our connection manager is going to need to know exactly where to find the file and it's name we have hosen the first option. The final thing we see on this screen is the ability to traverse subfolders. In our example we do not need to do this.
When the Foreach enumerator finds a file it needs to tell us about what it found and it does this by populating a variable. Click on to the Variable Mappings node now. Our package currently has no variables able to accept the name of the file so we are going to create a new one.
The next screen we see allows us to set the values of the variable. As we can see variables can be scoped in SSIS to certain executables in the package or to the package itself.
Here is how our variable looks with all its properties set.
Because the enumerator will only return us at most one value on every iteration we map our variable to an index of 0.
We have now configured everything as far as the Foreach enumerator is concerned. We now need to set the rpoerties of the Flat File Connection Manager. Highlight the manager in the tray at the bottom, right click and choose properties.
The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column drop the list down and choose ConnectionString
Now hit the ellises button to the right and we are taken through to the expression editor where we will build the actual expression itself
Our requirements are pretty simple here and all we want to do is to retrieve the variable we defined earlier. To do this simply drag the variable from the list at the top to the expression text box at the bottom. Property Expressions can become very complex and we shall no dount be seeing more of them in future articles. After you have chosen the variable click OK
We now see that our expression is mapped to our ConnectionString property. Click OK
Finally we can now see our File Manager's Connection string property being mapped to an expression in the properties of the manager.
When the enumerator finds a file matching our requirements it will set the correct property on the connection manager and this will be used by the pipeline at runtime.
Data Flow Task
•Data Flow Task: This task extracts data from a source, allows for transformations of that data, and then the data is loaded into a target data destination.
Data Preparation Tasks
•File System Task: This task allows the user to copy/move/delete files and directories on a file system.
•FTP Task: This task allows the user to copy/move/delete files and directories over FTP.
•Web Service Task: This task allows the user to execute a Web service method and store the results
•XML Task: This task is used to work with XML data. XSLT can be used along with XPath to validate, compare and merge documents. The results of this can then be stored.
•Data Profiling Task: This task can be used for checking and validating data quality. Profiles can be set up and checked for varius data quality issues such as, column length issues, column patterns, column statics, etc.
Workflow Tasks
•Execute Package Task: This task will run other SQL Server Integration Services packages.
•Execute Process Task: This task will execute an application or batch file.
•Message Queue Task: This task allows you to send and receive messages between SSIS packages, or to send messages to an application via an application queue. This task uses Message Queuing (MSMQ)
•Send Mail Task: This task allows for email messages to be created and sent using an SMTP server.
•WMI Data Reader Task: This task allows a Package to query, using WQL, computer systems (local and remote) for information regarding that computer.
•WMI Event Watcher Task: This task watches for WMI events that have occurred on a computer system, and allows the package to take an action if certain criteria are met.
Scripting Tasks
•Script Task: This task can be used to program functions that are not available in the standard SSIS tasks or transformations. In SSIS 2005 this task can be programmed in VB .NET. In SSIS 2008 VB .NET and C# can be used to program a Script Task.
SQL Server Maintenance Tasks
•Back Up Database Task: This task will allow you to backup a one or many SQL Server databases.
•Check Database Integrity Task: This task will allow you to check the integrity of all the objects in one or many SQL Server databases.
•Execute SQL Server Agent Job Task: This task allows for the execution of a SQL Server Agent job.
•Execute T-SQL Statement Task: This task is similar to the Execute SQL Task, however it only supports Transact SQL Statements. It should be used for SQL Server specific SQL statements.
•History Cleanup Task: This task allows for the cleanup of historical activity data. It will cleanup the history for database maintenance plans, backup activites, restore activities and SQL Server agent jobs.
•Maintenance Cleanup Task: This task allows for the cleanup of backup files, and the reports of maintenance plans.
•Notify Operator Task: This task allows SSIS to notify SQL Server Agent operators. They can be notifies by email, pager, or netsend.
•Rebuild Index Task: This task will rebuild an index or indexes on one or many databases.
•Reorganize Index Task: This task will reorganize an index or indexes on one or many databases.
•Shrink Database Task: This task will shrink the size of the SQL Server database data and database log files.
•Update Statistics Task: This task will update the statistics for one of many tables in one or many databases.
SQL Server Tasks
•Bulk Insert Task: This task offers an efficient way to copy large volumes of data.
•Execute SQL Task: This task allows the execution of a SQL statement. If the statement returns results, they can be stored in a variable.
•Transfer Database Task: This task will copy or move a SQL Server database between two instances of SQL Server. It can even be used to make a copy of a database on the same server. Databases can be copied either online or offline.
•Transfer Error Messages Task: This task will transfer a single or multiple SQL Server user defined error messages between SQL Server instances. It can be setup to transfer specific user messages or all error messages.
•Transfer Jobs Task: This task will transfer a single or multiple SQL Server Agent jobs between SQL Server instances.
•Transfer Logins Task: This task will transfer a single or multiple SQL Server logins between SQL Server instances.
•Transfer Master Stored Procedures Task: This task will transfer a single or multiple SQL Server Master database stored procedures between SQL Server instances.
•Transfer SQL Server Objects Task: This task will transfer a single or multiple SQL Server database objects between SQL Server instances. Most of SQL Servers DDL objects can be copied with this task.
Analysis Services Tasks
•Analysis Services Execute DDL Task: This task will run data definition language statements on Analysis Services. This allows for the create, drop, alter of cubes, dimensions and mining models.
•Analysis Services Processing Task: This task will process Analysis Services Cubes, Dimensions, and Mining Models.
•Data Mining Query Task: This task will run a DMX (Data Mining Extensions) query that create a prediction based on new data that is run against a Analysis Services data mining model.
Posted by Ravi at 5:59 AM 0 comments
Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz
Thursday, August 26, 2010
Checkpoints,ErrorHandiling, and Transactions in SSIS
Error Handling:
To use error paths, you will need to configure the error output. There are three error-handling options for handling errors in the data flow components:
• Setting the error output to Fail Transformation will cause the data flow to fail if an error is encountered.
• Using the Ignore Failure option will allow the row to continue out the normal green data path, but the value that resulted in the error is changed to a NULL in the output.
• Setting the error output to Redirect Row will send the error row out the red error path; this is the only way to handle errors with separate components.
Check Points:
What does it do?
With Checkpoints enabled on a package it will save the state of the package as it moves through each step or task and place it in a XML file upon failure of the package. If your package does fail you can correct the problem in your package and rerun from the point of the tasks that did not successfully run the first time. Once the package completes successfully the file is no longer needed and automatically discarded.
How does this benefit you?
Just imagine your package is loading a table with 10 million records. Your package passes the Data Flow that performs this huge load without any problem (Other than the fact that it took two hours to load). The next task in your package is a Send Mail Task and for some reason fails.
You correct the problem in the Send Mail Task, but without using Checkpoints your package would still have to run that Data Flow that loads the 10 million records again (taking another two hours) even though you’ve already done it once. If you had enable Checkpoints on this package you could simply correct the problem in the Send Mail Task and then run the package again starting at the Send Mail Task. Sounds great right?
How do I configure it?
This example will run you through very basic package using Checkpoints. To see these instructions with screenshots go to my regular blog http://blogs.pragmaticworks.com/devin_knight/2009/06/enabling-checkpoints-in-your-ssis-packages.html
Example Overview
• Use Three Execute SQL Task using the AdventureWorks2009 (It can really be any database for this example) database as a connection manager.
• Configure the package to handle Checkpoints
• Configure the individual tasks to handle Checkpoints
Step 1: Configure Execute SQL Tasks
• Drag three Execute SQL Tasks on your Control Flow.
• Use any database for the Connection property on all three tasks
• Configure Execute SQL Task SQLStatement property: Select 1
• Configure Execute SQL Task 1 SQLStatement property: Select A (Set to intentionally fail)
• Configure Execute SQL Task 2 SQLStatement property: Select 1
Step 2: Configure Package to enable Checkpoints
• Open the properties menu at the package level (Just open properties in the Control Flow without any task or connection manager selected)
• Change the properties CheckpointFileName: c:\Checkpoint.xml (Feel free to use the .txt extension when naming the checkpoint if you want to open it in notepad and look at it!)
• Change the properties CheckpointUsage: IfExists
• Change the properties SaveCheckpoints: True
Step 3: Configure Each Task
• Select each task individually and open the properties menu at the task level (Just click the task once then hit F4)
• Change the FailPackageOnFailure property to True
Step 4: Run the Package
• Run the package and you will see the package fail on the second task
• This also created the file c:\Checkpoints.xml. Feel free to open it and take a look! I use the tool XML Notepad to view XML Files. It’s Free.
• You could also save this file with the.txt extension and just view in regular notepad and it still works as a Checkpoint.
• If you run the package a second time it will skip the first task that was successful and start right at the second task
Step 5: Correct the Problem and Rerun Package
• Open the Execute SQL Task 2 and configure the SQLStatement property: Select 1
• The package has now completed and skipped the first step which already succeeded. Imagine if that first step would normally take two hours to run!
Defining Package and Task Transaction Settings
You can set package transactions at the entire package level or at any control flow container level or task level. Transactions in SSIS use the Windows Distributed Transaction Coordinator (DTC); the DTC service needs to be started on the machine for transactions to work. Any service or program that is enabled to work with the DTC can be part of a transaction in SSIS.
To enable a transaction within a package, you need to set the TransactionOption property of the task or container to Required. Figure 5-1 highlights the properties of a package at the control flow level, which means they apply to the package as a whole. The TransactionOption property is the same on any control flow object.
Figure:1 A task's or container's TransactionOption property must be set to Required to enable a transaction within a package.
When deciding whether and how to implement a transaction, follow these guidelines:
• For transactions to be enabled in SSIS, you need to turn on the DTC service, and the tasks that you want to be part of the transaction must work with the DTC service natively.
• If a series of tasks must be completed as a single unit, in which either all the tasks are successful and committed or an error occurs and none of the tasks are committed, then place the tasks within a Sequence Container, and then set the TransactionOption property of the container to Required.
• A task can inherit the transaction setting of its parent when the TransactionOption property is set to Supported, which is the default setting when creating a task or container.
• You can prevent a task from participating in a transaction by setting its TransactionOp-tion setting to NotSupported.
• Transactions work at the control flow level and not within a data flow. This means that you can turn on a transaction for a data flow task, but you cannot turn it on separately for selected components within the data flow; either the entire data process will be successful or it will be rolled back.
Implementing Restartability Checkpoints
At times, especially if you are working with complicated or long-running packages, you will want the ability to restart a package if it fails and have it start at the point of failure. In other words, you might not want the tasks that were already successful to be run again if the package is restarted. This can be done by enabling checkpoints in the package.
Enabling restartability within a package requires, first, enabling a package to use checkpoints, and, second, setting the specific tasks and containers to write checkpoints. To turn on checkpoints within a package, follow these steps:
1. Within the package, open the Properties window, and then select the Control Flow tab, which will reveal the properties of the package.
2. Set the SaveCheckpoints property at the package level to True. This allows checkpoints to be saved during package execution.
3. In the CheckpointFileName property, provide a valid path and file name to a checkpoint file. Packages use files to maintain their state information, so if a package fails and is then restarted, the package can read the checkpoint file to determine where it left off and to track the state information at the last successful task.
4. Set the CheckpointUsage to IfExists, which causes the package to run from the beginning if the file is not present or to run from the identified point if the file exists.
Practice: Implementing Package and Task Transactions
In this practice, you will turn on transactions at the container level and observe the results when a task fails within the container.
Exercise 1: Enabling Transactions
1. Navigate to the Control Panel/Administrative Tools/Services console, and then start the Distributed Transaction Coordinator service.
2. Open the SSIS project that you created in Chapter 4, and then open the package called MyPackage.dtsx. Or you can use the 'Start Here' project in the Source\Ch 05 folder in the installed practice files.
3. From the View menu in the menu bar, open the Properties window, and then click the pushpin in the Properties window to lock the window in the open position.
4. In the Control Flow Designer, select the Sequence Container (by clicking on it), and then note the Sequence Container properties listed in the Properties window.
5. Set the TransactionOption to Required using the drop-down list.
6. Save the package by clicking the Save icon in the toolbar.
Exercise 2: Observing a Transaction Rollback
1. With the package from Practice 1 still opened, expand the Sequence Container, and drag and drop a new Execute SQL Task to the bottom of the Sequence Container workspace.
2. Connect the green precedence arrow from the Data Flow to the new Execute SQL Task by dragging the green arrow from the bottom of the Data Flow onto the Execute SQL Task.
3. Edit the Execute SQL Task by double-clicking on the task. In the Execute SQL Task Editor, change the Connection property to the AdventureWorks connection.
4. Change the Name property within the Execute SQL Task Editor to Force Failure.
5. Select OK in the Execute SQL Task Editor to return to the Control Flow.
6. With the Force Failure Execute SQL Task still selected, open the Properties window and change the ForceExecutionResult property to Failure. By setting this property to Failure, you are specifying that the task should fail intentionally, which is something you might do for testing purposes.
7. Open a new database query, in SSMS, against the AdventureWorks database.
8. Run the following SQL statement and observe the results: SELECT COUNT(*) FROM Sales_Summary
9. In the Business Intelligence Development Studio (BIDS), execute the SSIS package you just modified, which will intentionally fail at the last step.
10. Stop the package execution, and rerun the query from step 8.
11. Observe that even though the data flow was successful, the data was rolled back because the Sequence Container was configured with a transaction, and the last task within the Sequence Container failed.
Quick Check
1. You add a sequence container to a package that contains several tasks, one of which calls a command on a legacy system and another of which a Data Flow Task imports data into SQL Server. Even with DTC started and transactions turned on, your sequence container fails before the tasks even run. What is the problem?
2. What do you need to set in order to use checkpoint properties at the package level, after you have turned the checkpoint properties on?
Quick Check Answers
1. The transactions featured in SSIS use the DTC service. However, not all systems support DTC, and a transaction cannot be forced on a non-compliant system, so the container will fail. You should remove the legacy task from the sequence container that has the transaction.
2. You need to set the FailPackageOnFailure property to True for tasks to write to the checkpoint file. However, if you want to rerun any successful tasks that occur before the failure task, you need to use a sequence container around the group of related tasks that require transactions.
Handling Package Errors with Event Handlers
In the data flow, using data viewers provides the ability to easily debug problems while processing data. The control flow, however, is different because the focus is on workflow and execution rather than on data and transformations. Leveraging the capabilities in Visual Studio, the control flow supports visual debugging and breakpoint features. Let's first look at the event handlers that SSIS provides; then we will explore the debugging capabilities in the control flow.
Event Handlers
SSIS provides the ability to listen for certain execution events and perform other operations when an event happens (depending on the execution event). For example, if an error happens, the error event handler can send an alert or potentially fix a data problem. Event handlers use the control flow paradigm for workflow processing, which includes all the same control flow tasks and containers that are found in the toolbox of the control flow.
You can define zero, one, or more than one event handler for a package. To add an event handler to a package, you need to select the Event Handler tab in the package designer. Creating a new package event handler requires that you select the executable and the event handler event, as Figure 2 shows.
Figure:2 Selecting the executable and event handler event for a package
The executable is the task or container scope that the event will fire. You can also choose the package itself (the highest-level container) as the executable for an event. The event handler event is the actual event that causes the event workflow to execute. The following table includes the package event handler types:
In addition, event handlers assigned to an executable scope will propagate down to child events when the event fires. If an event is assigned to a container, the child executables include the tasks and containers that are embedded within the parent container. This means that if you assign an OnError event to the package and an OnError event occurs at a task, the event handler would fire for both the task and the package (and for any containers in between). You would use an event handler for tracking error details, for sending failure messages in emails, and for implementing manual rollback logic.
BEST PRACTICES Capturing error information with the OnError event
Each package contains a set of system variables that are updated for the various levels in the package during the package execution. With event handlers, you can capture these variables and values, which provide contextual information, such as the ErrorCode, ErrorDescription, and SourceName (the task), when the event fires.
Using event handlers is a great way to track package execution; they can be used to audit the execution, capturing the errors that occur in a task. In addition, the event handler Send Mail Task can be used for notification; for example, it can notify an administrator of a certain predefined condition that requires a special response.
Exam Tip
Event handlers can be turned off for any task or container by setting the Disable-EventHandlers property of the Task or Container to True. In other words, if you have an event handler defined, but you specifically do not want it to be invoked for a specific task, then you can turn off event handlers for that task only.
Debugging the Control Flow with Breakpoints
Package debugging lets you know what is going on during the execution of a package in the designer so that you can troubleshoot or validate processing logic. Control flow debugging involves setting breakpoints in the package, which will pause the control flow execution so that you can observe the execution state. SSIS takes advantage of the breakpoint functionality that comes with Visual Studio, which means you have the capabilities to view execution information about the package when you execute a package in the designer.
BEST PRACTICES Breakpoints work in control flow only
Breakpoints function in the control flow but not in the data flow. For scripting, this means that you can set breakpoints only in a control flow Script Task and not in a data flow Script Component.
To set a breakpoint, highlight the task or container, and either press F9 or navigate to the Debug/Toggle Breakpoint menu. You can set multiple breakpoints in a package, and you can embed a breakpoint within a Script Task at a line of code. Figure:3 shows a package that is running but is paused at execution.
Figure:3 A package that is running but paused
In this screen, the arrow next to the breakpoint icon indicates which task the package is currently waiting to run. When you are paused in the debug environment, you can do the following things to help troubleshoot your package:
• Open the Locals window to see all the variable values and the package status. You can find this window in the Debug toolbar, next to the package execution selections. If you have several variables in a package that you actively use to control logic and precedence, you can use a breakpoint to pause the execution, allowing you to troubleshoot variable values handling before the package execution completes.
• When you have completed working during a pause and are in a Script Task, you can continue the execution of the script and package to the next breakpoint by either clicking the Continue button in the Debug toolbar or by pressing F5. Alternatively, you can stop the package from continuing by clicking the Stop button on the toolbar. Breakpoints in a Script Task are very useful because they help you validate the code logic and branching that you are performing with the script.
• When the package is paused on a task (as opposed to within the code of a Script Task as described in the prior bullet) in the control flow, you can also continue running the package to completion (or to the next breakpoint) by selecting the Continue button on the Debug toolbar or by pressing F5.
• Stopping the package during execution, whether the package is paused at a breakpoint or executing, is handled by clicking the Stop button in the toolbar or by pressing the Shift and F5 keys at the same time.
In all, breakpoints are powerful tools for resolving errors and validating functionality. Combined with data views in the data flow, they provide comprehensive debugging support during your package development.
Practice: Identifying Data Flow Errors
In this practice, you will add an error flow path and then identify the error by observing the rows in the output through a data viewer.
Exercise: Adding Error Flow Paths
1. In SSMS, create a new database query connected to the AdventureWorks sample database and run the following code:
USE [AdventureWorks] GO
TRUNCATE TABLE dbo.Sales_Summary GO
ALTER TABLE dbo.Sales_Summary WITH CHECK ADD CONSTRAINT [CK_Summary_ProductLine]
CHECK ((upper([ProductLine])='R' OR upper([ProductLine])='M' OR upper([ProductLine])='T')) GO
2. The above code uses the Sales_Summary table that you created in Chapter 4.
3. Open the package that you modified in the previous practices in this chapter.
4. Navigate to the Data Flow designer and open the OLE DB Destination adapter.
5. In the Data Access Mode drop-down list, change the selection to Table Or View, and then verify that the Sales_Summary table is still selected in the Name Of The Table Or The View drop-down list.
6. Click OK in the OLE DB Destination Editor to return to the package designer.
7. Right-click in the Data Flow workspace, and then choose Execute Task from the drop-down list to run the Data Flow Task. Before stopping the package, navigate to the Progress tab and observe that the OLE DB Destination failed because of a constraint violation.
8. Stop the package to return to design mode.
9. From the SSIS menu in the menu bar, select Variables; this will open the Variable window.
10. Select the leftmost icon in the Variable window toolbar to create a new variable for the package and name the variable ErrorCount.
11. Open the toolbar, and then drag a Row Count transformation onto the Data Flow work-space.
12. Highlight the OLE DB Destination adapter, and then drag the red error output path and drop it on the Row Count transformation.
13. When the Configure Error Output window appears, change the value in the Error Column drop-down list to Redirect Row, and then click OK to return to the Data Flow designer.
14. Open the Row Count transformation, and then change the VariableName property to
15. User::ErrorCount.
16. Click OK in the Row Count Editor to return to the Data Flow.
17. Right-click the red error path, and then select Data Viewers from the drop-down list. 16. Choose Add in the Data Flow Path Editor, highlight Grid, and click OK in the Configure
18. Data Viewer window and OK in the Data Flow Path Editor.
19. Right-click in the Data Flow designer workspace, and select Execute Task from the drop-down list.
20. A new Data Viewer will appear, which will reveal the OLE DB Destination Error Output.
21. Observe that the ProductLine column for all the error rows is S, which violates the defined constraint that you created in step 1.
22. Select Detach in the Data Viewer window, and then stop the package execution.
23. In SSMS, run the following database query, which adds S as a valid value of the Pro-ductLine column in the Sales_Summary table:
USE [AdventureWorks] GO
ALTER TABLE dbo.Sales_Summary
DROP CONSTRAINT [CK_Summary_ProductLine] GO
ALTER TABLE dbo.Sales_Summary WITH CHECK ADD CONSTRAINT [CK_Summary_ProductLine]
CHECK ((upper([ProductLine])='R' OR upper([ProductLine])='M' OR upper([ProductLine])='T' OR upper([ProductLine])='S')) GO
24. Return to BIDS and rerun the Data Flow, observing that the OLE DB Destination is now successful, with no rows being routed to the error path output or data viewer.
Quick Check
1. A Data Conversion transformation is failing in the middle of the data flow execution, and you need to determine what is causing the error. How should you proceed?
2. Your package contains a string variable that you are updating, using a Script Task, to be a file path and file name. Your package is failing at a File System Task that is configured to use the variable to move the file to a different folder on the server. How do you troubleshoot the package?
3. You would like to log all the package errors to a custom database table you have created for auditing purposes. How can you accomplish this task?
Quick Check Answers
1. To determine what is causing the error, configure the Data Conversion transformation error path to Flat File so that any rows that are failing conversion are sent out to a file. Then, create a data viewer on the error path, and run the package in BIDS. This technique will capture the errors in a file and display the rows in the designer for troubleshooting.
2. Because the Script Task can contain embedded breakpoints in the code, set a breakpoint in the script so that you will be able to execute the package and step through the lines of code, observing the value of the variable to check the code and accuracy.
3. By using the OnError event handler assigned to the package level, you can also use an Execute SQL Task that calls a stored procedure, passing in the SourceName and ErrorDescription variable values. The procedure can then track these details into a metadata storage table for auditing.
Posted by Ravi at 11:54 PM 0 comments
Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz
Thursday, August 19, 2010
Looping over files with the Foreach Loop Container
In SQL Server 2000 Data transformation Services (DTS) it was a bit of a hack to be able to loop over files of a given type in a certain directory and import them into your destination. It involved a lot of "Glue Code" and a certain amount of fooling the package into going back to a previous task because it still had work to do. Well thankfully in SQL Server 2005 Integration Services (SSIS) that has all changed and this article is going to show you how.
The image below shows us how incredibly simple and clean the package will look when finished. There are some things worth pointing out at this stage. In the centre of the screen we see the Foreach Enumerator container and inside that we see the Data Flow task which houses the pipeline. At the bottom in the Connection Managers tray we see our Flat File Connection Manager (My Source File) and our OLEDB Connection Manager (My Destination). The Flat File Connection Manager is the one in which we are most interested for this article. Both of these managers are used in the Data Flow behind the DataFlow task. We will not be detailing the pipeline behind the DataFlow task in this article but it consists of a Flat File Source moving data to an OLEDB destination.
Let's begin then by opening up the Foreach enumerator and moving straight to the Collection node in the tree on our left. Below we see our information already populated.
What we see on the screen is pretty self explanatory but let's go through it anyway. We have chosen to enumerate over a file collection and ths is indicated by the value next to the Enumerator property at the top. We need to specify a folder over which to loop and for which type of files to look and we do that in the centre of the form. We are given three options as to what is returned when the loop finds a file in the folder at the bottom of the form. We can return the whole filename including extension and path, the name and extension or simply the name of the file found. Because our connection manager is going to need to know exactly where to find the file and it's name we have hosen the first option. The final thing we see on this screen is the ability to traverse subfolders. In our example we do not need to do this.
When the Foreach enumerator finds a file it needs to tell us about what it found and it does this by populating a variable. Click on to the Variable Mappings node now. Our package currently has no variables able to accept the name of the file so we are going to create a new one.
The next screen we see allows us to set the values of the variable. As we can see variables can be scoped in SSIS to certain executables in the package or to the package itself.
Here is how our variable looks with all its properties set.
Because the enumerator will only return us at most one value on every iteration we map our variable to an index of 0.
We have now configured everything as far as the Foreach enumerator is concerned. We now need to set the rpoerties of the Flat File Connection Manager. Highlight the manager in the tray at the bottom, right click and choose properties.
The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column drop the list down and choose ConnectionString
Now hit the ellises button to the right and we are taken through to the expression editor where we will build the actual expression itself
Our requirements are pretty simple here and all we want to do is to retrieve the variable we defined earlier. To do this simply drag the variable from the list at the top to the expression text box at the bottom. Property Expressions can become very complex and we shall no dount be seeing more of them in future articles. After you have chosen the variable click OK
We now see that our expression is mapped to our ConnectionString property. Click OK
Finally we can now see our File Manager's Connection string property being mapped to an expression in the properties of the manager.
When the enumerator finds a file matching our requirements it will set the correct property on the connection manager and this will be used by the pipeline at runtime.
Saving and Running Packages
Once created a SSIS package, you're probably ready to run it and see what it does. But first, let's look at the options for saving SSIS packages. When you work in BIDS, your SSIS package is saved as an XML file (with the extension dtsx) directly in the normal Windows file system. But that's not the only option. Packages can also be saved in the msdb database in SQL Server itself, or in a special area of the file system called the Package Store.
Storing SSIS packages in the Package Store or the msdb database makes it easier to access and manage them from SQL Server's administrative and command-line tools without needing to have any knowledge of the physical layout of the server's hard drive.
Saving Packages to Alternate Locations
To save a package to the msdb database or the Package Store, you use the File > Save Package As menu item within BIDS.
To store copies of the package you've developed, follow these steps.
1. Select File > Save Copy of Package.dtsx As from the BIDS menus.
2. Select SSIS Package Store as the Package Location.
3. Select the name of your test server.
4. Enter the package path.
5. Click OK.
6. Select File > Save Copy of Package.dtsx As from the BIDS menus.
7. Select SQL Server as the Package Location.
8. Select the name of your test server and fill in your authentication information.
9. Enter ExportDepartments as the package path.
10. Click OK.
Running a Package
You can run the final package from either BIDS or SQL Server Management Studio. When you're developing a package, it's convenient to run it directly from BIDS. When the package has been deployed to a production server (and saved to the msdb database or the Package Store) you'll probably want to run it from SQL Server Management Studio.
SQL Server also includes a command-line utility, dtsexec, that lets you run packages from batch files.
Running a Package from BIDS
With the package open in BIDS, you can run it using the standard Visual Studio tools for running a project. Choose any of these options:
* Right-click the package in Solution Explorer and select Execute Package.
* Click the Start Debugging toolbar button.
* Press F5.
To run the package that you have loaded in BIDS, follow these steps:
1. Click the Start Debugging toolbar button. SSIS will execute the package, highlighting the steps in the package as they are completed. You can select any tab to watch what's going on. For example, if you select the Control Flow tab, you'll see tasks highlighted, as shown in Figure.
2. When the package finishes executing, click the hyperlink underneath the Connection Managers pane to stop the debugger.
3. Click the Execution Results tab to see detailed information on the package, as shown in Figure.
All of the events you see in the Execution Results pane are things that you can create event handlers to react to within the package. As you can see, DTS issues a quite a number of events, from progress events to warnings about extra columns of data that we retrieved but never used.
Running a Package from SQL Server Management Studio
To run a package from SQL Server Management Studio, you need to connect Object Browser to SSIS.
Try It!
1. In SQL Server Management Studio, click the Connect button at the top of the Object Explorer window.
2. Select Integration Services.
3. Choose the server with Integration Services installed and click Connect. This will add an Integration Services node at the bottom of Object Explorer.
4. Expand the Stored Packages node. You'll see that you can drill down into the File System node to find packages in the Package Store, or the MSDB node to find packages stored in the msdb database.
5. Expand the File System node.
6. Right-click on the package and select Run Package. This will open the Execute Package utility, shown in Figure .
7. Click Execute.
8. Click Close twice to dismiss the progress dialog box and the Execute Package Utility.
9. Browse for the inserted data
10. Click the Execute toolbar button to verify that the package was run. You should see one entry for when the package was run from BIDS and one from when you ran it from SQL Server Management Studio.
Storing SSIS packages in the Package Store or the msdb database makes it easier to access and manage them from SQL Server's administrative and command-line tools without needing to have any knowledge of the physical layout of the server's hard drive.
Saving Packages to Alternate Locations
To save a package to the msdb database or the Package Store, you use the File > Save Package As menu item within BIDS.
To store copies of the package you've developed, follow these steps.
1. Select File > Save Copy of Package.dtsx As from the BIDS menus.
2. Select SSIS Package Store as the Package Location.
3. Select the name of your test server.
4. Enter the package path.
5. Click OK.
6. Select File > Save Copy of Package.dtsx As from the BIDS menus.
7. Select SQL Server as the Package Location.
8. Select the name of your test server and fill in your authentication information.
9. Enter ExportDepartments as the package path.
10. Click OK.
Running a Package
You can run the final package from either BIDS or SQL Server Management Studio. When you're developing a package, it's convenient to run it directly from BIDS. When the package has been deployed to a production server (and saved to the msdb database or the Package Store) you'll probably want to run it from SQL Server Management Studio.
SQL Server also includes a command-line utility, dtsexec, that lets you run packages from batch files.
Running a Package from BIDS
With the package open in BIDS, you can run it using the standard Visual Studio tools for running a project. Choose any of these options:
* Right-click the package in Solution Explorer and select Execute Package.
* Click the Start Debugging toolbar button.
* Press F5.
To run the package that you have loaded in BIDS, follow these steps:
1. Click the Start Debugging toolbar button. SSIS will execute the package, highlighting the steps in the package as they are completed. You can select any tab to watch what's going on. For example, if you select the Control Flow tab, you'll see tasks highlighted, as shown in Figure.
2. When the package finishes executing, click the hyperlink underneath the Connection Managers pane to stop the debugger.
3. Click the Execution Results tab to see detailed information on the package, as shown in Figure.
All of the events you see in the Execution Results pane are things that you can create event handlers to react to within the package. As you can see, DTS issues a quite a number of events, from progress events to warnings about extra columns of data that we retrieved but never used.
Running a Package from SQL Server Management Studio
To run a package from SQL Server Management Studio, you need to connect Object Browser to SSIS.
Try It!
1. In SQL Server Management Studio, click the Connect button at the top of the Object Explorer window.
2. Select Integration Services.
3. Choose the server with Integration Services installed and click Connect. This will add an Integration Services node at the bottom of Object Explorer.
4. Expand the Stored Packages node. You'll see that you can drill down into the File System node to find packages in the Package Store, or the MSDB node to find packages stored in the msdb database.
5. Expand the File System node.
6. Right-click on the package and select Run Package. This will open the Execute Package utility, shown in Figure .
7. Click Execute.
8. Click Close twice to dismiss the progress dialog box and the Execute Package Utility.
9. Browse for the inserted data
10. Click the Execute toolbar button to verify that the package was run. You should see one entry for when the package was run from BIDS and one from when you ran it from SQL Server Management Studio.
Advantages of SSRS?
Advantages Of Ssrs
* 'Direct' and efficient reporting access to information residing in both Oracle and MS SQL Server databases.
* Faster (and therefore cheaper) production of reports on both relational and cube data.
* An easy to deploy centralised reporting infrastructure based on Microsoft Reporting Services.
* Faster delivery of information to the business, providing better decision support.
* Ability for the business to self-serve, edit and interact with information without having to rely on IT or IS resources.
* Simple pricing model tailored for both entry and enterprise level installations, allowing for inexpensive provision of Business Intelligence for the Masses and democratisation of information.
* No need for expensive specialist skills.
* The beauty is that the entire report and data source definition is stored as a simple XML file. This is the file the reporting engine uses to render reports. The elements and attributes required for defining a report format are fully documented. Further, you can even add your custom elements if you want to enrich available functionality. Most report writers available today never provided this functionality.
* XML based report definition allows you to directly design reports programmatically and render them. This was very difficult to achieve in currently available report writers.
* The default report designer is integrated with Visual Studio .NET so that you can create application and its reports in the same environment.
* The report designer eliminates the traditional bands very effectively. It provides three types of elements—Table, Matrix and List. Table is equivalent to the traditional report with header, footer, detail and groups. You can have multiple tables rendering different data arranged side by side!
* For each type of reporting element, you have to attach a dataset to it. Dataset is based upon data source.
* The matrix is like a pivot table. It has rows, columns and cells containing computed data. Very useful and very easy. I am sure all of you remember how much we have to struggle today to create a simple cross-tab report. Write complex queries, struggle with table formatting and so on. With this new tool, just drag the matrix on the report, specify row, column and data fields and that’s it.
* The list is free form data. It can be descriptive and cannot be represented as a structured table, somewhat like a data repeater. Whatever data elements you put in the list are repeated for each row in the base dataset. This allows you to create free form layout reports that still repeat for each data item.
* The report items can be recursive. For example, one list can contain another list. What’s more one report can be defined as a sub-report of the base report. This provides more than just drill down. The subreport also need not be hard coded. Parameters can be passed online to it based upon the area of base report clicked.
* Now, about rendering. This is the most sophisticated part. By default rendering is in HTML. But while you are viewing the report, you can simply click on the toolbar and render it in many different ways.
* The most important part is that all the reports are stored on the central SQL Server database. Usually, we have reports for each application stored and managed separately. This leads to a lot of confusion and administrative headaches.
* The reports are viewed and administered by using a Web-based implementation of the entire reporting engine. The default website provides a base structure which is folder based. Typically you will have folders created for each application or user functionality.
* How do you access reports usually? By instancing the report writer runtime. Here you don’t have to do that. Because all reports are accessible in one of the two ways:
- By specifying the URL identifying the report on the reportserver or
- By calling the Web service.
* The best part of the reporting server is that the entire functionality is exposed as a single Web service! You can create, manage, and view reports using various methods provided by the web service.
* The security is managed in a role-based manner and can be applied to folders as well as reports.
* User can manage their own reporting needs by accessing reports ad-hoc or by subscribing to the reports. Subscription based reports are automatically sent by mail to the users.
* All reports require parameters to be accepted from users. Here once parameters are defined, the UI for these parameters is automatically generated.
* Finally, you have many ways of rendering the reports:
* HTML (MHTML)
* Excel
* Acrobat
* Tiff (image)
* XML
* CSV
* And of course, you can write your own rendering mechanism, if you like!
* Depending upon the type of output you want, some features are disabled. For example, HTML reports do not support pagination. Whereas, XML and CSV will not support drilldown. This is primarily due to the nature of the output format and not due to inadequate rendering capabilities of the reporting services.
* 'Direct' and efficient reporting access to information residing in both Oracle and MS SQL Server databases.
* Faster (and therefore cheaper) production of reports on both relational and cube data.
* An easy to deploy centralised reporting infrastructure based on Microsoft Reporting Services.
* Faster delivery of information to the business, providing better decision support.
* Ability for the business to self-serve, edit and interact with information without having to rely on IT or IS resources.
* Simple pricing model tailored for both entry and enterprise level installations, allowing for inexpensive provision of Business Intelligence for the Masses and democratisation of information.
* No need for expensive specialist skills.
* The beauty is that the entire report and data source definition is stored as a simple XML file. This is the file the reporting engine uses to render reports. The elements and attributes required for defining a report format are fully documented. Further, you can even add your custom elements if you want to enrich available functionality. Most report writers available today never provided this functionality.
* XML based report definition allows you to directly design reports programmatically and render them. This was very difficult to achieve in currently available report writers.
* The default report designer is integrated with Visual Studio .NET so that you can create application and its reports in the same environment.
* The report designer eliminates the traditional bands very effectively. It provides three types of elements—Table, Matrix and List. Table is equivalent to the traditional report with header, footer, detail and groups. You can have multiple tables rendering different data arranged side by side!
* For each type of reporting element, you have to attach a dataset to it. Dataset is based upon data source.
* The matrix is like a pivot table. It has rows, columns and cells containing computed data. Very useful and very easy. I am sure all of you remember how much we have to struggle today to create a simple cross-tab report. Write complex queries, struggle with table formatting and so on. With this new tool, just drag the matrix on the report, specify row, column and data fields and that’s it.
* The list is free form data. It can be descriptive and cannot be represented as a structured table, somewhat like a data repeater. Whatever data elements you put in the list are repeated for each row in the base dataset. This allows you to create free form layout reports that still repeat for each data item.
* The report items can be recursive. For example, one list can contain another list. What’s more one report can be defined as a sub-report of the base report. This provides more than just drill down. The subreport also need not be hard coded. Parameters can be passed online to it based upon the area of base report clicked.
* Now, about rendering. This is the most sophisticated part. By default rendering is in HTML. But while you are viewing the report, you can simply click on the toolbar and render it in many different ways.
* The most important part is that all the reports are stored on the central SQL Server database. Usually, we have reports for each application stored and managed separately. This leads to a lot of confusion and administrative headaches.
* The reports are viewed and administered by using a Web-based implementation of the entire reporting engine. The default website provides a base structure which is folder based. Typically you will have folders created for each application or user functionality.
* How do you access reports usually? By instancing the report writer runtime. Here you don’t have to do that. Because all reports are accessible in one of the two ways:
- By specifying the URL identifying the report on the reportserver or
- By calling the Web service.
* The best part of the reporting server is that the entire functionality is exposed as a single Web service! You can create, manage, and view reports using various methods provided by the web service.
* The security is managed in a role-based manner and can be applied to folders as well as reports.
* User can manage their own reporting needs by accessing reports ad-hoc or by subscribing to the reports. Subscription based reports are automatically sent by mail to the users.
* All reports require parameters to be accepted from users. Here once parameters are defined, the UI for these parameters is automatically generated.
* Finally, you have many ways of rendering the reports:
* HTML (MHTML)
* Excel
* Acrobat
* Tiff (image)
* XML
* CSV
* And of course, you can write your own rendering mechanism, if you like!
* Depending upon the type of output you want, some features are disabled. For example, HTML reports do not support pagination. Whereas, XML and CSV will not support drilldown. This is primarily due to the nature of the output format and not due to inadequate rendering capabilities of the reporting services.
SQL Server Interview Questions2
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
SQL Server Interview Questions
1
What is denormalization and when would you go for it?
A
As the name indicates, denormalization is the reverse process of normalization. It's the controlled introduction of redundancy in to the database design. It helps improve the query performance as the number of joins could be reduced.
2
How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables?
A
One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships. One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships. Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.
3
What's the difference between a primary key and a unique key?
A
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.
4
What are user defined datatypes and when you should go for them?
A
User defined datatypes let you extend the base SQL Server datatypes by providing a descriptive name, and format to the database. Take for example, in your database, there is a column called ZIP_Code which appears in many tables. In all these tables it should be varchar(6).
In this case you could create a user defined datatype called ZIP_Code_Type of varchar(6) and use it across all your tables.
5
What is bit datatype and what's the information that can be stored inside a bit column?
A
Bit datatype is used to store boolean information like 1 or 0 (true or false). Untill SQL Server 6.5 bit datatype could hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit datatype can represent a third state, which is NULL.
6
Define candidate key, alternate key, composite key.
A
A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table. If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys. A key formed by combining at least two or more columns is called composite key.
7
What are defaults? Is there a column to which a default can't be bound?
A
A default is a value that will be used by a column, if no value is supplied to that column while inserting data. IDENTITY columns and timestamp columns can't have defaults bound to them. See CREATE DEFUALT in books online.
8
What is a transaction and what are ACID properties?
A
A transaction is a logical unit of work in which, all the steps must be performed or none. ACID stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a transaction. For more information and explanation of these properties, see SQL Server books online or any RDBMS fundamentals text book.
9
Explain different isolation levels An isolation level determines the degree of isolation of data between concurrent transactions.
A
The default SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read, Serializable.
10
How does .NET and SQL SERVER thread is work?
A
There are two types of threading pre-emptive and Non-preemptive but Sql Server support Non-preemptive and .NET thread model is different. Because Sql have to handle thread in different way for SQLCLR this different thread are known as Tasking of Threads . In this thread there is a switch between SQLCLR and SQL SERVER threads .SQL SERVER uses blocking points for transition to happen between SQLCLR and SQL SERVER threads.
11
What's the maximum size of a row?
A
8060 bytes.
12
What is lock escalation?
A
Strong names are required to store shared assemblies in the global assembly cache (GAC). This is because the GAC allows multiple versions of the same assembly to reside on your system simultaneously, so that each application can find and use its own version of your assembly. This helps avoid DLL Hell, where applications that may be compiled to different versions of your assembly could potentially break because they are all forced to use the same version of your assembly.
Another reason to use strong names is to make it difficult for hackers to spoof your assembly, in other words, replace or inject your assembly with a virus or malicious code.
13
What's the difference between DELETE TABLE and TRUNCATE TABLE commands?
A
DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
14
What are constraints? Explain different types of constraints.
A
Constraints enable the RDBMS enforce the integrity of the database automatically, without needing you to create triggers, rule or defaults. Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY
15
Whar is an index?
A
Indexes in SQL Server are similar to the indexes in books. They help SQL Server retrieve the data quicker.
16
What are the types of indexes?
A
Indexes are of two types. Clustered indexes and non-clustered indexes. When you craete a clustered index on a table, all the rows in the table are stored in the order of the clustered index key. So, there can be only one clustered index per table. Non-clustered indexes have their own storage separate from the table data storage. Non-clustered indexes are stored as B-tree structures (so do clustered indexes), with the leaf level nodes having the index key and it's row locater. The row located could be the RID or the Clustered index key, depending up on the absence or presence of clustered index on the table.
17
I create a separate index on each column of a table. what are the advantages and disadvantages of this approach?
A
If you create an index on each column of a table, it improves the query performance, as the query optimizer can choose from all the existing indexes to come up with an efficient execution plan. At the same t ime, data modification operations (such as INSERT, UPDATE, DELETE) will become slow, as every time data changes in the table, all the indexes need to be updated. Another disadvantage is that, indexes need disk space, the more indexes you have, more disk space is used.
18
What is RAID and what are different types of RAID configurations?
A
RAID stands for Redundant Array of Inexpensive Disks, used to provide fault tolerance to database servers. There are six RAID levels 0 through 5 offering different levels of performance, fault tolerance.
19
What are the steps you will take, if you are tasked with securing an SQL Server?
A
Preferring NT authentication, using server, databse and application roles to control access to the data, securing the physical database files using NTFS permissions, using an unguessable SA password, restricting physical access to the SQL Server, renaming the Administrator account on the SQL Server computer, disabling the Guest account, enabling auditing, using multiprotocol encryption, setting up SSL, setting up firewalls, isolating SQL Server from the web server etc.
20
What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
A
Deadlock is a situation when two processes, each having a lock on one piece of data, attempt to acquire a lock on the other's piece. Each process would wait indefinitely for the other to release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user's process. A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely.
21
What is blocking and how would you troubleshoot it?
A
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.
22
How to restart SQL Server in single user mode?
A
SQL Server can be started from command line, using the SQLSERVR.EXE. This EXE has some very important parameters with which a DBA should be familiar with. -m is used for starting SQL Server in single user mode and -f is used to start the SQL Server in minimal confuguration mode.
23
what are the DBCC commands that you commonly use for database maintenance?
A
DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.
24
What are statistics?
A
Statistics determine the selectivity of the indexes. If an indexed column has unique values then the selectivity of that index is more, as opposed to an index with non-unique values. Query optimizer uses these indexes in determining whether to choose an index or not while executing a query.
25
Under what circumstances they go out of date, how do you update statistics?
A
Some situations under which you should update statistics: 1) If there is significant change in the key values in the index 2) If a large amount of data in an indexed column has been added, changed, or removed (that is, if the distribution of key values has changed), or the table has been truncated using the TRUNCATE TABLE statement and then repopulated 3) Database is upgraded from a previous version Look up SQL Server books online for the following commands: UPDATE STATISTICS, STATS_DATE, DBCC SHOW_STATISTICS, CREATE STATISTICS, DROP STATISTICS, sp_autostats, sp_createstats, sp_updatestats
26
What are the different ways of moving data/databases between servers and databases in SQL Server?
A
BACKUP/RESTORE, dettaching and attaching databases, replication, DTS, BCP, logshipping, INSERT...SELECT, SELECT...INTO, creating INSERT scripts to generate data.
27
Explian different types of BACKUPs avaialabe in SQL Server?
A
Full database backup, differential database backup, transaction log backup, filegroup backup.
28
What is database replicaion?
A
Replication is the process of copying/moving data between databases on the same or different servers.
29
What are the different types of replication you can set up in SQL Server?
A
SQL Server supports the following types of replication scenarios: * Snapshot replication * Transactional replication (with immediate updating subscribers, with queued updating subscribers) * Merge replication
30
How to determine the service pack currently installed on SQL Server?
A
The global variable @@Version stores the build number of the sqlservr.exe, which is used to determine the service pack installed.
31
What are cursors?
A
Cursors allow row-by-row prcessing of the resultsets.
32
Explain different types of cursors.
A
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven.
33
What are the disadvantages of cursors?
A
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.
34
How can you avoid cursors?
A
Most of the times, set based operations can be used instead of cursors. Another situation in which developers tend to use cursors: You need to call a stored procedure when a column in a particular row meets certain condition. You don't have to use cursors for this. This can be achieved using WHILE loop, as long as there is a unique key to identify each row.
35
What is a join?
A
Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
36
Explain different types of joins.
A
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
37
Can you have a nested transaction?
A
Yes, very much.
38
What is an extended stored procedure?
A
An extended stored procedure is a function within a DLL (written in a programming language like C, C++ using Open Data Services (ODS) API) that can be called from T-SQL, just the way we call normal stored procedures using the EXEC statement.
39
Can you instantiate a COM object by using T-SQL?
A
Yes, you can instantiate a COM (written in languages like VB, VC++) object from T-SQL by using sp_OACreate stored procedure.
40
What is the system function to get the current user's user id?
A
USER_ID(). Some more system functions: USER_NAME(), SYSTEM_USER, SESSION_USER, CURRENT_USER, USER, SUSER_SID(), HOST_NAME().
41
What are triggers?
A
Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table.
42
How many triggers you can have on a table?
A
In SQL Server 6.5 you could define only 3 triggers per table, one for INSERT, one for UPDATE and one for DELETE. From SQL Server 7.0 onwards, this restriction is gone, and you could create multiple triggers per each action.
43
How to invoke a trigger on demand?
A
In SQL Server 7.0 there's no way to control the order in which the triggers fire. In SQL Server 2000 you could specify which trigger fires first or fires last using sp_settriggerorder Triggers can't be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.
44
What are the uses of Triggers?
A
Triggers are generally used to implement business rules, auditing. Triggers can also be used to extend the referential integrity checks, but wherever possible, use constraints for this purpose, instead of triggers, as constraints are much faster. Till SQL Server 7.0, triggers fire only after the data modification operation happens. So in a way, they are called post triggers. But in SQL Server 2000 you could create pre triggers also. Search SQL Server 2000 books online for INSTEAD OF triggers.
45
What is a self join? Explain it with an example.
A
Self join is just like any other join, except that two instances of the same table will be joined in the query. Here is an example: Employees table which contains rows for normal employees as well as managers. So, to find out the managers of all the employees, you need a self join.
46
What is normalization?
A
The Process of organizing relational data into tables is actually referred to as normalization.
47
What is a Stored Procedure?
A
Its nothing but a set of T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements.
48
Can you give an example of Stored Procedure?
A
sp_helpdb , sp_who2, sp_renamedb are a set of system defined stored procedures. We can also have user defined stored procedures which can be called in similar way.
49
What is the basic difference between clustered and a non-clustered index?
A
The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db.
50
When do we use the UPDATE_STATISTICS command?
A
This command is basically used when we do a large processing of data. If we do a large amount of deletions any modification or Bulk Copy into the tables, we need to basically update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
What is denormalization and when would you go for it?
A
As the name indicates, denormalization is the reverse process of normalization. It's the controlled introduction of redundancy in to the database design. It helps improve the query performance as the number of joins could be reduced.
2
How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables?
A
One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships. One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships. Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.
3
What's the difference between a primary key and a unique key?
A
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.
4
What are user defined datatypes and when you should go for them?
A
User defined datatypes let you extend the base SQL Server datatypes by providing a descriptive name, and format to the database. Take for example, in your database, there is a column called ZIP_Code which appears in many tables. In all these tables it should be varchar(6).
In this case you could create a user defined datatype called ZIP_Code_Type of varchar(6) and use it across all your tables.
5
What is bit datatype and what's the information that can be stored inside a bit column?
A
Bit datatype is used to store boolean information like 1 or 0 (true or false). Untill SQL Server 6.5 bit datatype could hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit datatype can represent a third state, which is NULL.
6
Define candidate key, alternate key, composite key.
A
A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table. If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys. A key formed by combining at least two or more columns is called composite key.
7
What are defaults? Is there a column to which a default can't be bound?
A
A default is a value that will be used by a column, if no value is supplied to that column while inserting data. IDENTITY columns and timestamp columns can't have defaults bound to them. See CREATE DEFUALT in books online.
8
What is a transaction and what are ACID properties?
A
A transaction is a logical unit of work in which, all the steps must be performed or none. ACID stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a transaction. For more information and explanation of these properties, see SQL Server books online or any RDBMS fundamentals text book.
9
Explain different isolation levels An isolation level determines the degree of isolation of data between concurrent transactions.
A
The default SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read, Serializable.
10
How does .NET and SQL SERVER thread is work?
A
There are two types of threading pre-emptive and Non-preemptive but Sql Server support Non-preemptive and .NET thread model is different. Because Sql have to handle thread in different way for SQLCLR this different thread are known as Tasking of Threads . In this thread there is a switch between SQLCLR and SQL SERVER threads .SQL SERVER uses blocking points for transition to happen between SQLCLR and SQL SERVER threads.
11
What's the maximum size of a row?
A
8060 bytes.
12
What is lock escalation?
A
Strong names are required to store shared assemblies in the global assembly cache (GAC). This is because the GAC allows multiple versions of the same assembly to reside on your system simultaneously, so that each application can find and use its own version of your assembly. This helps avoid DLL Hell, where applications that may be compiled to different versions of your assembly could potentially break because they are all forced to use the same version of your assembly.
Another reason to use strong names is to make it difficult for hackers to spoof your assembly, in other words, replace or inject your assembly with a virus or malicious code.
13
What's the difference between DELETE TABLE and TRUNCATE TABLE commands?
A
DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
14
What are constraints? Explain different types of constraints.
A
Constraints enable the RDBMS enforce the integrity of the database automatically, without needing you to create triggers, rule or defaults. Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY
15
Whar is an index?
A
Indexes in SQL Server are similar to the indexes in books. They help SQL Server retrieve the data quicker.
16
What are the types of indexes?
A
Indexes are of two types. Clustered indexes and non-clustered indexes. When you craete a clustered index on a table, all the rows in the table are stored in the order of the clustered index key. So, there can be only one clustered index per table. Non-clustered indexes have their own storage separate from the table data storage. Non-clustered indexes are stored as B-tree structures (so do clustered indexes), with the leaf level nodes having the index key and it's row locater. The row located could be the RID or the Clustered index key, depending up on the absence or presence of clustered index on the table.
17
I create a separate index on each column of a table. what are the advantages and disadvantages of this approach?
A
If you create an index on each column of a table, it improves the query performance, as the query optimizer can choose from all the existing indexes to come up with an efficient execution plan. At the same t ime, data modification operations (such as INSERT, UPDATE, DELETE) will become slow, as every time data changes in the table, all the indexes need to be updated. Another disadvantage is that, indexes need disk space, the more indexes you have, more disk space is used.
18
What is RAID and what are different types of RAID configurations?
A
RAID stands for Redundant Array of Inexpensive Disks, used to provide fault tolerance to database servers. There are six RAID levels 0 through 5 offering different levels of performance, fault tolerance.
19
What are the steps you will take, if you are tasked with securing an SQL Server?
A
Preferring NT authentication, using server, databse and application roles to control access to the data, securing the physical database files using NTFS permissions, using an unguessable SA password, restricting physical access to the SQL Server, renaming the Administrator account on the SQL Server computer, disabling the Guest account, enabling auditing, using multiprotocol encryption, setting up SSL, setting up firewalls, isolating SQL Server from the web server etc.
20
What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
A
Deadlock is a situation when two processes, each having a lock on one piece of data, attempt to acquire a lock on the other's piece. Each process would wait indefinitely for the other to release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user's process. A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely.
21
What is blocking and how would you troubleshoot it?
A
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.
22
How to restart SQL Server in single user mode?
A
SQL Server can be started from command line, using the SQLSERVR.EXE. This EXE has some very important parameters with which a DBA should be familiar with. -m is used for starting SQL Server in single user mode and -f is used to start the SQL Server in minimal confuguration mode.
23
what are the DBCC commands that you commonly use for database maintenance?
A
DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.
24
What are statistics?
A
Statistics determine the selectivity of the indexes. If an indexed column has unique values then the selectivity of that index is more, as opposed to an index with non-unique values. Query optimizer uses these indexes in determining whether to choose an index or not while executing a query.
25
Under what circumstances they go out of date, how do you update statistics?
A
Some situations under which you should update statistics: 1) If there is significant change in the key values in the index 2) If a large amount of data in an indexed column has been added, changed, or removed (that is, if the distribution of key values has changed), or the table has been truncated using the TRUNCATE TABLE statement and then repopulated 3) Database is upgraded from a previous version Look up SQL Server books online for the following commands: UPDATE STATISTICS, STATS_DATE, DBCC SHOW_STATISTICS, CREATE STATISTICS, DROP STATISTICS, sp_autostats, sp_createstats, sp_updatestats
26
What are the different ways of moving data/databases between servers and databases in SQL Server?
A
BACKUP/RESTORE, dettaching and attaching databases, replication, DTS, BCP, logshipping, INSERT...SELECT, SELECT...INTO, creating INSERT scripts to generate data.
27
Explian different types of BACKUPs avaialabe in SQL Server?
A
Full database backup, differential database backup, transaction log backup, filegroup backup.
28
What is database replicaion?
A
Replication is the process of copying/moving data between databases on the same or different servers.
29
What are the different types of replication you can set up in SQL Server?
A
SQL Server supports the following types of replication scenarios: * Snapshot replication * Transactional replication (with immediate updating subscribers, with queued updating subscribers) * Merge replication
30
How to determine the service pack currently installed on SQL Server?
A
The global variable @@Version stores the build number of the sqlservr.exe, which is used to determine the service pack installed.
31
What are cursors?
A
Cursors allow row-by-row prcessing of the resultsets.
32
Explain different types of cursors.
A
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven.
33
What are the disadvantages of cursors?
A
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.
34
How can you avoid cursors?
A
Most of the times, set based operations can be used instead of cursors. Another situation in which developers tend to use cursors: You need to call a stored procedure when a column in a particular row meets certain condition. You don't have to use cursors for this. This can be achieved using WHILE loop, as long as there is a unique key to identify each row.
35
What is a join?
A
Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
36
Explain different types of joins.
A
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
37
Can you have a nested transaction?
A
Yes, very much.
38
What is an extended stored procedure?
A
An extended stored procedure is a function within a DLL (written in a programming language like C, C++ using Open Data Services (ODS) API) that can be called from T-SQL, just the way we call normal stored procedures using the EXEC statement.
39
Can you instantiate a COM object by using T-SQL?
A
Yes, you can instantiate a COM (written in languages like VB, VC++) object from T-SQL by using sp_OACreate stored procedure.
40
What is the system function to get the current user's user id?
A
USER_ID(). Some more system functions: USER_NAME(), SYSTEM_USER, SESSION_USER, CURRENT_USER, USER, SUSER_SID(), HOST_NAME().
41
What are triggers?
A
Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table.
42
How many triggers you can have on a table?
A
In SQL Server 6.5 you could define only 3 triggers per table, one for INSERT, one for UPDATE and one for DELETE. From SQL Server 7.0 onwards, this restriction is gone, and you could create multiple triggers per each action.
43
How to invoke a trigger on demand?
A
In SQL Server 7.0 there's no way to control the order in which the triggers fire. In SQL Server 2000 you could specify which trigger fires first or fires last using sp_settriggerorder Triggers can't be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.
44
What are the uses of Triggers?
A
Triggers are generally used to implement business rules, auditing. Triggers can also be used to extend the referential integrity checks, but wherever possible, use constraints for this purpose, instead of triggers, as constraints are much faster. Till SQL Server 7.0, triggers fire only after the data modification operation happens. So in a way, they are called post triggers. But in SQL Server 2000 you could create pre triggers also. Search SQL Server 2000 books online for INSTEAD OF triggers.
45
What is a self join? Explain it with an example.
A
Self join is just like any other join, except that two instances of the same table will be joined in the query. Here is an example: Employees table which contains rows for normal employees as well as managers. So, to find out the managers of all the employees, you need a self join.
46
What is normalization?
A
The Process of organizing relational data into tables is actually referred to as normalization.
47
What is a Stored Procedure?
A
Its nothing but a set of T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements.
48
Can you give an example of Stored Procedure?
A
sp_helpdb , sp_who2, sp_renamedb are a set of system defined stored procedures. We can also have user defined stored procedures which can be called in similar way.
49
What is the basic difference between clustered and a non-clustered index?
A
The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db.
50
When do we use the UPDATE_STATISTICS command?
A
This command is basically used when we do a large processing of data. If we do a large amount of deletions any modification or Bulk Copy into the tables, we need to basically update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
51
Which TCP/IP port does SQL Server run on?
A
SQL Server runs on port 1433 but we can also change it for better security.
52
From where can you change the default port?
A
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
53
Can we use Truncate command on a table which is referenced by FOREIGN KEY?
A
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity.
54
What is the use of DBCC commands?
A
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.
55
What command do we use to rename a db?
A
sp_renamedb ‘oldname’ , ‘newname’
56
Sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases?
A
In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.
57
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
A
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
58
What do you mean by COLLATION?
A
Collation is basically the sort order. There are three types of sort order Dictionary case sensitive, Dictonary - case insensitive and Binary.
59
When do you use SQL Profiler?
A
SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc..
60
What is a Linked Server?
A
Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.
61
Can you link only other SQL Servers or any database servers such as Oracle?
A
We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group.
62
Which stored procedure will you be running to add a linked server?
A
sp_addlinkedserver, sp_addlinkedsrvlogin
63
What are the OS services that the SQL Server installation adds?
A
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
64
Can you explain the role of each service?
A
SQL SERVER - is for running the databases SQL AGENT - is for automation such as Jobs, DB Maintanance, Backups DTC - Is for linking and connecting to other SQL Servers
65
How do you troubleshoot SQL Server if its running very slow?
A
First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes
66
Due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?
A
First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection; Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues.
67
What are the authentication modes in SQL Server?
A
Windows mode and mixed mode (SQL & Windows).
68
Where do you think the users names and passwords will be stored in sql server?
A
They get stored in master db in the sysxlogins table.
69
What is log shipping? Can we do logshipping with SQL Server 7.0?
A
Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.
70
SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
A
For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db.
71
What is BCP? When do we use it?
A
BulkCopy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same.
72
What should we do to copy the tables, schema and views from one SQL Server to another?
A
We have to write some DTS packages for it.
Subscribe to:
Posts (Atom)