How do I use a variable for a Default vlaue in a SQL Create Table statement?
Posted on 2010-09-15
I'm trying to modify a script to use a variable (@ParamID) as a Default value for a column in my Create Table statement, however when I execute the script below, I get an error "Variables are not allowed in the CREATE TABLE statement." Can this be done? Could somebody give me a sample please? Any way to use the value directly from the Select statement without using the variable?
The SQL script:
DECLARE @ParamID AS int
SET @ParamID = (SELECT Shift FROM DatabaseVersion WHERE ObjectID = 1)
CREATE TABLE [dbo].[IntercomProtocol](
[PartitionID] [dbo].[PartitionReference] DEFAULT (@ParamID) NOT NULL,