Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table field default value problem

Status
Not open for further replies.

msmonkey

Programmer
Apr 16, 2002
6
US
For MS SQL Server 7: Using Enterprise Manager, I entered a default value for a table field, but I can't seem to get the default value to show up after doing an insert.

I saw somewhere that in order for the default to work, you have to give it a value of NULL or DEFAULT in an insert, but all that does is enter the value NULL or DEFAULT.

Does anyone know how I can get the default value itself to show up??

 
It seems like this is a char or varchar column... Is that right? I wonder if you are doing something like this in your Insert:
INSERT myTable VALUES (1,'Bill',23,'DEFAULT')

The keyword DEFAULT should NOT be in quotes. Instead, just leave it without quotes like this:

INSERT myTable VALUES (1,'Bill',23,DEFAULT)

Does that do it for you?

bperry


 
I was hopeful for a second... I took a closer look at my query but it seems that I'm not using quotes where the default value would go.
--------------------------------------------
# SET DEFAULT VALUES, IF NECESSARY
if ($form_wait_time eq "") {
$form_wait_time = "DEFAULT";
}

$queryProcessJob = "INSERT INTO job (job_id,wait_time) VALUES (?,?)";
$sth = $dbh->prepare($queryProcessJob);
$sth->execute($db_job_id,$form_wait_time) or die $results->errstr;
---------------------------------------------
 
Hmmmm, okay let's try this:
Here I create a table with a default value of 'Nobody' on the employee name.

CREATE TABLE Table88 (
IdNum int not NULL,
Dept char(20) not NULL,
EmpName char(10) NOT NULL Default 'Nobody')


Okay, now Insert three records into the table.

INSERT into Table88 (IdNum,Dept,Empname)
VALUES (1,'Accounting','Brian')

INSERT into Table88 (IdNum,Dept,Empname)
VALUES (2,'Purchasing',DEFAULT)

INSERT into Table88 (IdNum,Dept)
VALUES (3,'Finance')

Look at records 2 and 3. They show two different ways of picking up the default value. I can guarantee you that those 2 records will have a name of Nobody. No question.
----------------------
So, since this is exactly how it is done, it's a matter of us figuring out how your example is different. I'm afraid I can't help with your specific syntax (that looks like Latin to me!).

Is there a way for you to print or display the actual command string that gets executed? Also, doublecheck the table definition to confirm that the column indeed does have a default value defined.

Maybe another forum reader can look at what we have here and make a suggestion.

rgrds, etc
bperry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top