Embedded SQL nd ADVANCED SQL
Embedded SQL nd ADVANCED SQL
Key Concepts:
1. Host Variables:
o Host variables are used to pass values between the SQL statements and the host
program.
o They are declared in the host language but used in the embedded SQL statements.
o SQL statements are embedded in the host language code using the EXEC SQL and
END-EXEC keywords.
3. Error Handling:
o SQLCA (SQL Communication Area) or SQLCODE are used for error handling to
capture the execution status of SQL statements.
Example:
int emp_id;
char emp_name[100];
EXEC SQL SELECT name INTO :emp_name FROM employees WHERE id = :emp_id;
Advantages:
• Efficiency: Reduces the overhead of context switching between application and database.
• Type Safety: Ensures that data types are consistent between the application and database.
Disadvantages:
Key Concepts:
1. Subqueries:
o Example:
SELECT emp_name FROM employees WHERE emp_id IN (SELECT manager_id FROM departments);
2. Joins:
o Types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.
o Example:
3. Indexes:
o Example:
4. Stored Procedures:
BEGIN
END;
5. Triggers:
o Example:
BEGIN
END;
6. Views:
o Example:
Advantages:
Disadvantages:
• Complexity: Advanced features can make the SQL code more complex and harder to debug.
• Resource Intensive: Some advanced features, like triggers, can consume more database
resources.