Hello,
I've been battling all day with this stored proc I tried to create. All I need it to do is create a table based on an arguement I pass it:
CREATE PROCEDURE [dbo].[sp_CreateUserLocalDB]
AS
SELECT 0
GO
--
-- Definition for stored procedure sp_CreateUserLocalDB :
--
ALTER PROCEDURE [dbo].[sp_CreateUserLocalDB]
@username varchar(255)
AS
CREATE DATABASE QUOTENAME(@username)
USE QUOTENAME(@username)
CREATE TABLE [dbo].[Actions] (
[actionid] int DEFAULT (0) NULL,
[marketingid] int DEFAULT (0) NULL,
[actionno] int DEFAULT (0) NULL,
[actiondate] datetime NULL,
[actiontypeid] int DEFAULT (-1) NULL,
[actiontypeidtext] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[replydate] datetime NULL,
[replyid] int DEFAULT (-1) NULL,
[replyidtext] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[addedby] int DEFAULT (0) NULL,
[lastedit] datetime NULL
)
ON [PRIMARY]
For starters, it doesnt like the first QUOTENAME(@username); It tells me that there is an error near @username?
Seconds, it reckons I cant use a USE statement in a SP; how do I get the SP to create the tables in the other database (not in master)
I've been battling all day with this stored proc I tried to create. All I need it to do is create a table based on an arguement I pass it:
CREATE PROCEDURE [dbo].[sp_CreateUserLocalDB]
AS
SELECT 0
GO
--
-- Definition for stored procedure sp_CreateUserLocalDB :
--
ALTER PROCEDURE [dbo].[sp_CreateUserLocalDB]
@username varchar(255)
AS
CREATE DATABASE QUOTENAME(@username)
USE QUOTENAME(@username)
CREATE TABLE [dbo].[Actions] (
[actionid] int DEFAULT (0) NULL,
[marketingid] int DEFAULT (0) NULL,
[actionno] int DEFAULT (0) NULL,
[actiondate] datetime NULL,
[actiontypeid] int DEFAULT (-1) NULL,
[actiontypeidtext] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[replydate] datetime NULL,
[replyid] int DEFAULT (-1) NULL,
[replyidtext] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[addedby] int DEFAULT (0) NULL,
[lastedit] datetime NULL
)
ON [PRIMARY]
For starters, it doesnt like the first QUOTENAME(@username); It tells me that there is an error near @username?
Seconds, it reckons I cant use a USE statement in a SP; how do I get the SP to create the tables in the other database (not in master)