473,836 Members | 1,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add not null column in a table

10 New Member
Hi again

I have another question, I would like to add NOT NULL column in my table. I have done like this :

ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

but it doesn't work and give the following error :
ERROR: ALTER TABLE: Attribute "patent_pri_dat e" contains NULL values

is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

Best regards,
Bogie
Sep 13 '07 #1
6 5166
rski
700 Recognized Expert Contributor
Hi again

I have another question, I would like to add NOT NULL column in my table. I have done like this :

ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

but it doesn't work and give the following error :
ERROR: ALTER TABLE: Attribute "patent_pri_dat e" contains NULL values

is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

Best regards,
Bogie

I looks like there are rows in which pri_date column contans NULLS values. U should fill it first.
Sep 13 '07 #2
amitpatel66
2,367 Recognized Expert Top Contributor
Hi again

I have another question, I would like to add NOT NULL column in my table. I have done like this :

ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

but it doesn't work and give the following error :
ERROR: ALTER TABLE: Attribute "patent_pri_dat e" contains NULL values

is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

Best regards,
Bogie
You can add NOT NULL columns to a table only if the table is EMPTY and does not contain any ROW.
Sep 13 '07 #3
rski
700 Recognized Expert Contributor
You can add NOT NULL columns to a table only if the table is EMPTY and does not contain any ROW.
I in version 8.* u can add not null on a column if it does not contain null values. Maybe I'm wrong but in earlier versions it's looks the same.
Sep 13 '07 #4
henryhcface
15 New Member
attention......
attention......
attention......
attention......
attention......
Sep 14 '07 #5
amitpatel66
2,367 Recognized Expert Top Contributor
I in version 8.* u can add not null on a column if it does not contain null values. Maybe I'm wrong but in earlier versions it's looks the same.
Yes It is possible to make the COLUMN NOT NULL in case if it does not contain any NULL value
Sep 14 '07 #6
bogie
10 New Member
I looks like there are rows in which pri_date column contans NULLS values. U should fill it first.

Hi

Thank you very much for the advice, it works.

Best regards,
Bogie
Sep 18 '07 #7

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

Similar topics

26
45465
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.) How can I achieve this? I suppose I would get the most-hated "table/view is changing, trigger/function may not see it" error if I tried to write a trigger that checks the uniqueness of non-null values upon insert/update.
3
6190
by: A.M. de Jong | last post by:
Reading a lot about Nulls right now I still can't find a Technical reason to use it or not. For what I've understand is this: In an Ingres database a Null column has a standard extra storage of 2 Bits. In a SQL Server database every column has a NULL-bit telling about this column it is NULL or NOT. That means that a varchar-empty NULLABLE column takes no space at all since the Nullable column defines it as NULL.
10
42433
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed to be optional, it's very definition is it's a necessary link to the parent table and part of the definition. If it's optional it shouldn't be part of the definition of a table and should be in a linking table instead. Comments?
3
2135
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in Perl, and Nulls have started to bother me greatly. The first issue is, as far as I understand it, a column should be NOT NULL if it is necessary (required) data. Now, if a column doesn't have to be NOT NULL; that is, it's not _required_ data,...
5
50684
by: Robert Stearns | last post by:
Either I missed something, or ALTER TABLE does not have this capability. Is there any way of doing it except DROPping all constraints which mention this table, EXPORTing the data, DROPping the table, reCREATEing the table without the 'NOT NULL property, reCREATEing the INDEXes, reloading the data, redefining all of DROPped constraints reCREATE the view which were marked inactive by the above.
7
2956
by: am72de | last post by:
Hi all, I've posted this problem some weeks ago, but noone had a solution. Perhaps now someone could help me. I have the following tables: Create Table T1 ( ID1 int Not Null , ID2 int Not Null
6
14405
by: axelsino | last post by:
I know this has been asked before and yes, I have read the section in the documentation about it. But, my question is: If I have setup mysql with strict_trans_tables, will MySQL allow "null" defaults in "not null" columns? If the answer is yes, will that information be reflected when I ask for metadata (column information, etc.)? Currently, when I ask for metadata information, not-null columns will return a default of "empty string". ...
3
13674
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or define a default value to be used? I want to think through the repercussions of this decision before I get into production.
2
12059
by: Jeff Kish | last post by:
Hi. I've read up on this, and have something that works, but I was wondering if there is anything I'm overlooking with this. Situation is: I have a bunch of tables.. I need to modify table2 as part of an upgrade of a database schema.
2
3883
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved. I’m learning SQL. I’m accessing database SQL2008 AdventureWorks, table Person.Contact, which has a...
0
9825
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9673
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10859
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10260
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9388
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4463
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.