Setting a default column value using SQL

  • Thread starter Thread starter roadkill669
  • Start date Start date
R

roadkill669

Guest
I am not sure if I am even able to do this, but I am wondering how to set the default value for a field when creating a database using SQL. I am doing everything with coldfusion and I havn't been able to figure out what code needs to be there. I have tried everything I can think of. Any help would be appreciated.
 
Well, this is what I tried

<cfquery name="alter_open" datasource="EflyerDataBase">
ALTER TABLE #tablename#
ADD CONSTRAINT column_open_def
DEFAULT 0 FOR opened
</cfquery>

and it came up with

Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in CONSTRAINT clause.

The error occurred in E:\Inetpub\wwwroot\message.ecendent.com\web\cbuild.cfm: line 29

27 : </cfquery>
28 : <cfquery name="alter_open" datasource="EflyerDataBase">
29 : ALTER TABLE #tablename#
30 : ADD CONSTRAINT column_open_def
31 : DEFAULT 0 FOR opened

I have this create the table in a previous query, like you need to, then I try adding the constraint. This is the same thing that I have been trying except for the "FOR {columnname}"

I will play around with this somemore. Thanks for the link. I will try digging in there to see if I can find something else that I missed.
 

Users who are viewing this thread

Back
Top Bottom