1.Primary Key
- Uniquely identifies each record in a table.
- Cannot contain NULL values.
- Each table can have only one primary key.
- Example: Roll no., Aadhar no. etc.
2.Candidate Key
- All attributes that can uniquely identify a record.
- From these, one key is chosen as the Primary Key.
- Example: Roll_No, Aadhar_No, and Email can all uniquely identify a student.
3. Alternate Key
- The remaining candidate keys other than the primary key.
- Example: If Roll_No is the primary key, then Aadhar_No becomes the alternate key.
4. Super Key
- A set of one or more attributes that can uniquely identify a record.
- Every Primary Key is a Super Key, but not all Super Keys are Primary Keys.
- Example: (Roll_No) or (Roll_No, Name) both can be super keys.
5.Foreign Key
- Used to link two tables together.
- It refers to the Primary Key of another table.
- Maintains referential integrity.
6.Unique Key
-
Ensures that all values in a column are unique, but it can have one NULL value.
Example:
Summary Of Keys in a Table
| Key Type | Unique | NULL Allowed | Example / Use |
|---|---|---|---|
| Primary Key | ✅ Yes | ❌ No | Roll_No |
| Candidate Key | ✅ Yes | ❌ No | Roll_No, Aadhar_No |
| Alternate Key | ✅ Yes | ❌ No | Non-selected candidate key |
| Super Key | ✅ Yes | ✅ Yes | (Roll_No, Name) |
| Composite Key | ✅ Yes | ❌ No | (Roll_No, Subject_Code) |
| Foreign Key | ❌ No | ✅ Yes | References other table |
| Unique Key | ✅ Yes | ✅ (one allowed) |
7. SQL (Structured Query Language)
- SQL is used to create, read, update, and delete data from databases.
- MySQL follows SQL syntax.
8. Data Types in MySQL
A. Numeric Data Types
| Data Type | Description | Example |
|---|---|---|
| INT | Integer (whole numbers) | marks INT → 85 |
| FLOAT | Decimal number (single precision) | price FLOAT → 99.5 |
| DOUBLE | Decimal (double precision) | height DOUBLE → 5.11 |
| DECIMAL(p,s) | Fixed-point number | salary DECIMAL(8,2) → 50000.75 |
B. String (Character) Data Types
| Data Type | Description | Example |
|---|---|---|
| CHAR(n) | Fixed-length string | gender CHAR(1) → ‘M’ |
| VARCHAR(n) | Variable-length string | name VARCHAR(50) → ‘Ankit’ |
| TEXT | Long text or paragraphs | description TEXT → ‘This is a note.’ |
C. Date and Time Data Types
| Data Type | Description | Example |
|---|---|---|
| DATE | Date (YYYY-MM-DD) | dob DATE → ‘2007-04-15’ |
| TIME | Time (HH:MM:SS) | class_time TIME → ’09:30:00′ |
| DATETIME | Date + Time | created_on DATETIME → ‘2025-10-29 08:45:00’ |
| YEAR | Year (YYYY) | passing_year YEAR → 2025 |
D. Boolean Data Type
| Data Type | Description | Example |
|---|---|---|
| BOOLEAN / BOOL | True (1) or False (0) | is_active BOOLEAN → 1 |
9.SQL Command Categories
| Type | Meaning | Commands |
|---|---|---|
| DDL (Data Definition Language) | Defines structure | CREATE, ALTER, DROP, TRUNCATE |
| DML (Data Manipulation Language) | Works with data | INSERT, UPDATE, DELETE, SELECT |
| DCL (Data Control Language) | Access control | GRANT, REVOKE |
| TCL (Transaction Control Language) | Transaction handling | COMMIT, ROLLBACK, SAVEPOINT |
