European Windows 2019 Hosting BLOG

BLOG about Windows 2019 Hosting and SQL 2019 Hosting - Dedicated to European Windows Hosting Customer

SQL Server 2016 Hosting - HostForLIFE.eu :: Identity Column In SQL Server

clock October 23, 2018 11:42 by author Peter
In this article, we will learn about identity function and how we reset identity columns in SQL Server. Identity keyword is used in SQL Server to auto increment column value.
Identity is a function which can be used to generate unique id values of a particular column automatically. It can be applied on integer datatype column only. A table should contain only one identity column.

Syntax
identity(seed,increment)
Default value of identity is identity (1,1)

The seed represents the starting value of an ID and the default value of seed is 1.

Increment: It will represent the incremental value of the ID and the default value of increment is 1.

Example

Create table student(Id int Primary key Identity ,Name varchar(50),City varchar(50),TotalNumer int)  
insert into student(Name,City,TotalNumer) values('A','Delhi',120)  
insert into student(Name,City,TotalNumer) values('B','Noida',110)  
insert into student(Name,City,TotalNumer) values('C','Gurgaon',125)  
select * from student  

Check the table, ID value is increased automatically. The default value of identity is the identity (1,1) ID column starts with 1 and increased by 1.

Example
User defined seed and incremental values,

create table tec(Id int identity(10,5),Deptname varchar(50))  
insert tec values('Dot Net')  
insert tec values('SQL')  
select * from tec 

Id value starts by 10 and increases by 5.

Note
If we want to insert the values into an identity column explicitly then we should follow the syntax.

Set identity_insert <Table name> off/on

Off-It is a default connection; we cannot insert a value into an identity column explicitly.

On-we can insert the values into an identity column explicitly. 

Reset Identity Column
Syntax
dbcc checkident('table name',reseed,0)
 
We can reseed identity column value using the DBCC CHECKIDENT command of SQL. Using this command we can reset identity column values,
dbcc checkident('student',reseed,0)

In this article, we have learned about identity column in SQL Server and how we can reset identity column values.

HostForLIFE.eu SQL Server 2016 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.



SQL Server 2016 Hosting - HostForLIFE.eu :: Resolving The "Wait Operation Timed Out" Error When TFS Stops Working

clock October 17, 2018 11:48 by author Peter

Today, I will share one more interesting issue. A few days ago, our system administrator installed the Microsoft Test Manager 2012 on Microsoft Team Foundation Server 2010 (TFS 2010). Suddenly, our TFS stopped working. TFS was not able to extract the data from the database. Then I checked the error in the Event Viewer and found the error as below.

I did confirm that all the services inside the SQL Server were working fine. It became very difficult to find out the cause of this error because in our environment, SharePoint Server also existed and it was using the same SQL Server and working fine. After searching a lot about it on the internet, I found somewhere that the people got the same error after installing the Visual Studio 2011 and Visual Studio 2012.
 
Finally, I got the solution. I removed “.NET FrameWork 4.5″ from the system and reinstalled the ”.NET FrameWork 4.0". Then, our TFS Server went up again and started running fine. But it wasted a lot of time to find this solution, so, I am posting this it here to help people. However, I would advise you to be careful before making any changes or installing something new on the running server.

HostForLIFE.eu SQL Server 2016 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.



SQL Server 2016 Hosting - HostForLIFE.eu :: How To Use TRY CATCH In SQL Procedure?

clock October 10, 2018 11:18 by author Peter

In this post, we will learn how to use TRY CATCH in SQL procedure and store an error with error text. Here is a simple example for generating the error and storing it in a SQL table. Let's start coding. For saving the error in the table first we need to create the table in SQL Database. See below.
    CREATE TABLE [dbo].[Error_StoreProcedure]( 
        [ID] [bigint] IDENTITY(1,1) NOT NULL, 
        [ErrorNumber] [varchar](50) NULL, 
        [ErrorSeverity] [varchar](50) NULL, 
        [ErrorState] [varchar](50) NULL, 
        [ErrorProcedure] [varchar](500) NULL, 
        [ErrorLine] [varchar](50) NULL, 
        [ErrorMessage] [varchar](max) NULL, 
        [EntryDate] [datetime] NULL, 
     CONSTRAINT [PK_Error_StoreProcedure] PRIMARY KEY CLUSTERED  
    ( 
        [ID] ASC 
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 
    GO

After creating the above table we need to create one procedure for saving the error in the table;  see below.
 CREATE PROCEDURE usp_GetErrorInfo   
    AS   
    BEGIN 
        INSERT INTO Error_StoreProcedure SELECT   
        ERROR_NUMBER() AS ErrorNumber   
        ,ERROR_SEVERITY() AS ErrorSeverity   
        ,ERROR_STATE() AS ErrorState   
        ,ERROR_PROCEDURE() AS ErrorProcedure   
        ,ERROR_LINE() AS ErrorLine   
        ,ERROR_MESSAGE() AS ErrorMessage 
        ,dbo.GetDateTimeZone()   
    END


After creating the above procedure now we have to use the above procedure inside the other procedure.
    CREATE PROCEDURE TESTING_ERROR_PROCEDURE 
      
    AS 
    BEGIN 
     SET NOCOUNT ON; 
     
        BEGIN TRY   
             
            -- Generate divide-by-zero error.   
            SELECT 1/0;   
         
        END TRY   
        BEGIN CATCH   
             
            -- Execute error retrieval routine.   
            EXECUTE usp_GetErrorInfo;   
         
        END CATCH;    
     
    END 
    GO


The above procedure generates the error and goes to the CATCH part and saves all information of the error into our error table.
Run this query SELECT * FROM Error_StoreProcedure

See the output of the above table. Output displays procedure name and line number of the error.

European SQL 2016 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in