Solved

MySQL Default Value

Posted on 2011-03-21
2
340 Views
Last Modified: 2012-05-11
When I try to enter a default value for a TEXT column in my MySQL database it will not let me. Is it possible to have a default value in a MySQL TEXT field?

I'm trying to write some PHP code that enters data in the MySQL databse & not being able to set a default field in the MySQL TEXT field is causeing some issues....

FYI...I am using PhP MyAdmin to try to set it up
0
Comment
Question by:wantabe2
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35179867
From the reference:
http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html
BLOB and TEXT columns cannot be assigned a default value.

so, you might try VARCHAR data type instead, if it's ok for that:
http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html

or, remove the NULL constraint, so that the field does allow NULLS.

note: a TEXT means very large text, which shall normally allow null ...
0
 
LVL 2

Expert Comment

by:ramkihardy
ID: 35179889
simple....
before passing values to the databse...
Check the textfiled is null....
if its is null..then pass the default value
else
pass the textfield value to the database...
Regards
Ramki
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now