homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Need some help with SQL command
tbe22




msg:4546225
 9:52 pm on Feb 16, 2013 (gmt 0)

I have a MySQL database, with a table called "posts", and two fields of my interest are "userid" and "source". I am trying to create an SQL command, which would insert a text string "http://domain-name.com" to all source fields that are empty, and that belong to user id, let's say 55.

So I need something like this:

Insert text string "domain-name.com" to table named "posts", into field called "source" when "userid" is "55"

(dont insert noting if the url, or something else is already there)

There is going to be more empty fields as the time goes by, and I am going to be adding the same url on a regular basic. So most of the fields will be already populated, but there are going to be new ones, and I am gonna have to enter the url there (let's say every week or two etc; only to the empty ones, I gues, or whichever way it is suppose to work)

Can somebody help me with that?

Thank you.

 

jadebox




msg:4546596
 9:48 pm on Feb 18, 2013 (gmt 0)

UPDATE posts SET source='http://domain-name.com' WHERE source = ''

But ... the right solution is probably to set the default value of the source column to "http://domain-name.com". You only have to do it once:

ALTER TABLE posts ALTER source SET DEFAULT 'http://domain-name.com'

-- Roger

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved