Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to check whether the column is set to primary key ?

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, how do we use coding to check whether the column have set to primary key ? thank you !
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A PK is a database constraint. You cannot insert null into it. So the check is implicit to its purpose, and performed by teh DB. If you are worried about trying to run JDBC code which might be inserting nulls into PK fields, just check for nulls as you would normally before trying to run the code.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, paul for reply ..

can we unset the primary key in column which already set as primary key ?

thank you !
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just remove the constraint in the DDL.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A not-null column needn't be a primary key, while a primary key might not be null.
start:

(catalog, schema, table as String), catalog and schema may be null.
See the javadocs for DatabaseMetaData for more detailed information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic