Home  • Database • Microsoft SQL Server

Import MSSQL Database with sqlcmd

Import sql script file
>sqlcmd -S localhost -d IERP_TEST  -i E:\db_file.sql
Note: not forward slash must be use backslash
To see tables in a database
>qlcmd -S localhost
USE your_database
go
SELECT  * FROM IERP_FASTMED.INFORMATION_SCHEMA.TABLES;
GO
go
If you need to select database
>sqlcmd -S localhost -d IERP_FASEMED -i e:ile.sql
Copy table with structure from one database to another database
select * into IERP_IBO_HR_DB_POLICE.dbo.hr_person_photo from IERP_IBO_HR_POLICE.dbo.hr_person_photo
To see database list
>qlcmd -S localhost
select name from sys.databases
go
or
>qlcmd -S localhost
EXEC sp_databases
go
or
sqlcmd -S localhost -Q "sp_databases"
go
note: -E: Use a trusted connection ("Windows authentication"). Replace by -U username -P password for SQL Server authentication. -S SERVERINSTANCE: The instance of SQL Server to which to connect. If you don't know the name of your instance, you can use sqlcmd -L to get a list. -Q: The query to execute. The uppercase Q causes sqlcmd to exit after executing the query. ref: https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-use-utility?view=sql-server-ver16

Comments 0


Copyright © 2024. Powered by Intellect Software Ltd