Stored procedure
-
Hi, This is my stored prosecure.But when i execute exec CreateDataBases 'testdb','testdb','c:\\testdb.mdf','c:\\testdb.ldf' It says the db already exists?? Am confused plaease help me... -- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= Create PROCEDURE CreateDataBases -- Add the parameters for the stored procedure here ( @database nvarchar(100), @databaseName nvarchar(100), @mdfName nvarchar(100), @ldfName nvarchar(100) ) AS declare @qry nvarchar(800) BEGIN select @qry = 'CREATE DATABASE ' + @database + ' ON PRIMARY (NAME= ' + @databaseName +', FILENAME ='''+ @mdfName + ''', SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON (NAME ='+@databaseName+',FILENAME='''+ @ldfName+''',SIZE = 1MB, MAXSIZE = 5MB, FILEGROWTH = 10%)' --print @qry exec SP_Executesql @qry END GO exec CreateDataBases 'testdb','testdb','c:\\testdb.mdf','c:\\testdb.ldf'
-
Hi, This is my stored prosecure.But when i execute exec CreateDataBases 'testdb','testdb','c:\\testdb.mdf','c:\\testdb.ldf' It says the db already exists?? Am confused plaease help me... -- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= Create PROCEDURE CreateDataBases -- Add the parameters for the stored procedure here ( @database nvarchar(100), @databaseName nvarchar(100), @mdfName nvarchar(100), @ldfName nvarchar(100) ) AS declare @qry nvarchar(800) BEGIN select @qry = 'CREATE DATABASE ' + @database + ' ON PRIMARY (NAME= ' + @databaseName +', FILENAME ='''+ @mdfName + ''', SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON (NAME ='+@databaseName+',FILENAME='''+ @ldfName+''',SIZE = 1MB, MAXSIZE = 5MB, FILEGROWTH = 10%)' --print @qry exec SP_Executesql @qry END GO exec CreateDataBases 'testdb','testdb','c:\\testdb.mdf','c:\\testdb.ldf'
It probably means that there is already a "testdb" database on your server.
-
It probably means that there is already a "testdb" database on your server.
That's a pretty wild guess based on such an unclear error message... ;)
-
That's a pretty wild guess based on such an unclear error message... ;)
Yes,because there is no other by that name.Thats why i am so much lost. For example i am creating the same stored procedure in another comp.But still getting the same error.
-
Yes,because there is no other by that name.Thats why i am so much lost. For example i am creating the same stored procedure in another comp.But still getting the same error.
A database creation script is supposed to look like:
CREATE DATABASE [testdb] ON (NAME = N'testdb_Data', FILENAME = N'C:\testdb_Data.mdf', SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON (NAME = N'testdb_Log', FILENAME = N'C:\testdb_Log.ldf', SIZE = 5MB, MAXSIZE = 5MB, FILEGROWTH = 10%)
If uncomment your "print" statement you will find that you are giving the log the same name as the database. Regards Andy
-
A database creation script is supposed to look like:
CREATE DATABASE [testdb] ON (NAME = N'testdb_Data', FILENAME = N'C:\testdb_Data.mdf', SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON (NAME = N'testdb_Log', FILENAME = N'C:\testdb_Log.ldf', SIZE = 5MB, MAXSIZE = 5MB, FILEGROWTH = 10%)
If uncomment your "print" statement you will find that you are giving the log the same name as the database. Regards Andy