Oid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalisha
    New Member
    • Mar 2007
    • 4

    #1

    Oid

    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?
  • archulu
    New Member
    • Mar 2007
    • 34

    #2
    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] );

    Comment

    • archulu
      New Member
      • Mar 2007
      • 34

      #3
      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#AEN2 256

      Comment

      • michaelb
        Recognized Expert Contributor
        • Nov 2006
        • 534

        #4
        Originally posted by kalisha
        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_oi ds 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.

        Comment

        Working...