Running queries with OSQL.EXE
Sometimes we can run SQL queries with a tool called OSQL.EXE . This is available in the below path by default based on SQL Server version.
D:\Program Files\Microsoft SQL Server\140\Tools\Binn\OSQL.exe.
See the below image.
By using the OSQL tool I have a run a SELECT query.
-S ServerName or InstanceName
-i Path in which I saved the .SQL query which contains SELECT command. And I saved it in a folder of a drive.
-E Windows Authentication
-U SQL Authentication.
-P Password need to be provided if you choose SQL Authentication(-U). Below case I have chosen Windows Authentication
And my select query looks below. And I save this to AdventureWorks2012 folder of D drive.
USE AdventureWorks2012
GO
SELECT top 10 * FROM [HumanResources].[Department]
Go to Run-->Cmd--> and here is the query and double quotes("") are compulsory
Comments