Cheatography
https://cheatography.com
Cheat Sheet to the topic 'Keys. Relations. Relationships. SQL Data Types'
Relational DB - Main Terms
Relational Database (RDB): |
A type of database that organizes data into tables with predefined relationships between them. Tables consist of rows (records) and columns (attributes) that store data in a structured manner. |
Table: |
A collection of related data organized into rows (records) and columns (attributes). Each table has a unique name and consists of a predefined set of columns with specific data types. |
Row (Record): |
A single entry or instance of data in a table. Represents a unique entity or record within the table. Each row consists of values corresponding to the columns defined in the table's schema. |
Column (Attribute): |
A named data element within a table that holds a specific type of data. Defines the type of information that can be stored in the column, such as numbers, text, or dates. |
Schema: |
The structure or blueprint of a database. Defines the tables, columns, data types, relationships, and constraints within the database. |
Query: |
A request for data retrieval or manipulation from a database. Written in SQL (Structured Query Language) to specify the desired data and the operations to be performed. |
Normalization
1NF (First Normal Form): Ensures that each column in a table contains only atomic values (no repeating groups). |
2NF (Second Normal Form): Requires meeting 1NF and ensuring that non-key attributes depend on the entire primary key. |
3NF (Third Normal Form): Requires meeting 2NF and removing transitive dependencies, ensuring that non-key attributes depend only on the primary key. |
|
|
Keys
Primary Key: A unique identifier for each record in a table. Ensures data integrity and enables efficient data retrieval. |
Foreign Key: A field in one table that refers to the primary key in another table. Establishes relationships between tables. |
Composite Key: A combination of two or more columns that together form a unique identifier for a record. |
Candidate Key: A column or set of columns that can uniquely identify a record in a table. |
Surrogate Key: A system-generated unique identifier used as a primary key, often an auto-incremented number. |
Relationships:
One-to-One: A relationship where each record in one table is related to exactly one record in another table. |
One-to-Many: A relationship where each record in one table is related to multiple records in another table. |
Many-to-Many: A relationship where multiple records in one table are related to multiple records in another table. Requires a junction table. |
|
|
SQL Data Types:
Numeric Data Types:
INT: whole numbers (e.g., 1, -5, 1000).
DECIMAL(p, s): fixed-point numbers with a specified precision (p) and scale (s).
FLOAT(p): floating-point numbers with a specified precision (p).
Character Data Types:
CHAR(n): fixed-length character strings with a maximum length of n characters.
VARCHAR(n): variable-length character strings with a maximum length of n characters.
TEXT: large variable-length character strings.
Date and Time Data Types:
DATE: a date value in the format YYYY-MM-DD.
TIME: a time value in the format HH:MM:SS.
DATETIME: a combination of date and time values (YYYY-MM-DD HH:MM:SS).
TIMESTAMP: a unique value that changes whenever the row is updated.
Binary Data Types:
BLOB: large binary objects (e.g., images, videos, files).
BINARY(n): fixed-length binary strings with a maximum length of n bytes.
VARBINARY(n): variable-length binary strings with a maximum length of n bytes. |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by mehalyna