Solved

SQL: how to change this value

Posted on 2009-07-10
13
238 Views
Last Modified: 2012-05-07
Hi experts,

I have a table as follows.

mysql> desc message_alert  ;
+---------------+-------------+------+-----+---------+----------------+
| Field             | Type        | Null | Key | Default | Extra          |
+---------------+-------------+------+-----+---------+----------------+
| id                | int(11)     | NO   | PRI | NULL    | auto_increment |
| dataset_id  | int(11)     | YES  | MUL | NULL    |                |
| dimension1 | varchar(20) | NO   |     | NULL    |                |


Now I want to change the value of column "Null" for "dataset_id" to "NO".  any ideas how to write this SQL?

Thanks so much.
0
Comment
Question by:davidw88
  • 4
  • 4
  • 2
13 Comments
 
LVL 17

Expert Comment

by:pssandhu
ID: 24826556
ALTER TABLE message_alert
ALTER COLUMN dataset_id int(11) NOT NULL
 
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24826569
Oh, I answered based on the MySQL.... since your desc statement says mysql
P.
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24826684
Are you asking how to change the default value for the column? If so, you cannot set it to 'NO' because the column is an integer type.

In any case, it is unclear which database you are referring to, your sample shows MySQL but you posted in Oracle and SQL Server zones.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:davidw88
ID: 24826691
This is MySQL.

Hi pssandhu: thanks so much for your prompt reply. I got

mysql> ALTER TABLE message_alert ALTER COLUMN dataset_id int(11) NOT NULL;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int(11) NOT NULL' at line 1


any more ideas?

0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24826708
What version of MySQL are you running. I am not too familiar wiht all different versions, but there might be a limitation based on your MySQL product version.
P.
0
 
LVL 17

Assisted Solution

by:pssandhu
pssandhu earned 60 total points
ID: 24826745
You might need to use the Change or Modify key words. Please see here:
http://www.freeopenbook.com/mysqlcookbook/mysqlckbk-chp-8-sect-3.html
P.
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 65 total points
ID: 24826771
Try MODIFY

ALTER TABLE message_alert MODIFY COLUMN dataset_id int(11) NOT NULL;
0
 

Author Comment

by:davidw88
ID: 24826789
It is Server version: 5.0.67-0ubuntu6 (Ubuntu)
0
 

Author Comment

by:davidw88
ID: 24826804
Cool! mrjoltcola's sql works!

Thanks experts!
0
 

Author Comment

by:davidw88
ID: 24826818
Thanks Advisor mrjoltcola for your advice. I did try to post in "MySQL" Zone, however I did not find such a zone so I posted in other related zones.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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