Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Stored procedure

Stored procedure

Scheduled Pinned Locked Moved Database
databasesharepointhelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new2pgrmg
    wrote on last edited by
    #1

    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'

    A 1 Reply Last reply
    0
    • N new2pgrmg

      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'

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      It probably means that there is already a "testdb" database on your server.

      P 1 Reply Last reply
      0
      • A andyharman

        It probably means that there is already a "testdb" database on your server.

        P Offline
        P Offline
        Paddy Boyd
        wrote on last edited by
        #3

        That's a pretty wild guess based on such an unclear error message... ;)

        T 1 Reply Last reply
        0
        • P Paddy Boyd

          That's a pretty wild guess based on such an unclear error message... ;)

          T Offline
          T Offline
          Trustapple
          wrote on last edited by
          #4

          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 1 Reply Last reply
          0
          • T Trustapple

            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 Offline
            A Offline
            andyharman
            wrote on last edited by
            #5

            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

            N 1 Reply Last reply
            0
            • A andyharman

              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

              N Offline
              N Offline
              new2pgrmg
              wrote on last edited by
              #6

              Thanks Andy,I will check it out and keep you posted

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups