473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ALTER TABLE question

I made a table this way:

mysql>create table tblCourses (courseCode char(30) primary key,
courseDescription char(50));

Now I realize that I forgot to enforce that both fields will not be null.
So I tried this:

mysql> alter table tblCourses (courseCode not null, courseDescription not
null);

but I got this result:

ERROR 1064: 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
'(courseCodenot null, courseDescription not null)' at line 1

Do I need to drop the table and start over? Or how could I add this?

Jul 20 '05 #1
2 1894
Richard Hollenbeck wrote:
I made a table this way:

mysql>create table tblCourses (courseCode char(30) primary key,
courseDescription char(50));

Now I realize that I forgot to enforce that both fields will not be null.
So I tried this:

mysql> alter table tblCourses (courseCode not null, courseDescription not
null);

but I got this result:

ERROR 1064: 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
'(courseCodenot null, courseDescription not null)' at line 1

Do I need to drop the table and start over? Or how could I add this?


Check the manual that
corresponds to your MySQL server version for the right syntax
Jul 20 '05 #2
Richard Hollenbeck wrote:
mysql>create table tblCourses (courseCode char(30) primary key,
courseDescription char(50));

Now I realize that I forgot to enforce that both fields will not be null.


It turns out that you can't alter simply the nullable/not nullable
attribute of a column. To change this attribute, you must list the
whole column definition, including name, datatype, etc.

alter table tblCourses
modify column courseCode char(30) not null primary key,
modify column courseDescription char(50) not null;

See http://dev.mysql.com/doc/mysql/en/ALTER_TABLE.html

I'm not sure what the reason is for this limitation, since there is
syntax to alter certain other attributes, such as the default. But
that's the way it is at least in current versions of MySQL.

Regards,
Bill K.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dylan Nicholson | last post by:
Seems that Oracle 9.2 (using MS ODBC driver) requires extra parentheses when adding multiple columns to a table: ALTER TABLE MyTable ADD (MyColumn1 VARCHAR(255), MyColumn2 VARCHAR(255)) vs ...
6
by: Brian Basquille | last post by:
Just started learning SQL recently. But one thing i'm still not clear on is about altering relationships between tables after they've been created. Instead of creating a foreign key when the...
3
by: Metal Dave | last post by:
Hello, A script we run against the database as part of the upgrade of our product is failing with the following message: ALTER TABLE ALTER COLUMN EncodedID failed because STATISTICS hind_61_3...
2
by: Gordowey | last post by:
I have the next question, and i would like to hear what do you think about, and if is there a better solution for "my problem" here is the question, I have a huge table with 60GB of data (image...
10
by: Jane | last post by:
Does any one know why this statement is failing? db2 => ALTER TABLE ELMT_T ALTER COLUMN CDTY_CD SET DATA TYPE VARCHAR(51) DB21034E The command was processed as an SQL statement because it was...
3
by: Michael Charney | last post by:
I am trying to alter a table that I imported data to. I can import the data just fine but when I run the following command: ALTER TABLE tblimport ADD COLUMN admit_date SmallDateTime It gives...
2
by: RamaKrishna Narla | last post by:
In MS SQL Server, I have the following tables with some data in it. create table table1 ( column1 varchar(32), column2 int not null, column10 varchar(255), ..... primary key (column1,...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
1
by: vasilip | last post by:
I'm testing out db2 for a project I'm starting that requires proper xml support and I can't seem to get both xml and spatial data to work well in the same table. Once having created a table...
1
by: quincy451 | last post by:
Ok I have a table with fields as follows: field1 varchar(10) field2 varchar(10) field3 varchar(10)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.