< Back

New-DbaDatabase

Mon Jan 13, 2020 12:48 pm

NAME New-DbaDatabase



SYNOPSIS

Creates a new database





SYNTAX

New-DbaDatabase [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Name] <System.String[]>] [[-Collation] <String>] [[-Recoverymodel] <String>] [[-Owner]

<String>] [[-DataFilePath] <String>] [[-LogFilePath] <String>] [[-PrimaryFilesize] <Int>] [[-PrimaryFileGrowth]

<Int>] [[-PrimaryFileMaxSize] <Int>] [[-LogSize] <Int>] [[-LogGrowth] <Int>] [[-SecondaryFilesize] <Int>]

[[-SecondaryFileGrowth] <Int>] [[-SecondaryFileMaxSize] <Int>] [[-SecondaryFileCount] <Int>] [[-DefaultFileGroup]

<String>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

This command creates a new database.



It allows creation with multiple files, and sets all growth settings to be fixed size rather than percentage

growth.





PARAMETERS

-Collation [<String>]

The database collation, if not supplied the default server collation will be used.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DataFilePath [<String>]

The location that data files will be placed, otherwise the default SQL Server data path will be used.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DefaultFileGroup [<String>]

Sets the default file group. Either primary or secondary.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.

This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables

advanced scripting.

Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own

try/catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LogFilePath [<String>]

The location the log file will be placed, otherwise the default SQL Server log path will be used.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LogGrowth [<Int>]

The amount in MB that the log file will be set to autogrow by.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LogSize [<Int>]

The size in MB that the Transaction log will be created.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Name [<System.String[]>]

The name of the new database or databases to be created.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Owner [<String>]

The login that will be used as the database owner.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PrimaryFileGrowth [<Int>]

The size in MB that the Primary file will autogrow by.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PrimaryFileMaxSize [<Int>]

The maximum permitted size in MB for the Primary File. If this is less the primary file size for the model

database, then the model size will be used instead.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PrimaryFilesize [<Int>]

The size in MB for the Primary file. If this is less than the primary file size for the model database, then

the model size will be used instead.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Recoverymodel [<String>]

The recovery model for the database, if not supplied the recovery model from the model database will be used.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecondaryFileCount [<Int>]

The number of files to create in the Secondary filegroup for the database.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecondaryFileGrowth [<Int>]

The amount in MB that the Secondary files will be set to autogrow by. Use 0 for no growth allowed. Each file

added will be created with this growth setting.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecondaryFileMaxSize [<Int>]

The maximum permitted size in MB for the Secondary data files to grow to. Each file added will be created with

this max size setting.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecondaryFilesize [<Int>]

The size in MB of the files to be added to the Secondary filegroup. Each file added will be created with this

size setting.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).



Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -

Integrated are all supported.



For MFA support, please use Connect-DbaInstance.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Database

Author: Matthew Darwin (@evoDBA, naturalselectiondba.wordpress.com) | Chrissy LeMaire (@cl)



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>New-DbaDatabase -SqlInstance sql1



Creates a randomly named database (random-N) on instance sql1

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>New-DbaDatabase -SqlInstance sql1 -Name dbatools, dbachecks



Creates a database named dbatools and a database named dbachecks on sql1

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>New-DbaDatabase -SqlInstance sql1, sql2, sql3 -Name multidb, multidb2 -SecondaryFilesize 20

-SecondaryFileGrowth 20 -LogSize 20 -LogGrowth 20



Creates two databases, multidb and multidb2, on 3 instances (sql1, sql2 and sql3) and sets the secondary data file

size to 20MB, the file growth to 20MB and the log growth to 20MB for each

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>New-DbaDatabase -SqlInstance sql1 -Name nondefault -DataFilePath M:\\Data -LogFilePath 'L:\\Logs with spaces'

-SecondaryFileCount 2



Creates a database named nondefault and places data files in in the M:\\data directory and log files in "L:\\Logs

with spaces".



Creates a secondary group with 2 files in the Secondary filegroup.



RELATED LINKS

https://dbatools.io/New-DbaDatabase