Constraint question
Oracle Version 10.2
OS: Solaris 10, x86
I have the following structure:
CREATE TABLE table1
column1 NUMBER NOT NULL,
column2 NUMBER NOT NULL,
startdate DATE NOT NULL,
enddate DATE NOT NULL
);I can have as many duplicates of the pair {column1, column2}. However I wish to restrict the STARTDATE and ENDDATE columns per {column1, column2} in a such way that they do not overlap in time.
For example, if I have:
COLUMN1 COLUMN2 STARTDATE ENDDATE
A B 2012-01-01 12:00:00 2012-01-02 12:00:00I can have at the same time another row for {A, B} with these dates:
COLUMN1 COLUMN2 STARTDATE ENDDATE
A B 2012-01-02 12:00:00 2012-01-03 12:00:00But I would like to not be able to have another row for {A, B} with these dates:
COLUMN1 COLUMN2 STARTDATE ENDDATE
A B 2012-01-02 08:00:00 2012-01-03 12:00:00in which case the dates will overlap with the dates from the first row.
How could it be implemented with constraints?
>
Probably worth reading:
>
Probably? Ah - the master of the understatement. To paraphrase Shakespeare's Hamnle: Tubby, or not Tubby. That is the question.
Deserves at least 20 points!
Similar Messages
-
Tomcat security constraint question
Hi all,
we're using the following security constring for securing our servletts. Everything works fine so far.
<security-constraint>
<web-resource-collection>
<web-resource-name>Test</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
</security-constraint>
Now the question: We've implemented some kind of password reminder which allows you to retrieve a new password, this servlett should be accessible by anybody.
Do we have to list all the url-mappings except the one for the password reminder or is there a special tag to exclude an url-pattern from the wildcard-rule which we haven't yet? Any hints would be appreciated...
Regards, FlorianUsing: Tomcat 5.5.20 on Windows Server 2003
Couple Questions:
1. How do I prevent users from entering a double
quote in the INPUT field on the server side?use javascript
Also, is
it possible to replace the double quote with single
quote on the server side? If yes, How? I don't want
to use JavaScript because it can be disabled.yes,
yourVarString.replaceAll("\"","\'");
2. Where is the best place to ack Tomcat questions?http://tomcat.apache.org/findhelp.html
I
had some question on security-constraint. I have a
folder that has sercurity-constraint on it, so when
that folder is accessed tomcat asks for credentials.
Once user provides proper Username and Password, it
grants them the access. Now I want to know once the
access is granted, how come it doesn't display
index.jsp form that folder, It displays an image. I
don't understand why?
Please help....i have encountered that also on tomcat 3 intalled on linux machine.. the account that was being used to start the tomcat is root.. then the resolution was the owner account of the tomcat starts the server and it worked! hope that give you an idea -
Web.xml - security constraint question
I want to make a kind of inverted security constraint. I want to ALLOW access to one specific page over HTTP. All other pages should be HTTPS.
Is that possible???Use the <security-role-ref> for the Faces Servlet to map the LDAP roles to the logical role names used by the managed bean to determine if links may be rendered.
Bean code:
this.isAdmin = context.getExternalContext().isUserInRole("admin");web.xml:
<security-role>
<role-name>Local Admin Group</role-name>
</security-role>
<security-role>
<role-name>DBA Group</role-name>
</security-role>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<security-role-ref>
<role-name>admin</role-name>
<role-link>DBA Group</role-link>
</security-role-ref>
<security-role-ref>
<role-name>admin</role-name>
<role-link>Local Admin Group</role-link>
</security-role-ref>
</servlet> -
A security-constraint question - Hopefully to get answered.
I have a security-constraint that protects URLs with pattern "/test/*". Now, the login page is defined as /login.jsp.
Now if i directly access the url say "/test/1.jsp" , I am redirected to /login.jsp.
Now, what i want is to find out what was the originally requested URL on the login jsp. In other words, I want to put a S.O.P statement in login.jsp that the originally requested URI was /test/1.jsp .
I tried searching Java sites and stuff nothing has come up. None of the request object's methods allude to it also.
Thanks for your help
NikhilYou can use the HTTP referrer header for this.String referrer = request.getHeader("referer"); // Yes, with the legendaric misspelling in it.Only keep in mind that the client has full control over what it sends with the request, so it could also spoof the referrer value. But if you only use this to redirect back to the desired page after login, those users (hackers) won't take benefit from it.
-
I have a table that contains among others the following columns:
AFFILIATED_LOCATION_ID
ADDRESS_ID
VENDOR_ID
I would like to enforce the following rules on this table:
If AFFILIATED_LOCATION_ID is not NULL, then ADDRESS_ID & VENDOR_ID must be NULL. If AFFILIATED_LOCATION_ID is NULL then ADDRESS_ID & VENDOR_ID cannot be NULL.
I am looking for help on how to enforce this in the database. Any ideas???
Thanks - MikeHow about a check constraint that states ...
(AFFILIATED_LOCATION_ID Is Not Null And
ADDRESS_ID Is Null And
VENDOR_ID Is Null)
Or
(AFFILIATED_LOCATION_ID Is Null And
ADDRESS_ID Is Not Null And
VENDOR_ID Is Not Null)
Thanks! That is what I was trying to accomplish.
Mike -
Whats the difference between declarative constraints. What are the difference between declarative constraints and constraints enforced by Oracle?
Yeah i know that. Actually i was going through Oracle's documentation Oracle 10g concepts. I was reading the topic "Constraints on Views". Its written that we can define declarative constraints on views. The below line is copied from the doc. Kindly refer below
"Only logical constraints, that is, constraints that are declarative and not enforced by Oracle, can be defined on views. The purpose of these constraints is not to enforce any business rules but to identify multidimensional data. The following constraints
can be defined on views:
Primary key constraint
Unique constraint
Referential Integrity constraint" -
Simple unique constraint question
HI ALL,
I have created a table as below, and added unique key to both the col of the table.
CREATE TABLE TT( A NUMBER,B NUMBER);
ALTER TABLE TT ADD CONSTRAINT UNQ_CNT UNIQUE(A,B);
INSERT INTO TT VALUES (&A,&B);
Enter value for a: 1
Enter value for b: null
Enter value for a: 1
Enter value for b: null
ORA-00001: unique constraint (SCOTT.UNQ_CNT) violatedwhy I am getting the above err as Null cannot be equal to Null so the record
should be unique from other record.
Kindly help in understanding this concept.
Regards,
AAK.AAK,
When you create UNIQUE constraint on multiple
NULLABLE columns, uniqueness is checked for NON-NULL
values. So in your case, when you try to insert
another row, ORACLE detects that column A already has
same value (1) and hence it gives error. You can find
more details in documentation.Two rows that contain nulls for one or more key columns and the same
combination of values for the other key columns violate the constraint.
Not for NON-NULL values only.
Khurram -
Deadline vs. date constraints question
Hi,
I'm breaking my head over this one. In my effort to make my planning as dynamic as possible, I used deadlines for tasks instead of date constraints. All tasks are on finish ASAP. Say I have this situation:
20 tasks, all with different deadline dates
only 2 or 3 resources assigned to the tasks, never more than 1 on each task
work/duration also varies
all the same priority
Now when I level the tasks, some of them go past their deadline date. I understand why. MS P doesn't account for the deadline dates and only gives a visual indicator when going beyond the deadline date. With leveling order set to priority/standard when leveling
MS P looks for priority first. They all have the same priority. Next are constraints. They don't have any constraints. Next up is slack which is varying, so leveling is based on slack only. I can see that tasks can be leveled in a way that not a single task
goes past it's deadline. I know I can't make MS P level this way, or the way I want. Another way would be to work with 'Finish no later than' constraint. Since I read many articles about this all stating that avoiding this kind of restrictions is
your best bet to level without errors or MS P crashing, I'm in doubt wether to use them or not. What's your opinion on this one?Hi Trevor,
Thanks for your feedback. I was doubting myself after reading your reply so I tried a very simple set of tasks with deadlines. Like this:
Task Deadline Duration Work Resource
1 1-14-15 1d 8h 1
2 1-19-15 2d 16h 1
3 1-23-15 3d 24h 1
4 1-30-15 4d 32h 1
5 2-09-15 5d 40h 1
6 2-11-15 1d 8h 1
7 2-16-15 2d 16h 1
8 2-20-15 3d 24h 1
9 2-27-15 4d 32h 1
10 3-09-15 5d 40h 1
Please try in MS P and let me know what it comes up with. The deadlines give plenty of room to finish the tasks in time with just one resource. But after leveling, tasks 2, 3, 4, 6, 7 and 8 all go past their deadline. When I make a predecessor
of every previous task (linking them) the work finishes on 2-23-15 with no overallocation, far before the latest deadline which is 3-09-15. I don't want to make constraints if there in reality isn't any, so made the predecessors just to prove that is possible
to level in a way that there isn't any overallocation and all tasks finish on time. -
Access update cascade ref constraint question
Access allows the definition of update cascade referential
constraints. This type of constraint is not allowed to be
defined declaratively in Oracle, but can be implemented using
trigger code. Does the Access module in Migration Workbench
create the required triggers to enforce update cascade
relationships?
Thanks,
George
nullWell, there is no UPDATE CASCADE clause supported in Oracle.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/data_int.htm#sthref2962
You can refer to following link from Tom Kyte as to how you can implement the UPDATE CASCADE.
http://asktom.oracle.com/tkyte/update_cascade/index.html -
Question on PSI: Setting Constraint Type
In our current project, we are using the PSI to copy multiple tasks from one section of the project and paste at the end in order to create new set of tasks within the project. Below is the code snippet from our solution. We, first, create a new task object.
And then we unto newly created blank task, we copy the task from the source task (from another section of the project). Then, we assign new task ID GUID. Everything gets copied correctly when comparing the original task and newly created task. One property
we have question is Task_Contraint_Type. The source task’s Task_Contraint_Type is “As soon as possible” and when we make the copy (as in the code below and upon saving the project data back to Project Server and publish/check-in the project, when we open the
project, the newly created task’s constraint type is “This task has a ‘Start No Earlier Than’ constraint on
Date” (See image below). We expected “As soon as possible” because the source task was “As soon as possible” However, this was not the case.
As a result, we modified the code (see bold) so that during the copy/create new task, we set Task_Constaint_Type to “As soon as possible”. However, this still resulted, again, in “This task has a ‘Start No Earlier’…” constraint. The workaround for now was
after we finish copy all tasks, we then grab the dataset again and then update all tasks once again to set the Task_Constraint_Type to “As soon as possible”. However, this results in doing the work twice and can be potential performance hit as we noticed that
calling “QueueAddToProject” took a lot of time as project gets fairly large (we create project of size 25k tasks). Do you know why setting Task_Constaint_Type duing the initial task creation yields different value?
// Create a new task object
Project.ProjectDataSet.TaskRow newTask = _tasksDataset.Task.NewTaskRow();
// Copy data from the source task to newly created task
newTask.ItemArray = _tasksDataset.Task[i].ItemArray.Clone() as object[];
// Make a new GUID to be the new task's GUID
Guid taskId = Guid.NewGuid();
// Assign differentiating properties to the new task
newTask.PROJ_UID = _projectUid;
newTask.TASK_UID = taskId;
newTask.TASK_DUR = (int)PSLibrary.Task.DurationFormat.Day;
newTask.TASK_CONSTRAINT_TYPE = 0; //
0 = As soon as possible
newTask.StatusManager = _projectOwnerUid;Hi all,
It turns out that calling:
newTask.SetTASK_START_DATENull()
newTask.SetTASK_FINISH_DATENull()
and then:
newTask.TASK_CONSTRAINT_TYPE = 0;
solves the problem of the constraint not being set. -
A simple question...Constraints covering more than 1 table
Hello you all,
I got a simple question for a school project I have to do in Oracle. At least I think it will be simple for most people on this forum. But I can't figure it out. (Excuse me for the head title of the thread as well, but I don't know the exact term for this in english )
I can figure out how to do constraints in one table, for example:
'enddate > begindate'
But I got the following situation that I got the 2 following tables:
- Project
- Projectphase
I want to build in a constraint that prevents that the 'enddate' of the table 'Project' has an earlier date than the 'enddate' of the table 'Projectphase' because all projectphases have to be finished before a project can be finished.
I've tried to do this with constructions like 'Pro.Project.Enddate' and 'Pph.Projectphase.Enddate' but that doesn't work out.
So any help will be greatly appreciated.I think what you want is called a "business rule". It can be implemented by using triggers on the tables, not constraints.
Tim -
Questions on ENABLE NOVALIDATE a constraint
I run the command on Oracle 11.2.0.1 on Redhat 5.2SQL> alter table agency add constraint agency_agcy_ori unique (agcy_ori) ENABLE NOVALIDATE;
alter table agency add constraint agency_agcy_ori unique (agcy_ori) ENABLE NOVALIDATE
ERROR at line 1:
ORA-02299: cannot validate (DEVPF.AGENCY_AGCY_ORI) - duplicate keys found I knew the table has duplicate and null in the column which I want to add unique constraint. Using NOVALIDATE, I expect it tolarates the exist duplicate and valid new added data for uniqueness. Because it is stated in Oracle DOc B28286 that (page 8-15) ENABLE NOVALIDATE ensures that all new DML operations on the constrained
data comply with the constraint. This clause does not ensure that existing data in
the table complies with the constraintHowever, my database does not agree with this. Did I misunderstood the doc?
Other related questions
1) I have two rows with the column agcy_ori is NULL. Would that be considered duplicate and fails VALIDATE when create a unique constraint.
2) The same doc also states (page 8-16) DISABLE VALIDATE disables the constraint and drops the index on the constraint,
but keeps the constraint valid. This feature is most useful in data warehousing
situations, because it lets you load large amounts of data while also saving space
by not having an index. This setting lets you load data from a nonpartitioned table
into a partitioned table using the exchange_partition_clause of the ALTER
TABLE statement or using SQL*Loader. All other modifications to the table
(inserts, updates, and deletes) by other SQL statements are disallowedThis raises more questions:
a) DISABLE VALIDATE an unique constraint drop the unique index but still validate uniqueness. This is saying that te uniqueness is maintained without an unique index. If that is possible, why ENABLE an unique constraint need to create an unique index?
b) The last setense 'All other modifications to the table by other SQL statements are disallowed'. This actually make the table read only except for partition/nonpartition and SQL*LOADER. This can be a useful feature but I do not see the logic here: Cannot update column2 of the table just because a constraint in column 10 is DISABLE VALIDATE.
Hope people can help me here. Thanks.Re-read the documentation on the ENABLE clause
at http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/clauses002.htm#g1053592
ENABLE Clause
Specify ENABLE if you want the constraint to be applied to the data in the table.
+If you enable a unique or primary key constraint, and if no index exists on the key, then Oracle Database creates a unique index. Unless you specify KEEP INDEX when subsequently disabling the constraint, this index is dropped and the database rebuilds the index every time the constraint is reenabled.+
You can also avoid rebuilding the index and eliminate redundant indexes by creating new primary key and unique constraints initially disabled. Then create (or use existing) nonunique indexes to enforce the constraint. Oracle does not drop a nonunique index when the constraint is disabled, so subsequent ENABLE operations are facilitated.
Create a non-unique Index first.
Hemant K Chitale -
Question about how to create FORIGEN KEY constraints against XMLTYPE table
Hi,
1.I have a table called SNPLEX_DESIGN which is created as XMLTYPE, the XMLTYPE is refered to a registered XMLschema. The XMLschema has a data element called BATCH_ID, and I create a primary key for the SNPLEX_DESIGN table on the BATCH_ID. The SQL staement as
ALTER TABLE SNPLEX.SNPLEX_DESIGN ADD (CONSTRAINT "BATCH_ID_PK" PRIMARY KEY(xmldata."BATCH_ID"))
2. I have another table call SNPLEX_PROCESS which is a regual relational table with a column TOKENID. I would like to create a forign key on TOKENID which needs to refer to the SNPLEX_DESIGN table BATCH_ID_PK primary key.
But I got error when I try to alter the SNPLEX_PROCESS table.
SQL> ALTER TABLE "SNPLEX"."SNPLEX_PROCESS" ADD (CONSTRAINT "BATCH_ID_FK" FOREIGN KEY("TOKENID") RE
FERENCES "SNPLEX"."SNPLEX_DESIGN"(xmldata."BATCH_ID"));
ERROR at line 1:
ORA-02298: cannot validate (SNPLEX.BATCH_ID_FK) - parent keys not found
3. Can someone helps me on this.. I have no problem to create a foreign key in SNPLEX_DESIGN to refere primary key in relational table. But Why I can not do the other way around.
Any assistances will be appreciated..
JinsenHi Jinsen
As mentioned in the error message not all rows in PROCESS have a corresponding value in DESIGN.
To find out which are missing do some selects to compare your data or use the exception clause in the ALTER TABLE statement.
e.g.: ALTER TABLE "SNPLEX"."SNPLEX_PROCESS" ADD (CONSTRAINT "BATCH_ID_FK" FOREIGN KEY("TOKENID") RE
FERENCES "SNPLEX"."SNPLEX_DESIGN"(xmldata."BATCH_ID")) EXCEPTIONS INTO <exception table>
Notice that you have to create the <exception table> with the script $ORACLE_HOME/rdbms/admin/utlexcpt.sql.
Chris -
How to apply the constraint ONLY to new rows
Hi, Gurus:
I have one question as follows:
We need to migrate a legacy system to a new production server. I am required to add two columns to every table in order to record who updates the row most recently through triggers, and I should apply not null constraint to the columns . However, since legacy system already has data for every table, and old data does not have value for the 2 new columns. If we apply the constraint, all of existing rows will raise exception. I wonder if there is possibility to apply the constraint ONLY to new rows to come in future.
Thanks.
SamWe need to migrate a legacy system to a new production server. I am required to add two columns to every table in order to record who updates the row most recently through triggers, and I should apply not null constraint to the columns .
The best suggestion I can give you is that you make sure management documents the name of the person that came up with that hair-brained requirement so they can be sufficiently punished in the future for the tremendous waste of human and database resources they caused for which they got virtually NOTHING in return.
I have seen many systems over the past 25+years that have added columns such as those: CREATED_DATE, CREATED_BY, MODIFIED_DATE, MODIFIED_BY.
I have yet to see even ONE system where that information is actually useful for any real purpose. Many systems have application/schema users and those users can modify the data. Also, any DBA can modify the data and many of them can connect as the schema owner to do that.
Many tables also get updated by other applications or bulk load processes and those processes use generic connections that can NOT be tied back to any particular system.
The net result is that those columns will be populated by user names that are utterly useless for any auditing purposes.
If a user is allowed to modify a table they are allowed to modify a table. If you want to track that you should implement a proper security strategy using Oracle's AUDIT functionality.
Cluttering up ALL, or even many, of your tables with such columns is a TERRIBLE idea. Worse is adding triggers that server no other purpose but capture useless infomation but, because they are PL/SQL cause performance impacts just aggravates the total impact.
It is certainly appropriate to be concerned about the security and auditability of your important data. But adding columns and triggers such as those proposed is NOT the proper solution to achieve that security.
Before your organization makes such an idiotic decision you should propose that the same steps be taken before adding that functionality that you should take before the addition of ANY MAJOR structural or application changes:
1. document the actual requirement
2. document and justify the business reasons for that requirement
3. perform testing that shows the impact of that requirement on the production system
4. determine the resource cost (people, storage, etc) of implementing that requirement
5. demonstrate how that information will actually be used EFFECTIVELY for some business purpose
As regards items #1 and #2 above the requirement should be stated in terms of the PROBLEM to be solved, not some preconceived notion of the solution that should be used.
Your org should also talk to other orgs or other depts in your same org that have used your proposed solution and find out how useful it has been for them. If you do this research you will likely find that it hasn't met their needs at all.
And in your own org there are likely some applications with tables that already have such columns. Has anyone there EVER used those columns and found them invaluable for identifying and resolving any actual problem?
If you can't use them and their data for some important process why add them to begin with?
IMHO it is a total waste of time and resources to add such columns to ALL of your tables. Any such approach to auditing or security should, at most, be limited to those tables with key data that needs to be protected and only then when you cannot implement the proper 'best practices' auditing.
A migration is difficult enough without adding useless additional requirements like those. You have FAR more important things you can do with the resources you have available:
1. Capture ALL DDL for the existing system into a version control system
2. Train your developers on using the version control system
3. Determining the proper configuration of the new server and system. It is almost a CERTAINTY that settings will get changed and performance will suffer even though you don't think you have changed anything at all.
4. Validating that the data has been migrated successfully. That can involve extensive querying and comparison to make sure data has not been altered during the migration. The process of validating a SINGLE TABLE is more difficult if the table structures are not the same. And they won't be if you add two columns to every table; every single query you do will have to specify the columns by name in order to EXCLUDE your two new columns.
5. Validating the performance of the app on the new system. There WILL BE problems where things don't work like they used to. You need to find those problems and fix them
6. Capturing the proper statistics after the data has been migrated and all of the indexes have been rebuilt.
7. Capturing the new execution plans to use a a baseline for when things go wrong in the future.
If it is worth doing it is worth doing right. -
DB Diagram: Modality Difference between NOT NULL and check constraint
Hi,
I am using jdev 11g (11.1.1.10) I am trying to create a db diagram from two tables. I have a FK that is NOT NULL (defined on the column). When i try to display these two tables modality, it does not show up in the diagram. I noticed that there are two ways NOT null can be defined on a table (right click on the db object to edit it; a) under column definitions there is a check box for not null, b) there is a check constraint that one can add to do not null.
I am confused and was wondering whether I must I have check constraints on the database in order to display modality (optional versus mandatory). Logically speaking it does not make any sense though.Hi Susan,
Thanks for your email. I understand that in order to show modality under
UML notation, one must define a COLUMN being NOT NULL instead of defining a check constraint.
I still do not understand how modality (optional versus mandatory) is shown in ERD notation in JDev. I tried flipping ERD/UML notations and made sure icons for tables were showing, but no MODALITY is shown in ERD notation ( an '0" icon or a "|" icon for optional and mandatory). Is it the solid line versus dotted line in the ERD diagram? I am confused because generally under Crawfoot ERD notation '0" icon or a "|" icon is shown for modality.
Modality gets picked up in jdev diagram when COLUMN not null is specified and UML notation is used
ALTER TABLE DETAILAJ MODIFY EMPID not null;
Modality does not get picked up in jdev db diagram when check constraint is specified and UML notation is used
ALTER TABLE DETAILAJ
ADD CONSTRAINT CK_NN_DETAILAJ__EMPID CHECK(EMPID IS NOT NULL) ;
Another question i have related to the matter mentioned above is as follows. Since I want to see modality in db diagram, it follows that I must define a column as not null instead of a check constraint. I must also use NO VALIDATE on NOT NULL column because i have prior data that does not meet the new restriction. I noticed that if i use the following syntax to define a NOT NULL column, two things happen.
a) A constraint is defined as not null automatically and a system generated name is given to the constraint.
b) DB diagram in Jdev does not show the modality.
My question is whether there is a way to see modality in this case.
alter table DETAILAJ
MODIFY EMPID NOT NULL ENABLE NOVALIDATE ;
Edited by: user11219846 on Nov 19, 2009 11:07 AM
Maybe you are looking for
-
Speckles dust on the screen and it cannot be removed today when I decided to change the screen protector film and noticed is not my fault it is a factory defect on screen it is either dead pixel or speckle dust on screen they are so many said and exp
-
What's the difference between [ADSI] and [ADSISearcher] in powershell
Hi Guys What's the difference between [ADSI] and [ADSISearcher] in powershell
-
How to enforce SCN of a datafile to the latest value?
Hello, I try to restore old contents of my database on another server. The DB is not (and never was) in ARCHIVELOGMODE, and I have 2 cold backups of it. Neither backup set is complete (due to recycling of old tapes), but I still can restore all dataf
-
Are CIN's supported in Pocket PC LabView?
Is the function [Advanced>Code Interface Node] available in the LabView Pocket PC environment?
-
WWhy are some messages only coming through to my iPad and not my phone?