Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MySQL Default Value

Posted on 2011-03-21
2
Medium Priority
?
355 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

971 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