Saturday, 31 March 2018

Windows Command Line Powershell CMD Bulk Copy Program SQL Imports And Exports



Windows CMD Powershell BCP SQL Imports and Exports

Windows BCP Export including field headers using union query from Microsoft SQL:

PS C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft SQL Server Tools 17> bcp "select 'Product','Low','High','Close','Previous','Direction','Date'  union all  select * from  test.
dbo.optionsonfxmajorsii" queryout optionsonfxmajorsiv.txt -T -c -SServerName\SQLEXPRESS -U"Username"

Windows BCP Import to Microsoft SQL skip first header row:

PS C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft SQL Server Tools 17> bcp "test.dbo.optionsonfxmajorsii" in optionsonfxmajorsiv.txt -T -c -F2 -SServername\SQLEXPRESS -U"Username"

Note:
-S = Server name without a space
-U = Username without a space.
-T = You trust the database you are connecting to.
-c = character text tab delimiter.
-F2 = import from second row.


No comments:

Post a Comment