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

x
?
Solved

SQL: how to change this value

Posted on 2009-07-10
13
Medium Priority
?
246 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
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!

 

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 240 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 260 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

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

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

885 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