SQL Refyne
SQL Refyne
Primary Key
A primary key uniquely identifies each record in a table. It must contain unique
values and cannot be NULL.
Foreign Key
A foreign key is a field in one table that uniquely identifies a row of another table. It
establishes a relationship between the two tables.
Unique Key
A unique key ensures that all values in a column are unique. Unlike the primary key,
a table can have multiple unique keys, and unique keys can contain NULL values.
Triggers
Triggers are procedural codes that automatically execute in response to certain
events on a table, such as INSERT, UPDATE, or DELETE.
Index
An index improves query performance by providing quick access to rows.
● Clustered Index: Sorts and stores data rows.
● Non-Clustered Index: Stores pointers to data rows.
Types of Normalization
Organizes data to reduce redundancy and improve data integrity by dividing a
database into multiple related tables.
● 1NF: Eliminate duplicate columns.
● 2NF: Remove subsets of data that apply to multiple rows.
● 3NF: Remove columns that are not dependent on the primary key.
```sql
DECLARE cursor_name CURSOR FOR SELECT * FROM table_name;
OPEN cursor_name;
FETCH NEXT FROM cursor_name;
CLOSE cursor_name;
DEALLOCATE cursor_name;
```