When we don't need a primary key for our table?

后端 未结 4 819
無奈伤痛
無奈伤痛 2021-02-04 10:06

Will it ever happen that we design a table that doesn\'t need a primary key?

4条回答
  •  醉酒成梦
    2021-02-04 10:50

    Depends.

    What is primary key / unique key?

    In relational database design, a unique key can uniquely identify each row in a table, and is closely related to the Superkey concept. A unique key comprises a single column or a set of columns. No two distinct rows in a table can have the same value (or combination of values) in those columns if NULL values are not used. Depending on its design, a table may have arbitrarily many unique keys but at most one primary key.

    So, when you don't have to differentiate (uniquely identify) each row,
    you don't have to use primary key

    For example, a big table for logs,
    without using primary key, you can have fairly smaller size of data and faster for insertion

提交回复
热议问题