|
| 1 | +--- |
| 2 | +id: codd-s-12-rules |
| 3 | +title: Codd's 12 Rules |
| 4 | +sidebar_label: Codd's 12 Rules |
| 5 | +sidebar_position: 1 |
| 6 | +description: Explore Dr. Edgar F. Codd's 12 Rules for true relational databases with examples and diagrams. |
| 7 | +--- |
| 8 | + |
| 9 | +# DBMS - Codd's 12 Rules |
| 10 | + |
| 11 | +Dr. Edgar F. Codd, after his extensive research on the Relational Model of database systems, came up with twelve rules of his own, which according to him, a database must obey in order to be regarded as a true relational database. |
| 12 | + |
| 13 | +## Rule 1: Information Rule |
| 14 | + |
| 15 | +The data stored in a database, may it be user data or metadata, must be a value of some table cell. Everything in a database must be stored in a table format. |
| 16 | + |
| 17 | +### Example: |
| 18 | + |
| 19 | +Consider a database for a library. The Information Rule ensures that every piece of data, like the title of a book or the name of an author, is stored within a specific table cell, such as the 'Book Title' attribute in the 'Books' table. |
| 20 | + |
| 21 | +## Rule 2: Guaranteed Access Rule |
| 22 | + |
| 23 | +Every single data element (value) is guaranteed to be accessible logically with a combination of table-name, primary-key (row value), and attribute-name (column value). No other means, such as pointers, can be used to access data. |
| 24 | + |
| 25 | +### Example: |
| 26 | + |
| 27 | +In a customer database, the Guaranteed Access Rule ensures that you can access a specific customer's details using their unique customer ID, such as querying "SELECT \* FROM Customers WHERE CustomerID = '123'". |
| 28 | + |
| 29 | +## Rule 3: Systematic Treatment of NULL Values |
| 30 | + |
| 31 | +The NULL values in a database must be given a systematic and uniform treatment. This is a very important rule because a NULL can be interpreted as one of the following − data is missing, data is not known, or data is not applicable. |
| 32 | + |
| 33 | +### Example: |
| 34 | + |
| 35 | +In an employee database, the Systematic Treatment of NULL Values ensures that if an employee's middle name is unknown or not applicable, it's represented as NULL in the database rather than an empty string or a placeholder. |
| 36 | + |
| 37 | +## Rule 4: Active Online Catalog |
| 38 | + |
| 39 | +The structure description of the entire database must be stored in an online catalog, known as data dictionary, which can be accessed by authorized users. Users can use the same query language to access the catalog which they use to access the database itself. |
| 40 | + |
| 41 | +### Example: |
| 42 | + |
| 43 | +An Active Online Catalog provides metadata about the database schema. For instance, it includes information about tables, columns, data types, and relationships, allowing users to understand and query the database structure. |
| 44 | + |
| 45 | +```mermaid |
| 46 | +erDiagram |
| 47 | + CAT_TABLE ||--o{ DB_TABLE : has |
| 48 | + CAT_TABLE ||--o{ COLUMN : has |
| 49 | + DB_TABLE ||--o{ COLUMN : contains |
| 50 | + DB_TABLE }|..|{ DATA : stores |
| 51 | +``` |
| 52 | + |
| 53 | +## Rule 5: Comprehensive Data Sub-Language Rule |
| 54 | + |
| 55 | +A database can only be accessed using a language having linear syntax that supports data definition, data manipulation, and transaction management operations. This language can be used directly or by means of some application. If the database allows access to data without any help of this language, then it is considered as a violation. |
| 56 | + |
| 57 | +### Example: |
| 58 | + |
| 59 | +SQL (Structured Query Language) is a comprehensive data sub-language that fulfills the requirements of data definition, manipulation, and transaction management. It allows users to interact with the database through standard commands like SELECT, INSERT, UPDATE, DELETE, and COMMIT. |
| 60 | + |
| 61 | +## Rule 6: View Updating Rule |
| 62 | + |
| 63 | +All the views of a database, which can theoretically be updated, must also be updatable by the system. |
| 64 | + |
| 65 | +### Example: |
| 66 | + |
| 67 | +Consider a view that combines data from multiple tables for reporting purposes. The View Updating Rule ensures that if the view includes columns from a single base table, those columns can be updated through the view. |
| 68 | + |
| 69 | +## Rule 7: High-Level Insert, Update, and Delete Rule |
| 70 | + |
| 71 | +A database must support high-level insertion, updation, and deletion. This must not be limited to a single row, that is, it must also support union, intersection and minus operations to yield sets of data records. |
| 72 | + |
| 73 | +### Example: |
| 74 | + |
| 75 | +The High-Level Insert, Update, and Delete Rule allows you to insert, update, or delete multiple rows at once. For instance, you can use an SQL statement like "DELETE FROM Employees WHERE Salary < 50000" to delete all employees with a salary below $50,000. |
| 76 | + |
| 77 | +## Rule 8: Physical Data Independence |
| 78 | + |
| 79 | +The data stored in a database must be independent of the applications that access the database. Any change in the physical structure of a database must not have any impact on how the data is being accessed by external applications. |
| 80 | + |
| 81 | +### Example: |
| 82 | + |
| 83 | +Physical Data Independence allows you to modify the storage structures (like changing indexes or file organization) without affecting how users and applications interact with the data. This ensures that applications remain functional even if the database undergoes structural changes. |
| 84 | + |
| 85 | +## Rule 9: Logical Data Independence |
| 86 | + |
| 87 | +The logical data in a database must be independent of its user’s view (application). Any change in logical data must not affect the applications using it. For example, if two tables are merged or one is split into two different tables, there should be no impact or change on the user application. This is one of the most difficult rules to apply. |
| 88 | + |
| 89 | +### Example: |
| 90 | + |
| 91 | +Imagine merging two tables 'Customers' and 'Suppliers' into a single table 'Partners'. Logical Data Independence ensures that existing applications accessing 'Customers' or 'Suppliers' continue to function seamlessly after the merge. |
| 92 | + |
| 93 | +## Rule 10: Integrity Independence |
| 94 | + |
| 95 | +A database must be independent of the application that uses it. All its integrity constraints can be independently modified without the need of any change in the application. This rule makes a database independent of the front-end application and its interface. |
| 96 | + |
| 97 | +### Example: |
| 98 | + |
| 99 | +Integrity constraints like primary keys, foreign keys, and unique constraints can be modified or added without affecting how applications interact with the database. This allows for changes in data validation rules without altering application logic. |
| 100 | + |
| 101 | +## Rule 11: Distribution Independence |
| 102 | + |
| 103 | +The end-user must not be able to see that the data is distributed over various locations. Users should always get the impression that the data is located at one site only. This rule has been regarded as the foundation of distributed database systems. |
| 104 | + |
| 105 | +### Example: |
| 106 | + |
| 107 | +In a distributed database, data may be stored across multiple physical locations. Distribution Independence ensures that users perceive and interact with the data as if it's stored in a single location, regardless of its actual distribution. |
| 108 | + |
| 109 | +## Rule 12: Non-Subversion Rule |
| 110 | + |
| 111 | +If a system has an interface that provides access to low-level records, then the interface must not be able to subvert the system and bypass security and integrity constraints. |
| 112 | + |
| 113 | +### Example: |
| 114 | + |
| 115 | +The Non-Subversion Rule prevents unauthorized access to low-level records or system components that could compromise security or integrity. It ensures that access controls and security measures are enforced, even through direct interfaces. |
| 116 | + |
0 commit comments