반응형
-- 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 ('screwdriver')
INSERT INTO products (product) VALUES ('hammer')
INSERT INTO products (product) VALUES ('saw')
INSERT INTO products (product) VALUES ('shovel')
GO
-- Create a gap in the identity values.
DELETE products
WHERE product = 'saw'
GO
SELECT *
FROM products
GO
-- Attempt to insert an explicit ID value of 3;
-- should return a warning.
INSERT INTO products (id, product) VALUES(3, 'garden shovel')
GO
-- SET IDENTITY_INSERT to ON. <-- 이녀석이 on 이 되어야지만 실행이된다. 안그러면 에러가뜸
SET IDENTITY_INSERT products ON
GO
-- Attempt to insert an explicit ID value of 3
INSERT INTO products (id, product) VALUES(3, 'garden shovel')
GO
SELECT *
FROM products
GO
-- Drop products table.
DROP TABLE products
GO
CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))
GO
-- Inserting values into products table.
INSERT INTO products (product) VALUES ('screwdriver')
INSERT INTO products (product) VALUES ('hammer')
INSERT INTO products (product) VALUES ('saw')
INSERT INTO products (product) VALUES ('shovel')
GO
-- Create a gap in the identity values.
DELETE products
WHERE product = 'saw'
GO
SELECT *
FROM products
GO
-- Attempt to insert an explicit ID value of 3;
-- should return a warning.
INSERT INTO products (id, product) VALUES(3, 'garden shovel')
GO
-- SET IDENTITY_INSERT to ON. <-- 이녀석이 on 이 되어야지만 실행이된다. 안그러면 에러가뜸
SET IDENTITY_INSERT products ON
GO
-- Attempt to insert an explicit ID value of 3
INSERT INTO products (id, product) VALUES(3, 'garden shovel')
GO
SELECT *
FROM products
GO
-- Drop products table.
DROP TABLE products
GO
반응형
'=====-I T-===== > ▣SQL' 카테고리의 다른 글
[MS-SQL]float 형 varchar 로 변경하는법 (5) | 2011.06.03 |
---|---|
[SQL] 주소정보 DB에 입력하기 (0) | 2011.04.17 |
[SQL] 트랜젝션 로그 백업 내용 보기 (0) | 2010.10.22 |
[MS-SQL] Join 을 사용한 Update (0) | 2010.10.13 |
[SQL] 결합인덱스 컬럼순서 결정방법 (0) | 2010.10.10 |