Solved

how to remove "not null" from an column?

Posted on 2003-11-05
6
4,687 Views
Last Modified: 2013-12-09
hello friends, I have a problem and hope u can help me.
Its probably quite easy so the point are not that high.
here we go:
(my english vacabulary is not the best but I hope youll understand)


I have a table filled with data.
one of the column is declared as "not null" and now I want to remove the "not null"-thingy.
I haved tryed the following but it didnt work.

ALTER TABLE my_table ALTER COLUMN my_column DROP not null;

what do I do wrong.
/evikekka
0
Comment
Question by:evikekka
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
Trekker72 earned 25 total points
ID: 9691402
try

update RDB$RELATION_FIELDS set RDB$NULL_FLAG = NULL
where (RDB$FIELD_NAME = 'my_column') and (RDB$RELATION_NAME = 'my_table');
0
 
LVL 10

Expert Comment

by:János Szabó
ID: 9692379
Hi evikekka,
try as follows:
1. insert a new column with the same properties except NOT NULL
2. copy into the new column the data from the old column
3. delete the old column
4. rename the new column to the old column name

with best regards

Janos
0
 

Author Comment

by:evikekka
ID: 9692716
excelent Trekker72.
ty vm.

and Janos,
thank you to.
I found that solution myself on borlands homepage,  the problem was that I didnt know how to copy data;)
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 10

Expert Comment

by:János Szabó
ID: 9693406
Hi evikekka,

sorry, I made a mistake.

To modify an existing column while retaining the data in that column, you need to perform a six step process:
1. Use ALTER TABLE to add a new column to the table.
2. Perform an UPDATE query to copy the data from the existing
column to the new column.
3. Use ALTER TABLE to drop the existing column.
4. Use ALTER TABLE to add a new column with the revised settings, using the same name as the column just dropped.
5. Perform another UPDATE query to copy the data from the temporary column to the newly created column.
6. Finally, use ALTER TABLE to drop the temporary column at the
end of the table.

This sequence of steps is required if you need to make a change that is not supported by the ALTER TABLE statement, such as changing the datatype of a column. To change the name of a column, perform steps 1 through 3.
0
 
LVL 10

Expert Comment

by:János Szabó
ID: 9693417
The solution of Trekker72 is great.

wbr Janos
0
 

Author Comment

by:evikekka
ID: 9693424
yes it is.
it worked fine, but thanks anyway for your time and help
/evikekka
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some very basic things about SQL Server filegroups.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question