MS SQL import SQL file

兩種從MSSQL執行外部檔案的方式:

1. Execute file from SQL Tool
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
EXEC master..xp_cmdshell  'c:\Scripts\create_db.sql'

2. Execute file from CMD Tool
SQLCMD -E -d master -i c:\Scripts\create_db.sql