Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Tuesday, May 13, 2014

How to Connect SQL Server integration services using SSMS

When connecting to integration services I have faced the below error even though my windows login have admin permissions.




Cannot connect to MALLIREDDY.
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476
Connecting to the Integration Services service on the computer "MALLIREDDY" failed with the following error: "Access is denied."

By default, only administrators have access to the Integration Services service. On Windows Vista and later, the process must be running with administrative privileges in order to connect to the Integration Services service. See the help topic for information on how to configure access to the service.
For help, click: http://go.microsoft.com/fwlink/?LinkId=220763
Connecting to the Integration Services service on the computer "MALLIREDDY" failed with the following error: "Access is denied."
By default, only administrators have access to the Integration Services service. On Windows Vista and later, the process must be running with administrative privileges in order to connect to the Integration Services service. See the help topic for information on how to configure access to the service


For Connecting SQL Server Integration Services run the SQL Server Management studio as run as administrator. SSMS will connect integration service successfully.




Similarly in data tools some times for bulk data load the data tools must run as administrator.




Monday, May 12, 2014

Uninstall SQL Server 2014 instances


It’s easy to uninstall SQL Server instance  from control panel. Here I will show how to uninstall SQL Server 2014

Go to control panel or type the below command in run it will open the control panel.


Enter command appwiz.cpl





Then double click the Microsoft SQL Server 2014 setup. Clicks remove to uninstall the SQL server setup.




the instance to remove the instance from list of installed instances.





Then select features to remove. I have select SQL Server 2014 features for removing.

Shared features will be used by other instances. Shared features will be installed once and used by other instances.


Click on next ,Then click on remove to uninstall the features selected.


Wait until the installation shows completes.








Verify using SSMS whether instance uninstalled properly.


Alternatively you can verify the services using services.msc command

Install SQL Server 2014 step by step using screen shots

Last week I have downloaded SQL Server 2014 from Microsoft website. 
The download size is 2.09GB. I have downloaded .CAB version. Also it’s available in ISO download. The download is available two types of downloads 32 bit or 64 bit. SQL Server setup is available in different languages. I have downloaded English version which is commonly used in various countries.

I have 64 bit operating system so I downloaded the 64 bit file.

I installed it in my Laptop successfully.  I installed the SQL server 2014 as administrator.
These are my Laptop Configurations.

RAM: 4GB
System Type: 64 –bit Operating System
Operating System: Windows 7 Home basic Service Pack1
Processor: Intel(R) Core™ i5 CPU M480 @2.67GHZ 2.66GHZ
The prep requites for installing SQL Server 2014 is Previous version of SQL Server should not installed.

Also Visual Studio should not be installed in Laptop.
Once you have downloaded SQL Server 2014 from Microsoft website.


 Then Extract the .cab set up as shown below



Once the file extraction completed successfully it will launch the SQL Server Installation Center.



Go to installation tab.
I cannot install failover cluster as operating system does not support the installation of clustered node.
So I have selected the Stand alone installation




Once selected the New SQL Server Stand-alone installation it will open the SQL Server 2014 setup.

In order to install SQL Server setup should pass all the global rules. If any rule fails the setup will abort the installation.
The list of global rules is shown as below.



Once all rules passed will go to product updates tab. The setup will search for new updates if internet is connected to the system.
Ignore the error message shown here and click on next






If any updated is found in next step it will include the updates in the setup. 





Then next step is installation rules. if any of the given installation rules fails system will abort the SQL Server setup.  Some of the important prerequisites before installation is SQL Server 2008 Business Intelligence should not be installed. Prior to SQL Server 2012 BI tools is included in SQL Server setup.




From SQL Server 2012 onwards SQL server BI tools need to install separately called as SQL Server data tools.

 SQL Server 2014 CTP1 should not present in system. It’s better to uninstall previous versions of SQL server present in system.

Once installation rules passed next step is installation type




Installation Type allows you to install a new installation or add features to an existing instance.
Also it will display the existing installed instances

I have selected the perform new installation. Then next step is specifying the product version.





I selected the free edition (Evaluation edition and Expression editions available as free editions).
Evaluation edition contains all the features of SQL server but with 180 days expiration.
Then next step is accepting license terms




