472,331 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How to add not null constraint to existing table?

How to add not null constrint to an existing table?


i tried with "alter table emp add constraint not_null_name not null(name)" command
but it's giving error ..........

alter table emp add constraint not_null_name not null(name)
*

ERROR at line 1:
ORA-00904: : invalid identifier
Aug 11 '07 #1
5 110989
debasisdas
8,127 Expert 4TB
NOT NULL constraint can't be added at table level

to add the constraint u need to modify the column

Expand|Select|Wrap|Line Numbers
  1. alter table emp modify ename not null;
Aug 11 '07 #2
Hi,
If u need add any constraints to tables means you write like

alter table table_name
add constraints

if u need add not null constraints means

alter table table_name
modify constraints
Aug 20 '07 #3
hi why "NOT NULL" is only constraint which cannot be enforced at table level?
Sep 28 '10 #4
amitpatel66
2,367 Expert 2GB
You can do so by using below ALTER statement:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER TABLE emp MODIFY name NOT NULL
  3. /
  4.  
  5.  
Make sure there are no existing NULL values in the column name, else you will not be able to ENABLE NOT NULL constraint.

Check below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> create table my_test(col1 NUMBER);
  3.  
  4. Table created.
  5.  
  6. SQL> ed
  7. Wrote file afiedt.buf
  8.  
  9.   1* insert into my_test values(1)
  10. SQL> /
  11.  
  12. 1 row created.
  13.  
  14. SQL> ed
  15. Wrote file afiedt.buf
  16.  
  17.   1* insert into my_test values(NULL)
  18. SQL> /
  19.  
  20. 1 row created.
  21.  
  22. SQL> commit;
  23.  
  24. Commit complete.
  25.  
  26. SQL> alter table my_Test modify col1 NOT NULL;
  27. alter table my_Test modify col1 NOT NULL
  28. *
  29. ERROR at line 1:
  30. ORA-02296: cannot enable (APPS.) - null values found
  31.  
  32.  
  33. SQL> delete from my_test WHERE col1 IS NULL;
  34.  
  35. 1 row deleted.
  36.  
  37. SQL> COMMIT;
  38.  
  39. Commit complete.
  40.  
  41. SQL> alter table my_Test modify col1 NOT NULL;
  42.  
  43. Table altered.
  44.  
  45. SQL> desc my_test;
  46.  Name           Null?    Type
  47.  -------------- -------- ---------
  48.  COL1           NOT NULL NUMBER
  49.  
  50. SQL> 
  51.  
  52.  
Sep 29 '10 #5
"add constraint" only for out-of-line constraints
while not-null constraint is inline constraint,
so cannot use "add constraint" for not-null constraint
ie. to add inline constraint uses modify column

alter table emp modify
column_abc_name constraint not_null_column_abc_name not null
;
Dec 12 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding...
1
by: deko | last post by:
DoCmd.CopyObject copies data, but I only need structure. I'm trying to clone several tables in my Access 2003 mdb. The goal is to link to a...
1
by: surya | last post by:
i have table fff .it has two fields one is fno int , another is fname varchar(20) fff fno fname -------- ----------- 100 ...
5
by: annecarterfredi | last post by:
Is there any command (alter table ...?) to drop 'Not Null' constraint on a column? I have a column CODE which has 'Not Null' constraint defined and...
1
by: aling | last post by:
Damn! SQLServer2000 can't add a NOT NULL COLUMN even in one empty existing table! That is, A is the existing table and it is emtpy, I want to add...
4
by: Shrutisinha | last post by:
Hi Guys Really need your help I donno what I am doing wrong in here Want to create a table with another existing table Here is the syntax I am...
1
by: arcingmad | last post by:
Hi I am using the following code in a button click event to run a query stored in a .mdb file from an external geographic program ArcGIS via a jet...
1
by: femina | last post by:
when i create a table from another table with as subquery the not null constraint gets copied but the primary constraint is not copied. can you help...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.