Home  • Database • Microsoft SQL Server

SQL Server cmd commands and examples

Connect to the SQL Server

Step 1 Open command prompt Step 2 Command as follows: C:UsersUserName>sqlcmd -S localhostsqlexpress Remote login C:UsersUserName>sqlcmd -S 28.147.169.237 -U sa -P password

Display all databases in the SQL Server

C:UsersUserName>select name from sys.databases C:UsersUserName>go

Delete a database from SQL Server

C:UsersUserName>sqlcmd -S localhostsqlexpress C:UsersUserName>drop database [DBName] C:UsersUserName>go Note: Here tris is a database name and sqlexpress is a default instance name. SQL Server keeps all databases in its instance.

Show all tables in a database

USE your_database
SELECT name FROM sys.tables

Describe table

exec sp_columns MyTable

Import sql file

sqlcmd -S localhostsqlexpress -i  E:mydb.sql 
sqlcmd -S localhost -i  E:mydb.sql 

Reference

sqlcmd-use-the-utility

Comments 7


Here tris is a database name
https://technet.microsoft.com/en-us/library/ms166559(v=sql.105).aspx
https://technet.microsoft.com/en-us/library/ms170572(v=sql.105).aspx
https://www.simple-talk.com/sql/sql-tools/sql-server-sqlcmd-basics/
thanko sir
win
Ahsan Habib
Email: rajuhabib0007@gmail.com
Joined: 13 May 2017

win
Haris Abdullah
Email: harissihab1992@gmail.com
Joined: 13 May 2017

Copyright © 2024. Powered by Intellect Software Ltd