hi, I am new to Oracle.Just started using it.Could anyone help me with this problem. I have many tables in my database. I want to identify the primary keys for a particular table. When i give DESC tablename, it does not show the constraint Primary Key for the table. How do i identify the primary keys for the table.
The basic aim behind defining the primary key in the table is to identify the record uniquely from ur table. The primary key is a set of one or more number of attributes which when taken collectively will identify the record uniquely from ur table. The syntax for defining a table is
Actually i have the tables already created in the database.
But the Primary Keys have not been defined for the tables.
Is there any way through which i can find out which columns are the primary keys for a table?
Joined: Jun 05, 2006
Ya exactly u have a way of defining a primary key after creating a table also. There u need to alter the table, using the command.
alter table <table_name> add constraint <constraint_name> primary key(attribute_name);
alter table add constraint pk primary key(rollno);
Giving name to constraint is just for the sake of convinience & u can use it whenever u want to delete that constraint. But remember if u have created a table & inserted the data into the field which u now want to make a primary key then that field should have UNIQUE & NOT NULL values only otherwise it will not alter ur table to define existing attribute as primary key.
Just try it.
It will definately solve ur problem.
Joined: Jun 05, 2006
Now i got ur problem, i think u want to identify the primary key attributes of ur existing tables. OK.
U can just check which attribute(s) is/are defined as primary key of ur table by executing the command
it will show u the list of fields, their data types & constraint if any defined. So it will show u the word NOT NULL in front of the primary key field. & if it doesn't show it means u have still not defined primary key for ur table, so now u would have to alter the table.