473,385 Members | 1,782 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,385 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 111194
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 help? if i have 10 fields in 1 record and...
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 2-3 new columns worth. Now my questions are:...
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 series of Excel spreadsheets and then run various...
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 suresh 102 ramesh here there is...
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 I want to drop 'Not Null'. Please let me know. ...
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 one NOT NULL COLUMN (col_new) to A using following...
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 using create table pctemp1 As (SELECT...
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 adodb connection I have the need to run an...
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 me with the reason behind this thanks in advance
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.