Next setup role provides an option to individually select which features components to install.
I have selected the SQL Server feature installation.





Features selection allows selecting the individual features for an instance. we can install only the components we required.  I have selected all the features.





Feature rules determine if the installation process will be blocked.



Specify the instance name in instance configuration tab. we can select either default instance or named instance. SQL Server allows only one default instance and up to 49 named instances.



If we select default instances then instance name will be MSSQLSever.

Server configuration allows specifying the service accounts and SQL server collation.



We can changes the SQL server collation using collation tab. By default SQL server uses the SQL_Latin1_General_CP__CI_AS collation.





Next step is Database Engine configuration. It will allow configuring the server security.





We can use mixed mode or windows authentication mode. Windows authentication provides more secure than SQL Server authentication. Specify at least one SQL Server administrator to have unrestricted access to SQL server.

Data directory tab allows configuring the database files configuration.


File stream tab allows enabling file stream for T-SQL access. File stream allows the database to store the blob files in File system. all files will be also part of database backup.


Next step Analysis Service configuration is similar to database configuration which allows to specify the security and data directories.


Reporting services configuration is used for configure the reporting services.




Next step feature configuration rules determine whether the installation process will succeeded or failed.



Next step is ready to install.



Then click on install .and verify the installation.


Wait until the installation completes as shown below.


SQL server 2014 installed successfully. for verify the installation Connect all the services to ensure all installed components are working properly.





Wednesday, April 23, 2014

Working with hierarchyid

The hierarchyid data type is variable length data type introduced in SQL Server 2008.

Create table with hierarchyid data type

declare @emp as table(id int,hierid hierarchyid,name varchar(100))

hierarchyid functions.

GetRoot() : GetRoot function is used for getting root level. we can use this function for inserting the data as level 0.

GetDescendant() : function accepts two parameters child1 and child2.

if both are null,null it is in first level.

GetLevel (): function is used for getting hierarchy level.

insert @emp
select 1,hierarchyid::GetRoot(),'malls'

declare @parentid hierarchyid
select @parentid=hierarchyid::GetRoot()

insert @emp
select 2,@parentid.GetDescendant(null,null),'redd'

--select hierid.ToString(),hierid.GetLevel() from @emp
select id,name,hierid.GetLevel() from @emp
--getroot(),GetDescendant,GetLevel,read,write

select id,name,hierid.GetLevel() from @emp
where hierid.GetLevel()=1




Wednesday, April 9, 2014

Improve query performance using index in SQLServer

Index Basics:
Clustered Index: clustered index will arrange the pages of table using clustered key. It will arrange the entire physical table either in ascending or descending order in the disk.
If there is no clustered index on a table then it is called as heap. By default when a row is inserted the row identifier will allocate 8 KB Space. For small table index and table scan will perform the same.

For larger table, the index seek will perform better than the table scan.
Clustered index leaf nodes contain data pages of those tables. It uses binary tree mechanism.
Only one clustered index can be created on a table. Clustered index can be created using 16 columns (maximum).

Non Clustered indexes can also be used for improving query performance.  Non- clustered index will store the information for only the columns used in indexes. The leaf node of non-clustered index stores the row identifier if there is no clustered index on the table else it will stores the clustered key. Row identifier stores the information about data pages. Page contains 8 KB. The sum of 8 pages can be called as extent.

As per books online you can create 999 non- clustered indices per table.

Indexes will help us to improve query performance. It will be mainly used for selecting the data.  I will show here how indexes will improve the query performance. The down side of indexes is it will allocate extra space in database. If Inserts, Updates and delete are more it will create blocking, fragmentation, page splits and deadlocks.

Covering index is a non-clustered that satisfies the selectivity of the query.
Filtered index is a non-clustered index with where clause.

IF we create a clustered index on a view with schembinding then that index is called as indexed view.

I have created the table EMP table with the following details.

create table emp (id int identity ,name varchar(200),Datejoined date default getdate()) .

Let us populate some test data.

insert into emp (name)
select (name) from sys.all_parameters
union all
select name from sys.all_objects
union all
select name from sys.all_columns
union all
select name from sys.indexes where name is not null
union all
select name from sys.databases
GO

Suppose we have a search condition to fetch emp table details based on id column as shown in below query.

