473,378 Members | 1,152 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,378 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 111188
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: 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...

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.