Constraint unique but allows null values
HelloI have a table in Oracle XE (10g) with four matching columns:
PrimaryKey
Book_FKEY
Subject_FKEY
Author_FKEY
The rules for this table are:
A line can contain Book_FKEY and Subject_FKEY (Author_FKEY is Null)
A line can contain Book_FKEY and Author_FKEY (Subject_FKEY is Null)
A line cannot contain only Book_FKEY, but a line must ALWAYS be Book_FKEY
A line cannot contain, Book_FKEY and Subject_FKEY and Author_FKEY
I tried to use the Unique key constraint in Oracle SQL Developer (v2.1.1) but it failed.
Can you help me please?
Thanks a lot for your help.
I would use only triggers after exhausting all other possibilities of constraint. You already have the constraints of primary key and foreign key in place, which is good. Technically, I believe that what you need is an extra check constraint to accomplish what you want to do, I think your best bet is to add a Unique combination of Not Null constraints and check on this Board.
First of all, Book_FKEY must always have a value, so make sure not Null column, if not already...
alter table modify Book_FKEY not null;
Second, I guess that your primary key is a substitute (number generated automatically), then you'll want a unique constraint to enforce a single author of book/object instance...
alter table add constraint unique (Book_FKEY, Subject_FKEY, Author_FKEY);
And finally, you will need a check constraint to apply other rules...
alter table add constraint check
(
(Book_FKEY is not null and Subject_FKEY is not null and Author_FKEY is null) or
(Book_FKEY is not null and Subject_FKEY is null and Author_FKEY is not null)
)
I hope it works for you,
Mark
Tags: Database
Similar Questions
-
will be the foreign key allows Null values?
Hello gurus!
will be the foreign key allows Null values?
Thanks in advance!Yes
You can try example below
create table table_1(id number primary key) insert into table_1 values (1); create table table_2 (id number references table_1(id),name varchar2(10)) insert into table_2 values (null,'test') commit;
-
Hello!
I had a TMS12.2 (via 12.6 and 13.2) to TMS14.1.1 upgrade.
When I go to: systems > overview of the system and select all systems and all the settings, I get an error message.
An order referred before you have a problem with the values of ip box.
Is it possible that 14.1 upgrade does not correctly check if the empty database fields?
How I'll fix it, did an upgrade using 14.2, or is it a sql command that must be executed
(or some values to be defined)?
Error details:
Server Error in '/tms' Application.
--------------------------------------------------------------------------------
Column 'SNMP Get Community Name' does not allow nulls.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.NoNullAllowedException: Column 'SNMP Get Community Name' does not allow nulls.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NoNullAllowedException: Column 'SNMP Get Community Name' does not allow nulls.]
System.Data.DataColumn.CheckNullable(DataRow row) +2131738
System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent) +5073836
System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException) +195
System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent) +344
Tandberg.TMS.UI.SystemOverview.ViewSystemOverviewGrid.CreateDataSource(EmbedLinksSetting embedLinks) +6856
Tandberg.TMS.UI.SystemOverview.ViewSystemOverviewGrid.DataBindToTMSGrid(EmbedLinksSetting embedLinksSetting) +171
Tandberg.TMS.UI.SystemOverview.SystemOverviewView.SystemOverviewViewDataBind(EmbedLinksSetting embedLinksSetting) +196
Tandberg.TMS.UI.SystemOverview.SystemOverviewHost.ShowModule(ModuleActions moduleAction) +115
Tandberg.TMS.UI.SystemOverview.SystemOverviewHost.systemOverviewFilter_ModuleAction(Object sender, ModuleControlEventArgs e) +43
Tandberg.TMS.Service.Navigation.TMSModuleBase.FireModuleEvent(ModuleControlEventArgs e) +22
Tandberg.TMS.Service.Navigation.TMSModuleBase.FireViewAction() +34
Tandberg.TMS.UI.SystemOverview.SystemOverviewFilter.viewButton_Click(Object sender, EventArgs e) +65
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Hi Martin,
You see flaws CSCue22625. A fix was published in TMS 14.2.
Kind regards
Kjetil
-
CF10 active metrics logging but getting NULL values instead
In an effort to troublshoot
I activated the connection CFADMIN settings but this is what I see in the metrics.log file. What gives?"Information","scheduler-1","11/13/13","15:59:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1737648152 Total memory: 2117206016 Active Sessions: 0" "Information","scheduler-1","11/13/13","16:00:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1565060456 Total memory: 2117206016 Active Sessions: 0" "Information","scheduler-3","11/13/13","16:01:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1634382744 Total memory: 2089222144 Active Sessions: 0" "Information","scheduler-2","11/13/13","16:02:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1532903104 Total memory: 2089222144 Active Sessions: 0" "Information","scheduler-0","11/13/13","16:03:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1371544704 Total memory: 2089222144 Active Sessions: 0" "Information","scheduler-2","11/13/13","16:04:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1193930792 Total memory: 2089222144 Active Sessions: 0" "Information","scheduler-3","11/13/13","16:05:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1749200240 Total memory: 2117664768 Active Sessions: 0" "Information","scheduler-3","11/13/13","16:06:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1614707664 Total memory: 2117664768 Active Sessions: 0" "Information","scheduler-2","11/13/13","16:07:54",,"Max threads: null Current thread count: null Current thread busy: null Max processing time: null Request count: null Error count: 21 Bytes received: null Bytes sent: null Free memory: 1485357392 Total memory: 2117664768 Active Sessions: 0"
I found the answer here: ColdFusion 11 settings log NULL values. Chris Tierney
Change the connector port in CFIDE (just underneath where you check "Enable logging of measures" to the one defined as the port of the AJP connector in server.xml - 8012 often.) You need to restart coldfusion.
Several ways to check a second time, I used
grep - ir 'port connector' / opt/coldfusion10 /.
-
Update statement using unique table with null values
Hi all
I want to update the table example table contain columns of c1.c2, c3 as below data
tab1: -.
------------------------
C1 c2 c3
1 2 null
3 null null
4 5 null
6 null null
-----------------------------------------
now, I want to update each value null to bellows value c3 c3
for example, the data as below
C1 c2 c3
1 2 3
4 5 6
How can using the update statement update it please help me
Thanks in advance
BalaSo you can never be sure of your order by...
SQL> create table tab1 as 2 ( 3 select 1 c1, 2 c2, null c3 from dual union all 4 select null, null, 3 from dual union all 5 select 4 ,5, null from dual union all 6 select null, null ,6 from dual 7 ); Table created. SQL> SQL> select * 2 from tab1 3 / C1 C2 C3 ---------- ---------- ---------- 1 2 3 4 5 6 SQL> SQL> merge into tab1 t 2 using (select rowid rid 3 , c1 4 , c2 5 , c3 6 , lead (c3) over (order by rowid) ld 7 from tab1 8 ) v 9 on (t.rowid = v.rid) 10 when matched 11 then update set c3 = ld 12 delete where c3 is null 13 ; 4 rows merged. SQL> SQL> SQL> select * 2 from tab1 3 ; C1 C2 C3 ---------- ---------- ---------- 1 2 3 4 5 6 SQL>
@Peter: PTR, het is niet koud. Het zonnetje schijnt ;)
for everyone: no, it's not cold. The Sun is shining. -
Hi all
Can I restrict null values when passing parameters in procedures. can someone explain to me with a small exampleHello
Pascale says:
The table does not allow null values. It throws an exception when the value null is passed IN parameterAre you talking about raising of arguments passed to a procedure or a table?
If a column in the table has a NOT NULL constraint, an error will be reported in the world tries to add a NULL value in this column, or if someone tries to change an existing value with a NULL value.
I don't know anyway auto to force an error when a procedure is called with a NULL argument. There may not be any built-in mechanism because it is so easy to test the NULL at the beginning of the procedure and explicitly to trigger an error.
-
Group by excluding null values
I want to run a select using "group by". However, I would like the results to exclude all null values in my area. Like for example the code following, but excluding NULL values.
Select the FIELD, count (FIELD)
of MYDATA
FIELD group;
How can I do this?
Hello
Maybe I don't understand your complete problem, but what of this
select FIELD, count(FIELD) from MYDATA where field is not null group by FIELD;
concerning
Kay -
Hello world
I did a pivot table. It displays correctly the results, but as null values. How to avoid display null values? If I don't get it, you can see what I mean in the picture below.
http://img251.imageshack.us/img251/9259/ORAF.jpgStansia,
You can check: http://total-bi.com/2010/10/replace-nulls-in-obiee-pivot-table/
Try what kishore said
Thank you
Saichand.v -
We use the UPDATE/INSERT mode, among the fields allows null value in the database, it cannot the corresponding record in the database of the collection because null = null does not work. How can handle us this in mapping?
Thank youTry this:
Re: Eric NULL valuesMate
-
I want to print something, if the value is not blank or not NULL. What exactly is the code for this? Why is it not simple check NULL values when the database allows NULL values?
< cfif getFaculty.emply_mddl_intl NEQ "" GOLD getFaculty.emply_mddl_intl IS NOT NULL > does not work. What does it mean?
DI wouldn't change the database. using the len (trim (string)) is just a reality in the world of CF. you get used to it :)
Yes, in queries, you can use the keyword NULL to your heart's content.
UPDATE myTable SET col1 = NULL where foo = 'bar '.
-
Maximum Unique constraints Null values
Nulls howmany Maximum allowed in the Unique constraintThere is NO Limit to it. You can have a number any NULL value in a column with a Unique constraint.
-
Constraint Unique NOT NULL in Data Modeling
I created unique constraints in the relational model and I am trying to figure out how to make a NOT NULL constraint.
Let's say the name of the table's category with cat_id, cat_name, sort columns.
I create in SQL 'category ALTER TABLE MODIFY (category CONSTRAINT NOT NULL xxx_cat_name_nn);', but there is no data entry point inside the Modeler in the [properties unique key - xxx_cat_name_nn] dialog box, that I can find, that allows me to tell him that it is a NOT NULL constraint. I'm sure that there is a way, but I just fall over my own feet, trying to find.
Any help would be greatly appricated.
Published by: 991065 on February 28, 2013 13:40Hello
You can make the column NOT NULL by disabling the "Allow nulls" property for the column.
If you want a named STEP forced to NULL value, you must also set the property "Not Null Constraint Name" (under the default tab and the constraint of the column properties dialog box).David
-
Add the constraint not NULL in the existing table that has null values
Hello
I want to add a constraint not null to and an existing table, but the table already contains values null in this column.
EMP
Emp_id name
1 axada
2
3 sdkdd
Here is already the data IE 2 empid is Null as name. I must add a fool of constraint not null which new values will not be null, but I don't want to change the data of exisitng alreadt which is null.
Hello
"The opposite": NOVALIDATE does not validate the data that is ALREADY in the table, but do not allow the insertion of a NULL value.
Have you tried my sample code?
CREATE TABLE MaTable (x NUMBER PRIMARY KEY, y NUMBER);
INSERT INTO myTable VALUES (1, 123);
INSERT INTO myTable VALUES ( 2, NULL );
INSERT INTO myTable VALUES (3, 456);
ALTER TABLE mytable MODIFY (y NOT NULL NOVALIDATE );
INSERT INTO myTable VALUES (4, 678);
INSERT INTO myTable VALUES ( 5, NULL );
SELECT * FROM MyTable;
'2' line was inserted with null before the creation of the NOT NULL constraint, this line remains "as what" at the end of the trial.
'5' line trying to insert a NULL value after creating the NOT NULL constraint, which is denied.
Best regards
Bruno.
-
I have an HTML5 form that allows the user to select 1 of 6 provinces of Costa Rica. If they do not select a Province, I use php code to send a NULL value and the other selections research of the form looking for all Provinces. If they choose a province, we are looking for database records that are found in this province. Currently I use the value = '%' as the selected value if the user does not have a choice. It works and looks in all provinces, but I get an error of W3c checking on the value = '% '. Y at - it another way to send a NULL value. PS: I have the same problem on the following form which allows you to select the Business category. The page is http://www.yellowpagescr.com
Here is a copy of the code. The RED line works but gets a W3c issue error of the test page. :
< form = class "navbar-form Center navigation bar" role = "Search" action = "#searchresults" method = "get" name = "selectterms" id = "selectterms" title = "" >
< select name = "province" autofocus class = 'copyright' title = "Click to select a Province (optional)" >
< option value = '%' selected = "selected" > all Provinces < / option >
< option value = "alajuela" > Alajuela < / option >
< option value = "cartago" > Cartago < / option >
< option value = "Guanacaste" selected > Guanacaste < / option >
< option value = "heredia" > Heredia < / option >
< option value = "Limon" > Limon < / option >
< option value = "Puntarenas" > Puntarenas < / option >
< option value = "San Jose" > San Jose < / option >
< option value = "Other" > other < / option >
< / select >
The correct way.
-
Addition of constraint not Null to a column that contains null values
All,
Could you please suggest me how to add the constraint not null to an existing column that has null values?
SQL > create table nn (number n, s varchar2 (10));
Table created.
SQL > insert into nn values (1, 'test');
1 line of creation.
SQL > insert into values nn (2 '');
1 line of creation.
SQL > commit;
Validation complete.
SQL > alter table nn edit n number not null;
Modified table.
SQL > nn desc;
Name Null? Type
----------------------------------------- -------- ----------------------------
N NUMBER NOT NULL
S VARCHAR2(10)
SQL > alter table nn edit n number null.
Modified table.
SQL > nn desc;
Name Null? Type
----------------------------------------- -------- ----------------------------
N NUMBER
S VARCHAR2(10)
SQL > alter table nn change s varchar2 (10) not null;
ALTER table nn change s varchar2 (10) not null
*
ERROR on line 1:
ORA-02296: impossible to activate (SCOTT) - found null values
SQL >
Thank you
Use NOVALIDATE:
SQL > alter table nn change s varchar2 (10) not null;
ALTER table nn change s varchar2 (10) not null
*
ERROR on line 1:
ORA-02296: impossible to activate (SCOTT) - found null valuesSQL >
SQL > alter table nn change s varchar2 (10) not null NOVALIDATE;Modified table.
SQL > insert into values nn (3, null);
insert into nn values (3, null)
*
ERROR on line 1:
ORA-01400: cannot insert NULL into ('SCOTT'. "' NN '. » S »)SQL > select * from nn;
N S
---------- ----------
1 test
2SQL >
SY.
Maybe you are looking for
-
my guard computer shut down on its own
After that connect to my home computer, I try to do some thing/all and it turns off. screen empties and turns itself off. I then restart the computer by turning the button and after the same amount of time it turns off again. It continues to be. I ru
-
Vista - Error Codes: 80246007 & 646 (cannot install updates)
When I updated to Vista and MS Office 2007 using Windows updates, download updates, but do not settle, and the error is reported as 80246007 and 646. I checked the "BITS" service settings that are good ('Automatic' and 'On the road') and the 'repair
-
Need help with the installation of Windows XP SP3.
Original title: xp sp3 criteria. My XP sp3 OS does not start. My xp sp2 installation disc is corrupt. I did a benchmark of different BONE with a base XP CD. IE 6 now does not work Can I download and upgrade directly to XP SP3?
-
Adding an SSD for Acer Aspire VN7 - 591G - 70RT (need help)
Hello I have an addition an Acer Aspire VN7-591 G-70RT with a slow 5400 RPM 1 TB WD Blue that creates a bottleneck in my laptop. I checked on Crucial to see if there are compatible SSD for my laptop which recommended: MX200 crucial m2 Type 2280 (Sing
-
My printer is configured to start when the computer turns on. I want to reconfigure it so that it won't turn. I know this is probably a simple change, but I can't find the path anywhere. Any help?