Scripting create Database (SQL Server)

We have a script to generate create db but for one of the databases , It seems to add ALTER

DATABASE ADD FILEGROUP for one db but not other..

Final text looks like this.. Could it be a option ? If it is which one is it?

/****** Object:  Database [APIDW]    Script Date: 06/30/2015 10:34:05 ******/
CREATE DATABASE [xx] ON  PRIMARY 
( NAME = xxx', FILENAME = N'Mxx.mdf' , SIZE = 17117184KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1048576KB ), 
( NAME = N'xxx'...

ALTER DATABASE xx ADD FILEGROUOP A; ---DON'T NEED THIS

ALTER DATABASE xx ADD FILEGROUOP B; ---DON'T NEED THIS
;

CREATE DATABASE [YY] ON  PRIMARY 
( NAME = xxx', FILENAME = N'Mxx.mdf' , SIZE = 17117184KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1048576KB ), 
( NAME = N'xxx'...

..
CREATE DATABASE [ZZ]

This script generates create db statements for all online user db

try { ... #Get a server object which corresponds to the default instance $srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server $Inst foreach($db in $srv.databases) { If($db.IsAccessible -and !$db.IsSystemObject -and !$db.IsDatabaseSnapshot) { If($db.name -ne "DBADB") { $db.name $db.script() | out-file $OutFile -append } } } $file = New-Object System.IO.StreamReader -Arg $OutFile $file.Close(); } catch { ExitProg $false $error[0] }





  • Edited by SQL_Jay Tuesday, June 30, 2015 3:17 PM
June 30th, 2015 3:16pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics