shilps
shilps

Reputation:

relational database schema

Can we define a string and a number both as a primary Key in table?

Upvotes: 1

Views: 423

Answers (2)

nvogel
nvogel

Reputation: 25534

Yes. In principle it ought to be possible to use any combination of attributes as a key or keys in a table (assuming nulls aren't permitted). In practice most SQL DBMSs place limits on the storage size and sometimes the types that can be used.

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300789

Yes. But depending on the RDBMS I wouldn't necessarily do that.

Instead create a surrogate primary key, and a unique compound key based on your domain values (string and number)

Upvotes: 2

Related Questions