Batch create databases

Source: Internet
Author: User
With PowerShell, we can easily create databases in batches. The following describes in detail: for example, if we want to create three databases at a time, their names are DB1, DB2, DB3, we can create a text file, for example, the file name is DBs, And the content is the list of database names to be created: Next, we can use the following cm

With PowerShell, we can easily create databases in batches. The following describes in detail: for example, if we want to create three databases at a time, their names are DB1, DB2, DB3, we can create a text file, for example, the file name is DBs, And the content is the list of database names to be created: Next, we can use the following cm

With PowerShell, you can easily create databases in batches. The following describes in detail:

For example, if we want to create three databases at a time, whose names are DB1, DB2, and DB3, we can create a text file. For example, the file name is DBs, the content is a list of database names to be created:

Next, we can use the following cmdlet to achieve our goal:

$ List = get-content D: \ DBs.txt echo $ list | ForEach-Object {Invoke-SqlCmd-Query "create database $ _"}


After the execution, refresh the SSMS database. The three databases have been created. OK:

For the context warning of the above provider, we can use-SuppressProviderContextWarning to disable the warning information (the following command ), you can also use the-IgnoreProviderContext parameter to notify Invoke-Sqlcmd to always use the default database of the Logon account.

$ List | ForEach-Object {Invoke-SqlCmd-Query "create database $ _"-SuppressProviderContextWarning}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.