473,406 Members | 2,954 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,406 software developers and data experts.

How to drop Not Null constraint (system generated)

Hello,

I created one table say "Table1" with one column say "Column1" with constraint Not Null. Oracle generated its own name for this constraint. Say SYS_C#########.

I want to delete this constraint using one sql script. But how i will find out the constraint name to drop this constraint?

-Dhiraj
May 21 '07 #1
3 69712
chandu031
78 Expert
Hello,

I created one table say "Table1" with one column say "Column1" with constraint Not Null. Oracle generated its own name for this constraint. Say SYS_C#########.

I want to delete this constraint using one sql script. But how i will find out the constraint name to drop this constraint?

-Dhiraj
Hi,

All the Not null constraints will be stored in a table called ALL_CONS_COLUMNS which has Owner, table_name,column_name,constraint_name and position(in case of primary key)

So to get the constraint name for just a NOT NULL constraint your query would look like this :

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT CONSTRAINT_NAME FROM ALL_CONS_COLUMNS WHERE OWNER = <user_name> AND TABLE_NAME = <table_name>
  3. AND COLUMN_NAME = <column_name> 
  4.  
May 21 '07 #2
frozenmist
179 Expert 100+
Hi,
A simple solution that I can think of if you know the column name is that
you can just alter the column to allow null. This would take out the constraint , wouldn't it?
If you want the constraint name as such, it would be better if you do what Chandu
suggested.
Eg:
If your table was like
create table table1 (col1 integer not null)
then you can use
Expand|Select|Wrap|Line Numbers
  1. Alter table table1 modify col1 integer null
  2.  
to remove the constraint.

Hope it helped
Cheers
May 21 '07 #3
chandu031
78 Expert
Hi,

If you just want to drop the not null constraint then there is a better way of doing it.

Just use the ALTER TABLE command:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER TABLE <table_name> MODIFY <column> <datatype> NULL
  3.  
  4.  
Of course this does not work the other way round i.e from NULL to NOT NULL
if there are already NULLs in your table. It will work if the field doesn't have NULLs
May 21 '07 #4

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

Similar topics

4
by: Kevin Haugen | last post by:
SQL SERVER 2000 System let's you alter the system tables and add indexes. However, it won't let you drop the index afterward. Anybody know how to drop an index on a system table? Thanks, ...
5
by: Charts | last post by:
I recently upgraded to VS2005. I noticed that in ASP.NET project, the system generated codes are missing from default.aspx.cs file. While I used to be able to see it in VS2003 project. Now, if I...
4
by: Ken D. | last post by:
I have an asp page that collects data on referrals. The user inputs the information and selects the rep to receive the referral. My data is being saved to a backend database (SQL) and the user 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: abhu50 | last post by:
i have created table with unnamed check constraint so pl help me to drop this check constraint also about dropping the foreign key that is unnamed???????????
5
by: ganeshshegde | last post by:
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...
8
by: Elfae | last post by:
I have searched high and low for a sample for this, and I just can't find any. Sorry for the length! Background Information The issue revolves around setting up a system-generated increase in...
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
4
by: rismy | last post by:
The code for PDF attachment (system generated)via Email
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.