Avoid Tables without Primary Key | CAST Appmarq

Avoid Tables without Primary Key

CRITICAL

Rule Definition
In relational database design, a candidate key is just a unique identifier. Next a primary key is a candidate key that's been singled out to uniquely identify each row in a table. A unique key or primary key comprises a single column or set of columns. No two distinct rows in a table can have the same value (or combination of values) in those columns. Depending on its design, a table may have arbitrarily many unique keys but at most one primary key.

Remediation
Check the statement and if so, add primary key.

Violation Code Sample
The following statement should be reviewed:
create table SQLAMDA001_7_TBL1
(category_name varchar2(10) not null ,
  title        varchar2(50) null ,
  title_id     varchar2(10) null ,
  author_name  varchar2(30) null
)
/
Fixed Code Sample
The following statement should be reviewed:
create table SQLAMDA001_7_TBL1
(category_name varchar2(10) not null ,
  title        varchar2(50) null ,
  title_id     varchar2(10) null ,
  author_name  varchar2(30) null
)
/
Add a primary key:
alter table SQLAMDA001_7_TBL1 add constraint SQLAMDA001_7_TBL1_PK primary key (category_name)
using index
/

Reference
https://docs.oracle.com/cd/B28359_01/server.111/b28318/data_int.htm#CNCPT021 http://www.geeksengine.com/database/design/data-integrity.php https://www3.ntu.edu.sg/home/ehchua/programming/sql/Relational_Database_Design.html Exceptions : DB2 global temporary tables and Oracle private temporary tables do not support primary keys https://www.ibm.com/developerworks/data/library/techarticle/dm-0912globaltemptable/index.html https://oracle-base.com/articles/18c/private-temporary-tables-18c

Related Technologies

Health Factor

  Security


Technical Criterion
Efficiency - SQL and Data Handling Performance

About CAST Appmarq

CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.

Benchmark Statistics

Global Compliance

60.81%

Total Violations
33,906
Total Opportunities
86,514
Average Violations / App.
639.74
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Select from drop-down

64.74%

Insurance

43.31%

Financial Services

46.37%