Guest tao Posted April 11, 2006 Share Posted April 11, 2006 Hi ,how can i get from specific table the Primary Key field name, by SQL Query?thanks,Tao Link to comment Share on other sites More sharing options...
aspnetguy Posted April 11, 2006 Share Posted April 11, 2006 I don't think you can.Why do you need to? Link to comment Share on other sites More sharing options...
sivasairam Posted April 13, 2006 Share Posted April 13, 2006 SELECT COLUMN_NAME FROM USER_CONS_COLUMNS WHERE CONSTRAINT_NAME = (SELECT CONSTRAINT_NAME FROM ALL_CONSTRAINTS WHERE CONSTRAINT_TYPE IN ('P') AND TABLE_NAME =<TABLE_NAME>)I think this will help you...Sairam Link to comment Share on other sites More sharing options...
rawr215 Posted June 21, 2006 Share Posted June 21, 2006 I just did my sql homework and i had to do the same thing i found this site was useful:http://www.cs.wisc.edu/~dbbook/openAccess/...e_guide.html#oc Observing ConstraintsOften you may wish to see what constraints exist on a table. The view USER_CONSTRAINTS is maintained by Oracle and has information about constraints. Some interesting columns include, the CONSTRAINT_NAME, CONSTRAINT_TYPE where P refers to primary key, and R is a foreign key constraints, the TABLE_NAME on which it is defined, and the R_CONSTRAINT_NAME for foreign key constraints. Type DESCRIBE USER_CONSTRAINTS for more informaion.Once you know the CONSTRAINT_NAME, you can use the USER_CONS_COLUMNS view to find the COLUMN_NAME and POSITION for that CONSTRAINT_NAME. You can query these views as you would any other table:select column_name, position, constraint_name from User_cons_columns; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now