sql server - Bulk insert when using IDENTITY -
this table structure.
create table emp (empid int identity(101, 1), empname varchar(20), salary decimal(10,2), created_date datetime default(getdate()) );
now have records
'ramesh',10000 'arun',20000
in .txt
file.
i need bulk insert records table. please guide me write bulk insert query.
basically, first need staging table has structure exactly matches .txt
file:
create table emp_staging (empname varchar(20), salary decimal(10,2) );
then, bulk insert data .txt
file staging table , check:
bulk insert dbo.emp_staging 'd:\temp\emps.txt' ( fieldterminator =',', rowterminator ='\n' ); select * dbo.emp_staging
once that's done - can insert data staging table actual table using insert .. select ...
:
insert dbo.emp ( empname, salary ) select empname, salary dbo.emp_staging select * dbo.emp
Comments
Post a Comment