david-zed
david-zed

Reputation: 21

SQL Server tables in wrong database

I am new to SQL Server and have a strange problem, I have created a database named zed and a user zed which is mapped to the zed database but when I try to create the tables from a script :

sqlcmd -S DESKTOP-TEDE7TP\SQLEXPRESS -U zed -P zedfinancials -i ../tables/static_tables.sql

The tables are created in the master database.

Upvotes: 1

Views: 466

Answers (2)

Morten
Morten

Reputation: 414

Try these 2 lines in the beginning of your script file (static_tables.sql):

USE [Zed]
GO

This will force the script to use the database specified.

Upvotes: 1

Fourat
Fourat

Reputation: 2447

You are missing the -d flag to set the database :

sqlcmd -S DESKTOP-TEDE7TP\SQLEXPRESS -U zed -P zedfinancials -d zed -i ../tables/static_tables.sql

Read more about sqlcmd : https://learn.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-2017

Upvotes: 5

Related Questions