Assuming:
- you have a .sql file you want to run,
- you have a username/password and all that.
Create a batch file.
- In file manager, right-click somewhere in the folder you want to put it in (like Documents\batch) and New->Text file.
- Edit the name that comes up and call it [something].bat
- Windows may warn you about renaming file extensions. Click OK.
- Right click the new file in file manager and Edit. It should open in notepad.
- Add this text, using your own server, username and password.
sqlcmd -S ".\SQLEXPRESS" -U myUserName -P myPassword -i %1 -d DBName >result.txt
start Notepad.exe result.txt
Save the file.
See that %1 in there? That means that the filename of any .sql file you drop onto this bat file's icon will get inserted and the query will run, dropping the results into a text file (>result.txt)
The bat file then opens notepad and shows the user the results.
...
Bryan Valencia is a contributing editor and founder of Visual Studio Journey. He owns and operates Software Services, a web design and hosting company in Manteca, California.
No comments:
Post a Comment