1

So I'm doing homework for a class and I have been stuck on this problem for days, apparently I'm not as good at google as I need to be.

Here it is: "Change the StoreReps table so that NULL values can’t be entered in the first and last name columns."

My Code (does not work):

    Alter Table StoreRep Modify lastname Not Null, Modify firstname Not Null;

My Code (does work but I need to be able to change both columns at the same time):

    Alter Table StoreRep Modify lastname Not Null;
1
  • Please add appropriate tags for SQL dialect you are using. From syntax I assume your RDMS is Oracle Commented May 10, 2013 at 14:34

3 Answers 3

2

If you're using MySQL, you also need to specify the type:

alter table StoreRep
modify firstname varchar(50) not null,
modify lastname varchar(50) not null;

See this demo.

Sign up to request clarification or add additional context in comments.

1 Comment

That all depends on dialect. Ravi Thapliyal's answer is good for Oracle, yours for MySql.
1
Alter Table StoreRep Modify (lastname Not Null, firstname Not Null);

1 Comment

Thanks! This worked. I am using Oracle for my class. I thought I tried this, but apparently I was missing the parenthesis.
0

You can use following query which can alter default value for multiple columns using single run:

     ALTER TABLE `wp_posts`  CHANGE `post_date` `post_date` DATETIME NOT NULL 
     DEFAULT CURRENT_TIMESTAMP, CHANGE `post_date_gmt` `post_date_gmt` 
     DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `post_modified` 
    `post_modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE 
    `post_modified_gmt` `post_modified_gmt` DATETIME NOT NULL DEFAULT 
     CURRENT_TIMESTAMP;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.