SQL Server 2008 Import Data From File Using sqlcmd

SQL Server provides us convenient way to import large data from .sql file using sqlcmd tools. Sometimes we need to import data using .sql file when SQL Server version is different between source and target database.

Let’s say the file is named import_db.sql, produced by ‘Generate Scripts’ feature in SQL Server Management Studio.

Import import_db.sql to destined database is very simple using sqlcmd tools.

  1. open windows command prompt
  2. write sqlcmd -E -i import_db.sql
  3. wait until sqlcmd finished execute the whole file

However, there is limitation using this method. Database name in ‘source database’ must be the same with database name in ‘target database’. Anyway we could handle this by manually edit import_db.sql.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.