SQL Server Performance

My Sql Problem

Discussion in 'General Developer Questions' started by Siona, Mar 2, 2009.

  1. Siona New Member

    Dear Friends, I have a Table with one Identity column. I want to insert few records.I want to make off identity and after inserting identity should on in my table.How can I achieve it?Cheers!
  2. FrankKalis Moderator

    Welcome to the forum!
    Have a look at SET IDENTITY_INSERT ON/OFF in Books Online.
  3. Sandy New Member

    SEEONA, See this.....-- Create #products table.CREATE
    TABLE #products (id int IDENTITY PRIMARY KEY, product varchar(40))GO-- Inserting values into #products table.INSERT
    INTO #products (product) VALUES ('aaa')INSERT
    INTO #products (product) VALUES ('bbb')INSERT
    INTO #products (product) VALUES ('ccc')INSERT
    INTO #products (product) VALUES ('ddd')GO-- Create a gap in the identity values.DELETE
    #products WHERE product = 'ccc'GOSELECT
    * FROM #products
    GO-- Attempt to insert an explicit ID value of 3;
    -- should return a warning.INSERT
    INTO #products (id, product) VALUES(3, 'ccc')GO-- SET IDENTITY_INSERT to ON.SET
    IDENTITY_INSERT #products ONGO-- Attempt to insert an explicit ID value of 3INSERT
    INTO #products (id, product) VALUES(3, 'ccc').GOSELECT
    * FROM #products
    GO-- Drop #products table.DROP TABLE #products
  4. Siona New Member

    Sandy,It’s really helpful for me... A Hearty Thanks Sandy...
    Frank thanks to you 2...Cheers! Seeona.
  5. Sandy New Member

    Seeona, you are always welcome to ask anything related to SQL...
    I accepted your thanks...Seeona
    Thank You...

Share This Page