SQL & PL/SQL :: How To Delete Constraint

Apr 26, 2012

i have a problem that i have created a table named PROJECT and structure is like-
CREATE TABLE PROJECT
(
id VARCHAR2(250 BYTE) NOT NULL,
NAME VARCHAR2(250 BYTE) NOT NULL,
COMPID NUMBER NOT NULL,

[code]...

and this table is created in some number of different database then i want to delete the not null constraint of "id" column and there is 3 not null constraint in my table and i didnot gave name at the time of creation, so we cant delete it by its name in the script because there will be different name in another database for the same constraint. i want to make a script to delete the not null constraint because it is the part of my script.

how should i get proper information for deleting the constraint. and i used "user_constraints" but it shows same information for the all three "not null" constraint.

View 2 Replies


ADVERTISEMENT

Get Table Name / Constraint Name / Constraint Type With Join Processes In String Type

Dec 25, 2007

i want to get table name, constraint name, constraint type with join processes in string type. this is what i want: alter table tablename add constraint constraintname constrainttype(columnname)

View 1 Replies View Related

PL/SQL :: To Delete Child Records Manually Without Using Oracle Delete Cascade

Oct 9, 2012

I have to write a procedure that accepts schema name, table name and column value as parameters....I knew that i need to use metadata to do that deleting manually.

View 9 Replies View Related

SQL & PL/SQL :: Constraint - Getting Error?

Aug 14, 2013

Create table students
(
Sid number(3),
Sname varchar(20) not null,
Email varchar(20) not null,
Doj Timestamp default sysdate not null,
Dob date not null,

[code]....

when i run the above code i m getting error like this...I dont understand wat error it is...Because i didnt reference any column in the check constraint...Thn why it says that i m referencing some column..

Error:
SQL>
SQL> Create table students
2 (
3 Sid number(3),
4 Sname varchar(20) not null,

[code]...

View 2 Replies View Related

SQL & PL/SQL :: Foreign Key Constraint

Feb 3, 2012

I have a parent table called dept and one child table emp which is referenced on deptno and now both have data . Now i want to truncate the dept table and i have truncated emp table after it when i am trying to truncate dept table then oracle throws a error that is-

"ORA-02266: unique/primary keys in table referenced by enabled foreign keys" ,

but when i tried to delete some records 1 by 1 then these have delete but truncate is not still working. why? if i have 10 millon records.

View 4 Replies View Related

Creating Table With A Constraint?

Oct 16, 2006

how to i insert a constraint of words into the table example below.I am new to this stuff man.

Create table Orders
(
orderID Number(8) Primary Key,
orderDate Date Not Null,
methPmt Varchar2(10),
custID Number(5),
orderSource Number(2),
Foreign Key(custID) Reference Customer(custID),
Foreign Key(ordersource) Reference OrderSource(ordersource)
);

The catch is I am required to enter a constraint of the methPmt will only take values of "CASH", "CREDIT" or "CHEQUE" only.

How am I suppose to enter this constraint value into the creation of this table?

View 3 Replies View Related

Referential Integrity Constraint?

Mar 23, 2011

Can I apply Referential Integrity to only selected rows of a particular column? This is the reference key to the primary key to another table. But, the issue is, this reference column is not having mandatory data for all the rows. So, whenever this is null, I dont want it to be referred by parent table.

View 4 Replies View Related

Unique Constraint Violated?

Mar 26, 2007

From a step by step instructions I'm asked to put the following into sql*plus:

CREATE TABLE Lab2Lecturer
(staffNO VarCHAR2(10) NOT NULL,
title VARCHAR2(3),
fName VARCHAR2(30),

[code]...

Then the following:

INSERT INTO Lab2Lecturer
(staffNO, title, fName, lName, streetAddress, suburb, city, postCode, country, lecturerLevel, bankNO, bankName, salary, workLoad, researchArea)
VALUES
('1000', 'Dr', 'Johanna','Santoso',
'3 Robinson Av', 'Kew', 'Melbourne', '3080', 'Australia', 'C', '1000567237', 'CommBank', 65000.00,1.0, 'O-R DB');

and finally,

INSERT INTO Lab2Lecturer
(staffNO, title, fName, lName, streetAddress, suburb, city, postCode,country, lecturerLevel, BankNO,bankName, salary, workLoad, researchArea)
VALUES
('1000', 'Dr', 'Justine', 'Martin', '6 Algorithm AV', 'Montmorency', 'Melbourne', '3089', 'Australia', 'D', '1000123456', 'CommBank', 89000.00, 1.0, 'CBR');

when I try entering in the second one I get an error 'unique constraint violated'.So whats wrong exactly?

View 1 Replies View Related

Constraint Specification Not Allowed Here

Aug 4, 2011

SQL> create table emp_column_level_cons(empno number(4) constraint empcol_empno_pk primary key
2 ename varchar2(15) unique,
3 job varchar2(20) not null,
4 sal number(7,2) check (sal between 1500 and 25000),
5 deptno number(4) constraint empcol_deptno_fk foreign key re
ferences dept(deptno) on delete cascade);
deptno number(4) constraint empcol_deptno_fk foreign key references dept(deptno) on delete c
*
ERROR at line 5:
ORA-02253: constraint specification not allowed here

================================================

View 1 Replies View Related

SQL & PL/SQL :: Find Constraint Name Of A Table

Dec 24, 2010

I want to know constraint name of a particular table if it exists.Here are the queries that i tried to find the constraint name of a particular table but the results were 'no rows selected'.

Queries:

select constraint_name from user_cons_columns where table_name='x';
select constraint_name from user_constraints where table_name='x';

View 5 Replies View Related

SQL & PL/SQL :: How To Add Oracle Constraint To Tables

Jan 4, 2013

I have three tables:

A {op_id, op_name, .}
B {b_id, op_id, supplier_id, .}
C {c_id, op_id, op_id2, supplier_id, relation, .}

Table B and C have op_id which is foreign key from table A. In table A op_id is primary key, in table B b_id is primary key and in table C c_id is primary key. In table B supplier_id and op_id may have duplicate records. Now I want to add constraint so that if I delete records from Table B for op_id and if a relationship record exists for op_id in table C then it should not allow me to delete. Is it possible through referential integrity constraint ?

View 5 Replies View Related

SQL & PL/SQL :: Novalidate Constraint Method

Mar 4, 2011

NOVALIDATE CONSTRAINT METHOD.

Below is the step i gone through:

1) CREATE TABLE mutu (id NUMBER, text VARCHAR2(20));

2) INSERT INTO mutu SELECT rownum , 'mutu' FROM dual CONNECT BY LEVEL <= 10000;

3) Insert Duplicate row.
INSERT INTO mutu VALUES (42, 'DUPLICATE');

4) COMMIT;

