Skip to main content

Primary key operations

This topic describes how to add, modify, and drop primary keys in seekdb.

Add a primary key

The syntax is as follows:

ALTER TABLE table_name ADD PRIMARY KEY (column_name);

In this syntax, table_name specifies the name of the table to which you want to add a primary key, and column_name specifies the column to which you want to add the primary key. For more information, see ALTER TABLE.

Assume that a table named tbl1 exists in the database. You can add a primary key index to the tbl1 table and apply it to the c1 column. Example:

ALTER TABLE tbl1 ADD PRIMARY KEY(c1);

Modify a primary key

The syntax is as follows:

ALTER TABLE table_name DROP PRIMARY KEY, ADD PRIMARY KEY (column_name);

In this syntax, table_name specifies the name of the table to which you want to add a primary key, and column_name specifies the column to which you want to add the primary key. For more information, see ALTER TABLE.

Assume that a table named tbl1 exists in the database and that a primary key exists in the tbl1 table. You can modify the primary key in the tbl1 table and apply it to the c2 column. Example:

ALTER TABLE tbl1 DROP PRIMARY KEY, ADD PRIMARY KEY(c2);

Drop a primary key

The syntax is as follows:

ALTER TABLE table_name DROP PRIMARY KEY;

In this syntax, table_name specifies the name of the table to which you want to add a primary key. For more information, see ALTER TABLE.

Assume that a table named tbl1 exists in the database and that a primary key exists in the tbl1 table. You can drop the primary key in the tbl1 table. Example:

ALTER TABLE tbl1 DROP PRIMARY KEY;

References

View indexes