MySQL

Rows

Data in a table is stored in rows. Each record saved is stored in its own row. Again, envisioning a table as a Excel spreadsheet style grid, the vertical columns in the grid are the table columns, and the horizontal rows are the table rows.

For example, a customers table might store one customer per row. The number of rows in the table is the number of records in it.

Primary Keys

Primary Key is a column whose values uniquely identify every row in a table.

Every row in a table should have some column that uniquely identifies it. A table containing customers might use a customer number column for this purpose, whereas a table containing orders might use the order ID. An employee list table might use an employee ID or the employee Social Security number column.

This column that uniquely identifies each row in a table is called a primary key. The primary key is used to refer to a specific row. Without a primary key, updating or deleting specific rows in a table becomes extremely difficult because there is no guaranteed safe way to refer to just the rows to be affected.

Any column in a table can be established as the primary key, as long as it meets the two conditions, first, primary key value should be unique (no two rows can have the same primary key value) and second, every row must have a primary key value (primary key columns may not allow null or empty values)

Primary keys are usually defined on a single column within a table. But this is not required, and multiple columns may be used together as a primary key. When multiple columns are used, the rules previously listed must apply to all columns that make up the primary key, and the values of all columns together must be unique.

by BrainBellupdated
Advertisement: