Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Default Value

Posted on 2011-03-21
2
Medium Priority
?
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…

721 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