DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: primary key ??

  1. #1
    Join Date
    Sep 2001
    Posts
    76
    hi friends,
    after creating a table with no constraints and then loading data into it, can we then define a primary key to that table ?

    thanks



  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Sure,
    ALTER TABLE xyz ADD CONSTRAINT pk_xyz PRIMARY KEY (pk_field);
    Jeff Hunter

  3. #3
    Join Date
    Sep 2001
    Location
    NJ, USA
    Posts
    1,287
    Better :

    ALTER TABLE xyz ADD CONSTRAINT pk_xyz PRIMARY KEY (pk_field)
    using index
    tablespace ...
    pctfree XX
    storage (...)
    exception into .....;

    because you loaded data into table and nobody never sure that PK column is primary key.


  4. #4
    Join Date
    Sep 2001
    Posts
    76
    thanks , the primary key worked, but, after creating a table and if i have to make a column not null, which already has data in it what do i do?

  5. #5
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Simply alter the table.

    ALTER TABLE my_table MODIFY (my_column NOT NULL);

    If there is any NULL value in MY_COLUMN the above will fail. You will first need to set all rows to have non-null value in that column, then you add NOT NULL constraint.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width