5)Create a NON-UNIQUE INDEX's CONSTRAINT as below.
ALTER TABLE mutu ADD CONSTRAINT mutu_pk PRIMARY KEY(id)
USING INDEX(CREATE INDEX mutu_pk ON mutu(id)) ENABLE NOVALIDATE;

6) Insert Duplicate row.
INSERT INTO mutu VALUES (42, 'DUPLICATE');

7) ERROR at line 1:
ORA-00001: unique constraint (SYS.ZIGGY_PK) violated

Why it shows the error. Even though I had created a NON-UNIQUE INDEX's Constraint only.

View 2 Replies View Related

PL/SQL :: Unique Constraint Violated

Oct 4, 2013

My DB version is

BANNER                                                     
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production                       
CORE 10.2.0.4.0 Production                                     
TNS for Linux: Version 10.2.0.4.0 - Production               
NLSRTL Version 10.2.0.4.0 - Production  

These error codes I'm getting in production.First of all, I've no duplicates present in that table for which this error has been raised.I've checked the index and related columns as well. NO DATA is there.So NO CHANCE for unique constraint violation.

SELECT * FROM ORDER_OCC_REQUISITION_X_REF WHERE LAB_ORDER_OCC_TEST_ID IN(SELECT LAB_ORDER_OCC_TEST_ID FROM LAB_ORDER_OCC_TEST WHERE LAB_ORDER_OCC_ID = 7944858);

no rows selected

 Now when I'm trying to insert one row inside this table I'm getting this error, as you are seeing no records for this occurrence_id. 

SELECT * FROM USER_INDEXES WHERE INDEX_NAME = 'ORD_OCC_REQ_UQ_TEST_IX_04';
--ORDER_OCC_REQUISITION_X_REF (Table name)
--MERGE_DT, LAB_ORDER_OCC_TEST_ID, TEST_ID, ACTIVE_YN (columns for the index 'ORD_OCC_REQ_UQ_TEST_IX_04')
As you can see there is no data then this error should not be raised.  Update procedure.
/*******************************************************************************************************************
     * Name                    : UPDATE_REQUISITION_X_REF
     * Description             : This Procedure update ORDER_OCC_REQUISITION_X_REF table with requisition_id
     *                           that was generated due to merge process.
     * In  parameters          : IN_merge_id         NUMBER   The order_ref_no of the orders to be merged (comma seperated)
     ***********************************************************************************************************************/
    PROCEDURE   UPDATE_REQUISITION_X_REF ( IN_merge_id  IN TT_ORD_REQUISITION_WORK_AREA.merge_id%TYPE)
    IS
  
[Code]....

View 8 Replies View Related

SQL & PL/SQL :: Name Of Primary Key Constraint Is ID_PK

Jul 31, 2010

I have a table say EMP with 2 fields ID and Name, with ID being the primary key. The name of the primary key constraint is ID_PK.Now my scenario is :

1. Rename the table EMP to EMP_TEMP;
2. Create an empty table EMP
3. If (data successfully loaded into EMP)
{
Drop EMP_TEMP;
}
else
{
Drop EMP;
Rename EMP_TEMP to EMP;
}

The problem here for me is the primary key constraint. When I am in 2, I cannot create the primary key constraint again since the old one is still in tact. If I go ahead to drop the original pk constraint and re-create a new one in 2, then in case of else part , I need to get the constraint again while renaming the original table.

View 6 Replies View Related

SQL & PL/SQL :: Facing Complex Constraint?

Sep 27, 2013

I have folliwng table
CREATE TABLE abcd
(
trans_type VARCHAR2(10) nn,
original_tran_no NUMBER,
original_line_item NUMBER(20),
original_trans_dt DATE);

I have to create a constraint when trans_type = 'R'then (original_tran_no and original_trans_dt ) should be not null else can be null able; is the follwing stmt right?

alter table abcd add constraint t1_chk1
check (
( case when trans_type = 'R' then (original_tran_no is not null
and original_trans_dt is not null))

View 10 Replies View Related

SQLPlus - How To Create New Table With Constraint

Mar 25, 2009

I'm trying to create a new table which has a date field (date of birth) and I want to include a constraint which will not allow me to add values if they are over 21 years old. I'm using SQLPlus .

View 3 Replies View Related

RMAN Unique Constraint Violation

Aug 23, 2011

Our RMAN backup failed because of the error:

starting full resync of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 08/22/2011 22:19:07
RMAN-03014: implicit resync of recovery catalog failed
RMAN-03009: failure of full resync command on default channel at 08/22/2011 22:19:07
ORA-00001: unique constraint (ODBA.DF_U2) violated

Searching metalink, its related to bug 6014994 and the proposed workaround is to delete the constraint:

Cause:
Dropping a datafile from a tablespace followed immediately by adding
another datafile to the same tablespace will cause this Unique Key violation.
Taking a RMAN debug trace will show the file# related to the error
This is reported as bug <<6014994>> Unpublished on Metalink and fixed in 11g
RMAN RESYNC catalog signals DF_U2 violated constraint when a file# is reused in
the same tablespace
Solution
WORKAROUND: Drop df_u2 constraint

where can I delete the constraint, is it possible to do in RMAN or in the target instance?

View 1 Replies View Related

How To Handle Unique Constraint Violation

Feb 5, 2013

I've set up Oracle Streams replication between multiple N-way zones like this:

CODE------------------------------
Nway1 |Intersect| Nway2
DB1 --|-- DB3 --|-- DB5              DB1, DB2, DB3, DB4 - N-way1
  |   |    |    |    |               DB3, DB4, DB5, DB6 - N-way2
DB2 --|-- DB4 --|-- DB6              DB3, DB4 - intersection zone
      |         |  
-------------------------------

Physically DB1 .... DBN connected sequentially, so I want to prevent segmentation if some DB is unaccessible, but at the same time fight unneeded redundancy which uses too much link bandwidth to send N-1 LCR-s to all members of a single N-way group (so I want to split one big N-way zone into smaller ones and sequentially connect them into chain - it significantly reduces load on link if N is big enough (>10)). Also I want to have 2 DB in intersection zone to prevent single point of failure.

This scheme has one drawback - if change originated on DB3 or DB4, then it will be propagated (more correctly - applied and captured again) to DB5 and DB6 by both DB1 and DB2 (and, as far as I know, I have no means in capture rules to detect state of DB2 from DB1 and vise versa), so on DB5 and DB6 I get:

CODEORA-00001: unique constraint (DUMMYUSR.UNIQUE_RECORDS) violated error

I've set up standard conflict handler for apply process:

CODE

declare                                                                                        
    cols DBMS_UTILITY.NAME_ARRAY;                                                              
begin                                                                                          
    cols(1) := 'no';                                                                          
    cols(2) := 'name';                                                                        
    cols(3) := 'ddate';                                                                        
    dbms_apply_adm.set_update_conflict_handler(                                                
        object_name       => 'DUMMYUSR.DUMMYTBL',                                              
        method_name       => 'DISCARD',                                                        
        resolution_column => 'no',                                                            
        column_list       => cols                                                              
    );                                                                                        
end;

but it seems that it does not handle uniqueness conflicts. What is the best way to handle uniqueness conflict (is there a better way than to write custom error handler) and how serious is the impact on insert performance of having unique constraint and corresponding error handler. (In real world I will have to deal with tables with metainformation and without any keys).

Also, how to proceed with no error or raise exception from apply error handler with error that caused this handler to run? In oracle docs I can find only example that modifies LCR and runs lcr.EXECUTE(TRUE), but what to do if I don't want to reexecute LCR, but merely check error code and propagate error if it is not ORA-00001?

View 1 Replies View Related

Row Violations Due To Referential Integrity Constraint?

Feb 2, 2012

Referential Integrity is very important in Oracle database. Consider a scenario where constraints were applied to a database but never enforced on. Only application code was leveraged over the past 1 year to manage this logic.

Over the course of the year there might have been lot of Row Violations which might have led to Data Inconsistency Issues.Do we have a Script, Tools in Oracle which flag all row level violations with referential integrity now being turned on.

View 1 Replies View Related

Add Constraint Default Value For Table Column With Name?

Oct 26, 2009

I would like to add a constraint "default value" for a table column, with a name.

I know how to do it for a constraint "not null" : ALTER TABLE tablename MODIFY columnname CONSTRAINT constraintname NOT NULL;

But I don't know how to do it for a constraint "default value".How can I do ?

View 2 Replies View Related

ORA-00001 - Unique Constraint Violated

May 14, 2010

I have faced an error as below:-

1 : 23000 : java.sql.BatchUpdateException: ORA-00001: unique constraint (SDS1.PK_EXP_TXT) violated
1 : 23000 : java.sql.SQLException: ORA-00001: unique constraint (SDS1.PK_EXP_TXT) violated
java.sql.BatchUpdateException: ORA-00001: unique constraint (SDS1.PK_EXP_TXT) violated
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9119)
[Code] ......

After i check data in all_indexes table, i have found some old data which are belongs to 2008 and 2009. The sample as below:-

OWNER INDEX_NAME LAST_ANALYZED
SDS1PK_ACTION 31-OCT-09 07:04:49
SDS1AK_ACTION 31-OCT-09 07:04:49
SDS1PK_COND 31-OCT-09 07:04:50
SDS1AK_COND 31-OCT-09 07:04:50
SDS1COND_FK1 31-OCT-09 07:04:50
SDS1COND_FK2 31-OCT-09 07:04:50

is it the problem due to the old data not remove from the all_indexes table ?.. if YES is it I have to delete the old data manually from the all_indexes table ?

View 7 Replies View Related

SQL & PL/SQL :: Modifying Existing Constraint On Table

Apr 1, 2013

Can we modifying the existing constraint on table?I have table level UNIQUE constraint on 3 columns of table.I need to modify the UNIQUE constraint to 2 columns? Instead of dropping/recreating the constraint, is there any option to modify the existing constraint

Ex

CREATE TABLE TEST_CONST(NUM1 NUMBER , NUM2 NUMBER , NUM3 NUMBER , UNIQUE (NUM1 ,NUM2,NUM3)); ;

SELECT * FROM USER_CONS_COLUMNS UCC WHERE UCC.TABLE_NAME LIKE 'TEST_CONST';

ALTER TABLE TEST_CONST MODIFY CONSTRAINT SYS_C0025132 UNIQUE(NUM1,NUM2);

ORA-00933: SQL command not properly ended

Third statement is not executing fine .

View 1 Replies View Related

SQL & PL/SQL :: Get The Rows That Produced A Constraint Violation

Nov 5, 2012

drop table t1
/
create table t1
(
id int PRIMARY KEY
)
/
insert into t1
select 1
from dual
union all
select 2
from dual
union all
select 2
from dual
union all
select 3
from dual
/

ERREUR à la ligne 1 :
ORA-00001: violation de contrainte unique (SYSTEM.SYS_C0011990)

how to get the rows that produced the constraint violation ?

View 10 Replies View Related

SQL & PL/SQL :: Which Constraint For Bitmap Join Indexes

Jul 18, 2013

I have a few dimension tables with surrogate keys and a fact table with foreign keys on columns referring to the dimension table. I want to create primary keys on the dimension tables and foreign keys on the fact table, but with minimal overhead of constraint validation when loading the data.

Other than bitmap indexes on the FK columns on the fact table, I also want to create a bitmap join index on the fact table joined to the dimension table on a handful of dimension columns.

Which is the best suited constraint definition? Only RELY, or RELY + DISABLE, or RELY + DISABLE + NOVALIDATE, or RELY + NOVALIDATE, or any other?

View 9 Replies View Related

SQL & PL/SQL :: Unique Constraint When 1 Column Is Not Null

Jun 15, 2012

I have 3 columns in a table: colX, colY, colZ.

Trying to find a way to prevent duplicates with these, but only if colX is not null.

For example, if there are already values for: colX = 1, colY = 1, colZ = 1

then:

Allowed: colX = null, colY = 1, colZ = 1
Not allowed: colX = 1, colY = 1, colZ = 1

I can't create a unique constraint on these columns because there are many null values for column colX, and as mentioned, when colX is null, colY and colZ can be any values.

I also tried using a before insert trigger to find duplicates before posting and raise an error if found, but this causes an ORA-04091 mutating error since the trigger in the table is referencing itself to check for duplicates.

Also, I know there is something called a function based index, but I cannot use those with my code, so I need another solution if possible.

View 4 Replies View Related

SQL & PL/SQL :: Enabling Constraint With Enable No Validate?

Sep 5, 2013

Is there any way to enable the constraint with out validating for the existing information.

As We can accomplish the same functionality when we are adding the constraint for the first time.

Ex: alter table scott.emp add constraint fk_deptno foreign key(deptno) references scott.dept(deptno) enable novalidate

The above SQL statement will enable the constraint with out validating for the existing information. So there is possibility of data will be there only in the child table but not in the parent table for existing information.

But in the future it will not allow to do so,if the constraint is in ENABLE staus.So i am just trying to disable the constraint to insert only into child table & trying to enable it with NOVALIDATE option .

But the following exception is coming .

SQL> alter table scott.emp ENABLE constraint fk_deptno enable NOVALIDATE;

alter table scott.emp ENABLE constraint fk_deptno enable NOVALIDATE

ORA-00905: missing keyword

SQL> alter table scott.emp ENABLE constraint fk_deptno NOVALIDATE;

alter table scott.emp ENABLE constraint fk_deptno NOVALIDATE

ORA-00933: SQL command not properly ended

Instead of dropping & recreating the same constraint , is there any alternate way to do this ?

View 3 Replies View Related

SQL & PL/SQL :: ORA00001 Unique Constraint Violated

Nov 4, 2012

I also put in the relevant code in case it's needed.

SQL> @lab_05_01.sql
SQL> -- Oracle Database 10g: Administration Workshop II
SQL> -- Oracle Server Technologies - Curriculum Development
SQL> --
SQL> -- ***Training purposes only***
SQL> -- ***Not appropriate for production use***
SQL> --
SQL> -- This script performs a batch promotion update.
SQL> -- The logic of the updates is not important -

[code]....

View 2 Replies View Related

SQL & PL/SQL :: Temporary Disable All Constraint In Particular Table?

Jan 7, 2012

i have one table HR.employees

SQL> desc hr.employees
Name Null? Type
----------------------------------------- -------- ----------------------------

EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)

SQL>

in this table i want to temporary disable all constraint in this employees table

View 4 Replies View Related

SQL & PL/SQL :: Possible To Get Exact Name Of Constraint From Any System Table

Sep 1, 2010

There was one constraint define on the column of table that the value of column should be in range of 100 to 200. Some one has deleted the constraint. Is it possible to get the exact name of constraint from any system table.

View 7 Replies View Related

SQL & PL/SQL :: Create A Table With Constraint And Index

Apr 7, 2010

I use Oracle 10.0.2.0.1.If I create a table with constraint key; after that I create an unique index key, I got an error. Does it mean when I create a table with constraint the unique index are automatically created and I could not create index key as I did as below?

create table test_const(ename varchar2(50) not null,
key_num number not null,
descr varchar2(100),
constraint constraint_test_const unique (ename, key_num));
create unique index test_const_idx on test_const
(
"ENAME","KEY_NUM"
)
tablespace tmp_data;

Error report: SQL Error: ORA-01408: such column list already indexed 01408. 00000 - "such column list already indexed" added [pre] tags by Sriram

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved