Sql – Inserting more than 1000 rows from Excel into SQLServer

insertsqlsql serversql-server-2008

I'm new to Sql but what is the best way to insert more than 1000 rows from an excel document into my database(Sql server 2008.)

For example I'm using the below query:

   INSERT INTO mytable(companyid, category, sub, catalogueref)
   VALUES
   ('10197', 'cat', 'sub', '123'),
   ('10197', 'cat2', 'sub2', '124')

This is working fine but there is a limit of inserting 1000 records and I have 19000 records and I don't really want to do 19 separate insert statements and another question, is that the company id is always the same is there a better way then writing it 19000 times?

Best Answer

Just edit the data in Excel or another program to create N amount of insert statements with a single insert for each statement, you'll have an unlimited number of inserts. For example...

INSERT INTO table1 VALUES   (6696480,'McMurdo Station',-77.846,166.676,'Antarctica','McMurdo')
INSERT INTO table1  VALUES  (3833367,'Ushuaia',-54.8,-68.3,'America','Argentina')
...19,000 later
INSERT INTO table1 VALUES   (3838854,'Rio Grande',-53.78769,-67.70946,'America','Argentina')