Search This Blog

Wednesday, July 25, 2012

Bulk Insert Query in SQL 2008


                             
                                             
CREATE TABLE Department
(
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(30)
)
******************************************************************
CREATE TYPE DeptType AS TABLE
(
DeptId INT, DeptName VARCHAR(30)
);

******************************************************************
CREATE PROCEDURE InsertDepartment
@InsertDept_TVP DeptType READONLY
AS
INSERT INTO Department(DepartmentID,DepartmentName)
SELECT * FROM @InsertDept_TVP;

DECLARE @DepartmentTVP AS DeptType;

INSERT INTO @DepartmentTVP(DeptId,DeptName)
VALUES (11,'Accounts'),
(12,'Purchase'),
(13,'Software'),
(14,'Stores'),
(15,'Maarketing');
*******************************************************************
EXEC InsertDepartment @DepartmentTVP;

No comments :