Advanced SQL covers selecting columns, aggregate functions like MIN() and MAX(), the CASE WHEN statement, JOINs, the WHERE clause, GROUP BY, declaring variables, and subqueries
4. What is Embedded SQL?
1. When we talk about industry-level applications we need properly connected systems which
could draw data from the database and present to the user. In such cases, the Embedded SQL
comes to our rescue.
2. We embed SQL queries into high-level languages such that they can easily perform the logic
part of our analysis.
3. Some of the prominent examples of languages with which we embed SQL are: C++, Java,
Python, etc.
4. Embedded SQL gives us the freedom to use databases as and when required.
5. Once the application we develop goes into the production mode several things need to be
taken care of.
6. With the help of the embedding of queries, we can easily use the database without creating
any bulky code.
7. With the embedded SQL, we can also create API’s which can easily fetch and feed data
whenever required.
5. How to Embed SQL in High-Level
Languages?
1. For using embedded SQL, we need some tools in each high-level
language.
2. In some cases, we have inbuilt libraries which provide us with the
basic building block.
3. While in some cases we need to import or use some packages to
perform the desired tasks.
4. For example:
Class.forName( “com.mysql.jdbc.Driver“ );
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/DataFlair","user","root“ );
Statement statement = connection.createStatement();
6. ADVANTAGES OF EMBEDDED SQL
1. Helps to access databases from anywhere.
2. Allows integrating authentication service for large scale
applications.
3. Provides extra security to database transactions.
4. Avoids logical errors while performing transactions on our
database.
5. Makes it easy to integrate the frontend and the backend of our
application.
8. What is Dynamic SQL?
1. Dynamic SQL is the process for programming SQL queries that are built dynamically with the
application operations.
2. Manage big industrial applications and manage the transactions without overhead.
3. We are free to create flexible SQL queries and the names of the variables or any other parameters
are passed when the application runs.
4. We can use stored procedures to create dynamic queries which can run when we desire.
5. We use the exec keyword.
6. When we use static SQL it is not altered from one execution to others, but in the case of dynamic
SQL, we can alter the query in each execution.
7. We should always prefer using static SQL over dynamic SQL for the following benefits of the static
SQL:
• If a query compiles successfully it implies that the syntax is correct.
• If a query compiles successfully it verifies that all the permissions and validations are correct.
• As all the data is pre-known in static SQL the overhead charges are reduced considerably.
9. When to Use Dynamic SQL?
1. When static SQL does not support.
2. When exact SQL statements are not known.
3. When we want to execute
• DDL: CREATE, DROP, GRANT, REVOKE
• DML: INSERT, UPDATE, DELETE
• SCL: ALTER SESSION and SET ROLE
11. What is Functional Dependency?
1. A functional dependency is a constraint that specifies the
relationship between two sets of attributes where one set can
accurately determine the value of other sets.
2. It is denoted as X → Y, where X is a set of attributes that is
capable of determining the value of Y.
3. X is called Determinant, and Y is called the Dependent.
4. Used to mathematically express relations among database
entities.
13. Armstrong’s axioms/properties of Functional
Dependencies
• Reflexivity: If Y is a subset of X, then X→Y
For example, {roll_no, name} → name is valid.
• Augmentation: If X → Y is a valid dependency, then XZ → YZ
For example, If {roll_no, name} → dept_building is valid, then
{roll_no, name, dept_name} → {dept_building, dept_name} is
also valid.
• Transitivity: If X → Y and Y → Z are both valid dependencies,
then X→Z.
For example, roll_no → dept_name & dept_name →
dept_building, then roll_no → dept_building is also valid.
15. • A dependent is always a subset of the determinant.
i.e. If X → Y and Y is the subset of X
Trivial functional dependency
Non-trivial functional dependency
• A dependent is strictly not a subset of the determinant.
i.e. If X → Y and Y is not a subset of X
16. • Entities of the dependent set are not dependent on each other.
i.e. If a → {b, c} and there exists no functional
dependency between b and c.
• For example,
Multivalued functional dependency
Here, roll_no → {name, age} is a Multivalued
functional dependency, since the dependents
name & age are not dependent on each other
(i.e. name → age or age → name doesn’t exist)
17. • A dependent is indirectly dependent on determinant,
i.e. If a → b & b → c, then according to axiom of transitivity, a
→ c
• For example,
Transitive functional dependency
Here, enrol_no → dept and dept →
building_no.
Hence, according to the axiom of
transitivity, enrol_no → building_no is a
valid functional dependency. This is an
indirect functional dependency, hence
called Transitive functional dependency.
19. What is Decomposition?
1. When a relation is not in appropriate normal form then the
decomposition of a relation is required.
2. It breaks the table into multiple tables.
3. If the relation has no proper decomposition, then it may
lead to loss of information.
4. Eliminate some of the problems like anomalies,
inconsistencies, and redundancy.
21. Dependency Preserving Decomposition
1. At least one decomposed table must satisfy every
dependency.
2. If a relation R is decomposed into relation R1 and R2, then
the dependencies of R must be a part of R1 or R2 or must
be derivable from the combination of functional
dependencies of R1 and R2.
3. That means, F1∪F2 ≡ F
22. Lossless Decomposition
1. If the information is not lost from the relation that is
decomposed, then the decomposition will be lossless.
2. The lossless decomposition guarantees that the join of
relations will result in the same relation as it was
decomposed.
3. The relation is said to be lossless decomposition if natural
joins of all the decomposition give the original relation.