By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Oid

P: 4
I created a table in which i dont have a primary key ,so i want to give oid as primary key .In the table i have some thousands of records. How do i generate oid for each record?
Apr 18 '07 #1
Share this Question
Share on Google+
3 Replies


archulu
P: 34
i think this is usefull for for u
i am given some ex below. in this ex primary key is emp_code, this emp_code is fk for remaining table

for primary key assighn ex:
CREATE TABLE Leavetable ( emp_code varchar(25) primary key NOT NULL, fdate date, update date, first_half date, second_half date, no_of_days integer [3] );

for foreighn key asighn ex:
CREATE TABLE Leavetype ( emp_code varchar(25) references leavetable(emp_code), date date, type_of_leave varchar, reason char [50] );
Apr 18 '07 #2

archulu
P: 34
if u r already create the table and now u want to add constrain to th table .
this ex use for u
ex:ALTER TABLE products ADD primary key (product_id) ;

for extra usage watch this site add:
http://www.postgresql.org/docs/8.1/interactive/ddl-alter.html#AEN2256
Apr 18 '07 #3

Expert 100+
P: 534
I created a table in which i dont have a primary key ,so i want to give oid as primary key .In the table i have some thousands of records. How do i generate oid for each record?
In the latests versions of Postgres tables are created without OIDs, unless default_with_oids is set to true.
So if you need oid you may have to explicitly ask for it in the CREATE TABLE clause.

In addition to this, OID is not the best candidate for unique key, a serial would make a much better key.
Read the CREATE TABLE manual, they have some helpful notes on this subject.
Apr 18 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.