How to use sqlcmd to create a database

佐手、 提交于 2019-11-30 11:59:12

Use @Jeremiah Peschka's answer to supply the sqlcmd utility with the script to execute.

As for the location for the newly created database, it can be specified as part of the CREATE DATABASE command:

CREATE DATABASE dbName
ON (
  NAME = dbName_dat,
  FILENAME = 'D:\path\to\dbName.mdf'
)
LOG ON (
  NAME = dbName_log,
  FILENAME = 'D:\path\to\dbName.ldf'
)

As you can see from the linked article, you can specify other properties as well, like initial size, maximum size etc.

sqlcmd -i C:\path\to\file.sql

More options can be found in SQL Server books online.

Badar

This is very simple. Just enter following command to run sqlcmd:
sqlcmd -U sa -P password
Then enter:

CREATE DATABASE MYDB
GO

This will create the db. Then enter "quit" to exit.

use this: sqlcmd -i "c:\my scripts\my script.sql"

see sqlcmd description at MS for other options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!