syntax for adding constraint say primary key to a column using alter command in db2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reshma tellis
    New Member
    • Feb 2011
    • 2

    syntax for adding constraint say primary key to a column using alter command in db2

    how can i alter a table by adding a constaint to a column in db2 suppose table is student and i want to add a primary key to it using constraints hw can i write the syntax
  • vijay2082
    New Member
    • Aug 2009
    • 112

    #2
    FYI

    C:\Users\vijay> db2 "create table vijay.test5 (name varchar(10) not null)"
    DB20000I The SQL command completed successfully.

    C:\Users\vijay> db2 describe table vijay.test

    Data type Column
    Column name schema Data type name Length Scale Nulls
    ------------------------------- --------- ------------------- ---------- ----- ------
    NAME SYSIBM VARCHAR 10 0 Yes

    1 record(s) selected.


    C:\Users\vijay> db2 "alter table vijay.test5 activate not logged initially with empty table"
    DB20000I The SQL command completed successfully.

    C:\Users\vijay> db2 "alter table vijay.test5 add constraint pk_test5 primary key(name)"
    DB20000I The SQL command completed successfully.

    C:\Users\vijay> db2 "describe indexes for table vijay.test5"

    Index Index Unique Number of
    schema name rule columns
    ------------------------------- ------------------- -------------- --------------
    VIJAY PK_TEST5 P 1

    1 record(s) selected.

    Comment

    Working...