select id,name,datejoined from emp where id = 1

In order verify the above query performance we can use the three set statistics statements.

set statistics io on|off
set statistics time on
set statistics xml on 

The above statistics statement is used for identifying IO requests like scan count, logical reads etc.
Scan count refers number of times the table scanned or index scanned.
Logical reads is used for fetching the data pages from memory

set statistics io on
set statistics time on
set statistics xml on
select id,name,datejoined from emp where id = 1
set statistics time off
set statistics xml off
set statistics io off


See the execution plan below






There is no clustered index on the table. So it is showing the table scan.

Execution statistics


SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 4 ms.
SQL Server parse and compile time:
   CPU time = 0 ms, elapsed time = 0 ms.

(1 row(s) affected)
Table 'emp'. Scan count 1, logical reads 4365, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

(1 row(s) affected)

 SQL Server Execution Times:
   CPU time = 16 ms,  elapsed time = 178 ms.


The above statistics shows that query optimizer scanned entire table. Logical reads are high.
Now we will create the clsutered index on emp table.
create unique clustered index  IXUC_emp_ID ON Emp (id)

Now verify the execution plan below






Now query optimizer is using clustered index seek.
Verify the statistics time and IO

 SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 0 ms.
SQL Server parse and compile time:
   CPU time = 0 ms, elapsed time = 1 ms.

(1 row(s) affected)
Table 'emp'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

(1 row(s) affected)

 SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 0 ms.

Now the query executed is 0 ms.  Only few logical reads required to fetch the data.
There is no table scan. Scan count is zero. So we have optimized the query using the clustered index.
But there is limitation to clustered index. We can create only one clustered index per table.
Suppose we have a query for fetching the employee details using the employee name.


set statistics io on
set statistics time on
set statistics xml on
select id,name,datejoined from emp where name = 'emp'
set statistics io off
set statistics time off
set statistics xml off

Execution statistics for the above query


 SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 0 ms.
SQL Server parse and compile time:
   CPU time = 0 ms, elapsed time = 15 ms.

(2 row(s) affected)
Table 'emp'. Scan count 1, logical reads 140, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

(1 row(s) affected)

 SQL Server Execution Times:
   CPU time = 15 ms,  elapsed time = 39 ms.

 SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 0 ms.

The above statistics shows that query optimizer used the clustered index to scan enitre. Because in where clause we have used name column but we have created the clustered index on ID column.

Scan count 1 means query optimizer scanned Clustered index one time.
Logical reads 140 means query optimizer used 140 data pages to fetch the data.


  Execution plan for the above query




       i.          Clustered index scan is almost equal to table scan.
      ii.          Optimizer will not choose the clustered index if the clustered key not exists in where clause of the query.
     iii.          In order improve query performance we can use the non-clustered index because we can create only one clustered index per table.

Create the non-clustered index using the below query

 create nonclustered index IXUNC_emp_name ON Emp (name)

 Now execute the same query and verify plan and the statistics





Now query for cost for index seeks is 28% and key lookup is 72 %. Even though we have created the non-clustered index on name column, we are retrieving two more columns id, datejoined in select clause of the query.  Non clustered index will store data of the non-clustered key columns. Non-clustered index leaf node contains the clustered key if clustered index exists on a table. So for fetching data about the two columns id,datejoined using non clustered index.

 DROP INDEX [IXUNC_emp_name] ON [dbo].[emp]
GO
CREATE NONCLUSTERED INDEX [IXUNC_emp_name] ON [dbo].[emp]
(
       [name] ASC
)
INCLUDE
(
id,
datejoined

)


  Execution plan for the above query

















Execution statistics for the above query

SQL Server Execution Times:
   CPU time = 0 ms, elapsed time = 0 ms.
SQL Server parses and compiles time:
   CPU time = 0 ms, elapsed time = 0 ms.

(1 row(s) affected)
Table 'emp'. Scan count 1, logical reads 3, and physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, and lob read-ahead reads 0.

(1 row(s) affected)

 SQL Server Execution Times:
   CPU time = 0 ms, elapsed time = 0 ms.

 SQL Server Execution Times:
   CPU time = 0 ms, elapsed time = 0 ms.




Using the above covering index we can improve the query performance.