>Volendo forzare invece un valore esplicito in una colonna con
>l'attributo IDENTITY :
>leggo dalla msdn
>
>-- should return a warning.
>INSERT INTO products (id, product) VALUES(3, 'garden shovel')
>GO
>-- SET IDENTITY_INSERT to ON.
>SET IDENTITY_INSERT products ON
>
>Quando inserisco SET IDENTITY_INSERT products ON nella query
>di inserimento
>mi restituisce un errore in sql express 2005:
>"Il costrutto o l'istruzione SQL Dichiara cursore non è supportato."
>
>Dipende dal fatto che uso sql Express 2005?
Ciao Giovanni,
non direi, l'errore che ricevi non riguarda il comando SET IDENTITY_INSERT.
Guarda il seguente esempio:
USE tempdb;
CREATE TABLE dbo.products(
id int NOT NULL IDENTITY PRIMARY KEY,
product varchar(20) NOT NULL
);
-- should return a warning.
INSERT INTO dbo.products (id, product) VALUES(3, 'garden shovel');
/* Output:
Server: Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column
in table 'products' when IDENTITY_INSERT is set to OFF.
*/
-- SET IDENTITY_INSERT to ON.
SET IDENTITY_INSERT dbo.products ON;
INSERT INTO dbo.products (id, product) VALUES(3, 'garden shovel');
/* Output:
(1 row(s) affected)
*/
SELECT *
FROM dbo.products;
/* Output:
id product
----------- --------------------
3 garden shovel
(1 row(s) affected)
*/
DROP TABLE dbo.products;
Ciao e Buon Natale
--
Lorenzo Benaglia
Microsoft MVP - SQL Server
http://blogs.dotnethell.it/lorenzo/
http://italy.mvps.org