Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • To insert values to identity column in SQL Server

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 288
    Comment on it

    Identity field is usually used as a primary key. When you insert a new record into your table, this field automatically assign an incremented value from the previous entry.


         Ex:
            CREATE TABLE Customer
            (
             ID int IDENTITY,
             Name varchar(100),
             Address varchar(200)
            )
    
    INSERT INTO Customer(ID,Name,Address) VALUES(1,'Shakham','Delhi')
    


    This will return an errror message that you cannot insert values into identity column .

    Disallow insert into identity field


        SET IDENTITYINSERT Customer ON
    
    
    INSERT INTO Customer(ID,Name,Address) VALUES(3,'Himanshu','Dehradun')
    INSERT INTO Customer(ID,Name,Address) VALUES(4,'Suresh','Noida')
    
    SET IDENTITYINSERT Customer OFF
    
    INSERT INTO Customer(Name,Address) VALUES('Sumit,'Noida')
    
    SQL Server

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: