Doubts on constraints
Hi All,
i have table structure like below. i need to create unique constraint on the below 3 columns(combined). Will i be able to create? i am having a doubt because since one column is nullable, can i create unique constraint on all 3 columns?
if yes, then how can i create it?
column_name Null
col A N
col B N
col C Y
user12133456 wrote:
Hi All,
i have table structure like below. i need to create unique constraint on the below 3 columns(combined). Will i be able to create? i am having a doubt because since one column is nullable, can i create unique constraint on all 3 columns?
if yes, then how can i create it?
column_name Null
col A N
col B N
col C Y
Yes you can.Unique constraint can contain null but primary not.
SQL> conn test/sm
Connected.
SQL> create table test(col1 number not null,col2 number,coll3 varchar2(50));
Table created.
SQL> alter table test add constraint uk_test unique (col1,col2,col3);
alter table test add constraint uk_test unique (col1,col2,col3)
ERROR at line 1:
ORA-00904: "COL3": invalid identifier
SQL> alter table test add constraint uk_test unique (col1,col2,coll3);
Table altered.
SQL>Edited by: Chinar on Aug 9, 2010 6:54 AM
Similar Messages
-
Doubt on Constraints in Oracle?
Hi Friends,
Constraints are the business rules that are enforced on the data that is stored in the tables.
We can define constraints in three forms :
1.using Constraint feature provided by Oracle i.e CHECK,NOT NULL,PRIMARY KEY .....
2.Using Triggers in the database
3.Writing the logic at the Application Level.
Among all these only (1) is preferred,why?
what exactly is the difference in the above approaches?
Are the remaining approaches time consuming ?The main reason why CONSTRAINTS are to be preferred over TRIGGERS or other approaches is that it is the accepted approach to solving the problem. The fact that constraints are faster than triggers is noteworthy but irrelevant. Relational theory uses keys to assert relational integrity: constraints are the way to implement those keys. If I was looking at a new system I would expect to see keys in the data model implemented as constraints in the schema. I would not expect nor want to have to look at triggers to see what relational integrity is enforced.
Using triggers instead of constraints is possible but it is like driving on the wrong side of the motorway: it's harder, it's dangerous and only a fool or a drunk would choose to do it.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Hi All,
Say suppose i have a table called T1. in that table i have a column called region. And lets say that region column is linked to multiple tables as foregin key.
Now, i want to know what are all the table names that this column is linked to ? i checked all_constraints view but i couldnt see the foregin key link relationships.
Regards,
HariThis may help you!
with temp_constraints as (
select table_name
, constraint_name pkey_constraint
, null fkey_constraint
, null r_constraint_name
from user_constraints
where constraint_type = 'P'
union all
select a.table_name
, a.constraint_name pkey_constraint
, b.constraint_name fkey_constraint
, b.r_constraint_name
from user_constraints a, user_constraints b
where a.table_name = b.table_name
and a.constraint_type = 'P'
and b.constraint_type = 'R'
select rpad( '*', (level-1)*2, '*' ) || table_name relation
from temp_constraints
start with fkey_constraint is null
connect by pkey_constraint< r_constraint_name
and prior pkey_constraint = r_constraint_namePS: Not my original. Posted in this forum long ago. -
Constraint Violation During Replication Causing In-Doubt
I keep getting a lot of In-Doubt transaction when a constraint is violated any one had this problem.
Using 10gr2 RAC
DISTRIB TRAN HOUDB.GRANTPRIDECO.CC.5c25b283.23.10.37105
is local tran 23.10.37105 (hex=17.0a.90f1)
change pending prepared tran, scn=1619261224 (hex=0.6083f728)
to pending forced commit tran, scn= (hex=0.00000000)
Thu Feb 2 14:42:42 2006
Error 2091 trapped in 2PC on transaction 27.32.28016. Cleaning up.
Thu Feb 2 14:42:42 2006
DISTRIB TRAN HOUDB.GRANTPRIDECO.CC.5c25b283.27.32.28016
is local tran 27.32.28016 (hex=1b.20.6d70)
insert pending prepared tran, scn=1619273067 (hex=0.6084256b)
Thu Feb 2 14:42:42 2006
Error stack returned to user:
ORA-02054: transaction 27.32.28016 in-doubt
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (BITTRK25.RN_B_FK) violated - parent key not found
ORA-02063: preceding 2 lines from SThu Feb 2 14:54:23 2006I keep getting a lot of In-Doubt transaction when a constraint is violated any one had this problem.
Using 10gr2 RAC
DISTRIB TRAN HOUDB.GRANTPRIDECO.CC.5c25b283.23.10.37105
is local tran 23.10.37105 (hex=17.0a.90f1)
change pending prepared tran, scn=1619261224 (hex=0.6083f728)
to pending forced commit tran, scn= (hex=0.00000000)
Thu Feb 2 14:42:42 2006
Error 2091 trapped in 2PC on transaction 27.32.28016. Cleaning up.
Thu Feb 2 14:42:42 2006
DISTRIB TRAN HOUDB.GRANTPRIDECO.CC.5c25b283.27.32.28016
is local tran 27.32.28016 (hex=1b.20.6d70)
insert pending prepared tran, scn=1619273067 (hex=0.6084256b)
Thu Feb 2 14:42:42 2006
Error stack returned to user:
ORA-02054: transaction 27.32.28016 in-doubt
ORA-02091: transaction rolled back
ORA-02291: integrity constraint (BITTRK25.RN_B_FK) violated - parent key not found
ORA-02063: preceding 2 lines from SThu Feb 2 14:54:23 2006 -
I have a table say OLD_TABLE. Now I want to create another table say NEW_TABLE which should be EXACTLY the same as OLD_TABLE. When I say "EXACTLY" the same I mean the data type of all the columns, Constraints (if any), primary key and foreign keys (if any) and every other thing must be the same as OLD_TABLE. Only the rows (or data) will differ between OLD_TABLE and NEW_TABLE and nothing else.
What query should I ues to acheive this? Pls advice!
Edited by: TuX4EvA on Dec 18, 2009 2:00 AMYou may want to have a look at DBMS_METADATA package.
As an example:
sql> set long 4000
sql> select dbms_metadata.get_ddl('TABLE','EUL_GW_COLS','ODM_USER') from dual;
DBMS_METADATA.GET_DDL('TABLE','EUL_GW_COLS','ODM_USER')
CREATE TABLE "ODM_USER"."EUL_GW_COLS"
( "C_O_SCHEM_NAME" VARCHAR2(64) NOT NULL ENABLE,
"C_O_OBJ_NAME" VARCHAR2(64) NOT NULL ENABLE,
"C_COL_NAME" VARCHAR2(64) NOT NULL ENABLE,
"C_SQL_DERIVATION" VARCHAR2(240),
"C_DATATYPE" VARCHAR2(70) NOT NULL ENABLE,
"C_NULL_INDICATOR" VARCHAR2(10) NOT NULL ENABLE,
"C_HIDDEN" VARCHAR2(1) NOT NULL ENABLE,
"C_LENGTH" NUMBER(22,0),
"C_DECIMAL_PLACES" NUMBER(22,0),
"C_DISP_NAME" VARCHAR2(100),
"C_HEADING" VARCHAR2(240),
"C_DESCRIPTION" VARCHAR2(240),
"C_DISP_SEQ" NUMBER(22,0),
"C_DISP_LENGTH" NUMBER(22,0),
"C_CASE_DISPLAY" VARCHAR2(10),
"C_CASE_STORAGE" VARCHAR2(10),
"C_ALIGNMENT" VARCHAR2(10),
"C_FORMAT_MASK" VARCHAR2(100),
"C_C_LOV_SCHEM_NAME" VARCHAR2(64),
"C_C_LOV_OBJ_NAME" VARCHAR2(64),
"C_C_LOV_COL_NAME" VARCHAR2(64),
"C_DEF_ROLLUP_FUNC" VARCHAR2(70),
"C_DISP_NULL_VALUE" VARCHAR2(240),
"C_ORD_CLAUSE_POS" NUMBER(22,0),
"C_ORD_DIRECTION" VARCHAR2(10),
"C_PLACEMENT" VARCHAR2(10),
"C_CONTENT_TYPE" VARCHAR2(100),
CONSTRAINT "EUL_GW_COLS_UNQ" UNIQUE ("C_O_SCHEM_NAME", "C_O_OBJ_NAME", "C_COL_
NAME")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"It will give you the exact DDL to create the same table with all the constraints in place including primary keys, foreign keys and not nulls.
You will only need to replace the names for anything suitable to you.
LW -
Is correct?
CREATE TABLE CONTROLE_USUARIO_LOGADO(USUARIO VARCHAR2(30) NOT NULL,SENHA VARCHAR2(20) NOT NULL,SERIAL VARCHAR2(30) NOT NULL,STATUS SMALLINT);
ALTER TABLE CONTROLE_USUARIO_LOGADO ADD CONSTRAINT PK_CONTROLE_USUARIO_LOGADO PRIMARY KEY(USUARIO,SENHA,SERIAL);
ALTER TABLE CONTROLE_USUARIO_LOGADO ADD CHECK(STATUS IN(0,1)) ENABLE;declare
meant_syntactically boolean := true;
begin
if meant_syntactically
then
dbms_output.put_line('Yes.');
MHO%xe> CREATE TABLE CONTROLE_USUARIO_LOGADO(USUARIO VARCHAR2(30) NOT NULL,SENHA VARCHAR2(20) NOT NU
LL,SERIAL VARCHAR2(30) NOT NULL,STATUS SMALLINT);
Tabel is aangemaakt.
Verstreken: 00:00:02.98
MHO%xe>
MHO%xe> ALTER TABLE CONTROLE_USUARIO_LOGADO ADD CONSTRAINT PK_CONTROLE_USUARIO_LOGADO PRIMARY KEY(US
UARIO,SENHA,SERIAL);
Tabel is gewijzigd.
Verstreken: 00:00:00.65
MHO%xe>
MHO%xe> ALTER TABLE CONTROLE_USUARIO_LOGADO ADD CHECK(STATUS IN(0,1)) ENABLE;
Tabel is gewijzigd.end if;
exception
when others
then
please elaborate/pinpoint/clearify the exact problem;
raise;
end; -
Hi ALL,
Doubt in GREP:
Working in Glossary, my requirement is upto first colon ":" i want to apply characterStyle after that give "Em Space".
How can we find first colon or commo etc.
I am using Zero or One Time1. I have never, ever, used Data Merge. Can you supply sample files and a written explanation of each of the eight items in the Data Merge menu? I can't promise I'll ever need it, but thanks anyway.
2. Please, please, do not use the word "doubt" Ever Again. I seriously doubt you know how to use it correctly. Use "question" if you are in doubt about when to use it correctly. Thank you. (Should you doubt my knowledge of English, then you are correct -- I'm not a native speaker either. But as you can see practise obviosly makes perfect.)
3. InDesign Help has all the proper help on GREP. It's right here: http://help.adobe.com/en_US/InDesign/6.0/WS1952D538-1335-4b1d-BA5E-FA5A176FDC9Fa.html and I got that by typing in "GREP" in the Help search box.
4. Why would anyone need a file and a list of examples telling how to use these particular parts of GREP? It's rather the other way around: if you need something that cannot be done with a regular search, read the help on GREP (see above) and check if the functions and constraints for each of these match your requirements. If so, there are usage samples on the Help page; and if not, it probably cannot be done, or you are looking at it the wrong way. -
How to create an in-doubt transaction?
I need to create/force an MSDTC in-doubt distributed transaction to verify that they are resolved automatically. The code successfully participates in the transaction via OraMTSSvcGet and OraMTSSvcEnlist and works as expected. I have tried creating in-doubt transactions via constraint violations, table locking, killing the application, killing the Oracle session, etc. but can't force an error between the first and second phase of the commit( which I think is the trick). Any ideas?
Message was edited by:
jgbellIf your site is dynamically populated with content from server-side databases, it's not hard.
If your site is static, a 3rd party search function might be a better choice until you're ready to build a dynamic site.
Zoom search engine
http://www.wrensoft.com/zoom/
Freefind
http://www.freefind.com/
Setting up a PHP environment in Dreamweaver
http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
Building your first dynamic website – Part 1: Setting up your site and database connection
http://www.adobe.com/devnet/dreamweaver/articles/first_dynamic_site_pt1.html
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
http://alt-web.com/
http://twitter.com/altweb -
Regarding Constraints in database ( increase or decrese performance)
Hi all
i want to ask one thing that should be use constraints in our tables?
I have a doubt that when we query that particular table then all the containts are also accessed...
In other case if we use less constraints then it will increse the performance or not ?
Regards
GurmeetFree cheese is only in mousetrap. For everything other you have to pay somehow. Including constraints. Including Oracle db as such. MySQL most probably will work faster than Oracle.
So choose either db with constraints and a bit slower DML (INSERTS, UPDATES, DELETES, and not queries, i.e. SELECTS), or data waste instead of data base.
Gints Plivna
http://www.gplivna.eu -
What is the use of security-constraint tag in web.xml
what is the use of following tag , and how to use that, and where to use that tag.
<web-resource-collection>
<web-resource-name>SecureOrderJSP</web-resource-name>
<descrip<url-pattern>/order/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name></role-name>
</auth-constraint>
</security-constraint>tion>Protect the Order JSP Pages </description>Hi,
You can refer this link
http://www.whizlabs.com/tutorial/scwcd/j-scwcd-7-5.html
give the complete description of your doubt
Thanks,
Snigdha Sivadas -
Basic doubt about Primary Keys/Foreign Keys in Oracle Tables
Hi,
I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle or not. I have been informed that Oracle does not encourage having Primary Keys/Foreign keys in its database tables. Instead it urges users to have unique constraints on the requisite columns.
However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. At the same time, I am being told that ETRM is not a reliable way of having correct information about table structure (at least the Primary Key information).
It would be nice if any one of you provides me with some insight in this. Any pointers to a document would be welcome.
ThanksFYI,
There is seprate forum for Core Sql quieries
PL/SQL
Thanks -
hi gurus ,
there is some doubt in Time constraints 1 , 2 and 3 . Can u plz Give me detail of time constraints with example so that it can clear the picture.
thanks and regards.
RuchiHi Ruchi,
Time constraint 1: No overlapping and no gaps.
Exactly one valid data record of the infotype in question must exist for the entire time that the employee belongs to the enterprise.
Time constraint 2: No overlapping but time gaps are permitted.
No more than one valid data record of the infotype in question can exist at any one time.
Time constraint 3: Overlapping and and time gaps are permitted.
Any number of valid data records of the infotype in question can exist at any one time.
With luck,
Pritam. -
Doubts in Management of global employees
Dear Experts,
im trying to configure Global employment in my system.
Here im having some doubts in the execution of Global employment.
the doubts are...1.Shall we need to configure seperate actions for the management of global employees and what are the specific infotypes for the actions.
2.How to activate the global employment in the system.
Kindly share your valuable advices.
Regards,
V Sai.Hope it helps
Payroll for Global Employees This component is not released for all customers. For more information, read SAP note 518503.
You use this component to run payroll for your global employees.
Implementation Considerations:
To implement this component you must activate it in your system. Access Customizing for Payroll and choose Payroll International --> Payroll for Global Employees, and perform the IMG activity Activate Payroll for Global Employees. You make other settings for this component in the same section.
Integration:
You can implement Payroll for Global Employees irrespective of whether you administer your global employees with the component Management of Global Employees or in some other way in the system.
Features:
For Payroll for Global Employees payroll is usually run in two countries. There is data exchange between two payroll systems. Data is exchanged in the form of wage types.
u2022 The sending payroll creates the wage types and stores them in table RT_GP (Results Table: Payroll for Global Employees).
u2022 The receiving payroll imports the wage types from the sending payroll and processes them further.
Use function XGP (Payroll for Global Employees) to transfer wage types from the sending payroll to the receiving payroll and to process them within the receiving payroll.
All features that are included in the appropriate Payroll country version are available in sending and receiving payroll. For more information, see Payroll country versions in the SAP Library under Human Resources --> Payroll --> Payroll <Country>.
Constraints:
At present you can only transfer wage types from the sending to the receiving payroll. Data exchange in two directions is not possible.
Example
Employees in your German firm are usually seconded to your subsidiary company in the USA for three to five years. The remuneration of these global employees is calculated in the Payroll of the US company. Payment is also effected in the USA. However, the employee also pays social insurance contributions in Germany during his overseas assignment. These social insurance contributions are calculated in the German payroll system, and transferred to the American payroll system. They are settled there with the remuneration of the employee. In this case the German payroll is the sending payroll system, and the American payroll is the receiving payroll system.
Execute the relevant personnel action or choose Human Resources > Personnel Management > Administration > HR Master Data > Maintain.
2. If you have chosen to maintain the infotype manually, enter the global employeeu2019s personnel number and choose infotype Global Assignment Details (0710).
3. Click Create.
4. Enter the data with regard to the global assignment and check their consistency. Note that the system automatically determines the end date of the assignment on the basis of the duration you have entered.
5. Enter the applicable employment percentage in the host country.
6. Enter the current personnel number the global employee is assigned to in the host country. For more information on how to use these fields, see the F1 documentation.
7. Click Save.
Maintaining the Global Assignment Status
In this step, you maintain the current status of the global assignment according to HR processor.
Procedure
1. Execute the relevant personnel action or choose Human Resources > Personnel Management > Administration > HR Master Data > Maintain.
2. If you have chosen to maintain the infotype manually, enter the global employeeu2019s personnel number and choose infotype Global Assignment Status (0715).
3. Click Create.
4. Select the applicable assignment status.
5. Click Save.
Copied from the previous Threads -
Constraints Problem in DOP table - Help
Sir,
I need to import a new table dump (Status.dmp) to USER1's schema.
USER1 is already having STATUS table (with STATUS_ID column is PRIMARY
KEY.)
I tried to drop table STATUS.
USER1> drop table status;
drop table status
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
Please clarify my doubts:-
1. How to find the FOREIGN KEY constraints related with STATUS.STAUS_ID.
2. What all steps I have to follow to drop this table.
I did the following steps:-
1. Disabled PRIMARY KEY constraint of SATUS table.
2. Tried to drop the table
drop table status
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
1. Enabled PRIMARY KEY constraint of SATUS table.
2. Disable all FOREIGN KEY constraints in USER1's schema
(By looking into USER_CONSTRAINTS.CONSTRAINT_TYPE='R'
3. Tried to drop the table
drop table status
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
1.Disable all FOREIGN KEY constraints in USER1's schema
(By looking into USER_CONSTRAINTS.CONSTRAINT_TYPE='R'
2. Dleted all the rows in STAUS Table.
3. Tried to drop the table
drop table status
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
4. Imported the dump file with IGNORE=Y
5. Impor wirk fine.
Enabled all disabled constrains.
regards,
MathewWill it disable the constraints of child table?SQL> create table one(cd number constraint one_pk primary key, nm varchar2(10));
Table created.
SQL> create table two(cd1 number,nm1 varchar2(10), constraint two_ref foreign key (cd1) references one(cd));
Table created.
SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME,SEARCH_CONDITION from user_constraints where table_name in ('ONE','TWO');
CONSTRAINT_NAME C TABLE_NAME SEARCH_CONDITION
ONE_PK P ONE
TWO_REF R TWO
SQL> drop table one cascade constraints;
Table dropped.
SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME,SEARCH_CONDITION from user_constraints where table_name in ('ONE','TWO');
no rows selected
Cheers, Bhupinder -
Hi,
I am dynamically entering table name in my form, according to the table entered i want to retrieve number of columns processed by form. e.g count(*)
select count (*) from :tab_name;
this query does not work, what is the other way to retrieve table name dynamically & then process it?
My second doubt is how to display oracle errors like unique constraint violated, referential integrity violated through forms. I have used message(sqlerrm). but it shows, "Nomal, successful completion". Any other in-built function provided by forms?
Regards.You can use dynamic SQL to pass a table name within a PL/SQL code.
for your second question you can use a form level ON-ERROR trigger with ERROR_CODE, ERROR_TEXT, SQLCODE, SQLERRM and DBMS_ERROR_CODE, DBMS_ERROR_TEXT.
Explanations are found in the forms online help.
Also Steve Cosner has a nice knit code for displaying errors with the ON-ERROR trigger in a custom way. check it out.
Re: FRM-40735:Pre_Insert trigger raised unhandled exception ORA-20011
Hope this helps.
Tony Garabedian
Maybe you are looking for
-
LYNC 2010 on Supportability on Windows 2012 R2
Is it possible to run Lync server 2010 on Windows server 2012 R2? Is there any known issues running LYNC 2010 Enterprise pool with Enterprise Voice on Windows 2012 R2 OS? Any special requirements or issues installing LYNC 2010 on Windows 2012 R2? We
-
How do I change the display order in the VPN menu in the status bar?
Hello, How do I change the display order in the VPN menu in the status bar? (in the drop-down menu from this icon) -> Thanks.
-
HT1430 Why won't my itunes open on my Iphone5 anymore????
Can somebody please help me?
-
Power on, on a timer.
Does anyone know how to set up my mac to turn on, on a timer?
-
How to convert JPanel code into JApplet?
i made a graph in JPanel.now i want to call that graph in my jsp page. for this purpose i need to convert that JPanel graph into JApplet. does anyone knows about this... regards