ArticleslgStudy

science

Embedded SQL

Embedded SQL is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Embedded SQL rather than just read about it. In short: Embedded SQL is a method of combining the computing power of a programming language and the database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program source code, of the host language.

Key takeaways

  • Embedded SQL belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Embedded SQL to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Embedded SQL from memory before moving on to harder problems.

Reference excerpt

Embedded SQL is a method of combining the computing power of a programming language and the database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program source code, of the host language. The embedded SQL statements are parsed by an embedded SQL preprocessor and replaced by host-language calls to a code library. The output from the preprocessor is then compiled by the host compiler. This allows programmers to embed SQL statements in programs written in any number of languages such as C/C++, COBOL and Fortran. This differs from SQL-derived programming languages that don't go through discrete preprocessors, such as PL/SQL and T-SQL. The SQL standards committee defined the embedded SQL standard in two steps: a formalism called Module Language was defined, then the embedded SQL standard was derived from Module Language. The SQL standard defines embedding of SQL as embedded SQL and the language in which SQL queries are embedded is referred to as the host language. A popular host language is C. Host language C and embedded SQL, for example, is called Pro*C in Oracle and Sybase database management systems, ESQL/C in Informix, and ECPG in the PostgreSQL database management system. SQL may also be embedded in languages like PHP etc. The SQL standard SQL:2023 is available through purchase and contains chapter 21 Embedded SQL and its syntax rules.

Database systems that support embedded SQL

Altibase C/C++ APRE is an embedded SQL precompiler provided by Altibase Corp. for its DBMS server.

IBM Db2 IBM Db2 for Linux, UNIX and Windows supports embedded SQL for C, C++, Java, COBOL, FORTRAN and REXX although support for FORTRAN and REXX has been deprecated.

IBM Informix IBM Informix version 14.10 for Linux, Unix, and Windows supports embedded SQL for C.}

Microsoft SQL Server C/C++ Embedded SQL for C has been deprecated as of Microsoft SQL Server 2008 although earlier versions of the product support it.

Mimer SQL Mimer SQL for Linux, macOS, OpenVMS and Windows support embedded SQL.

C/C++ Embedded SQL for C/C++ is supported on Linux, macOS, OpenVMS and Windows. COBOL Embedded SQL for COBOL is supported on OpenVMS. Fortran Embedded SQL for Fortran is supported on OpenVMS.

Oracle Database Ada Pro*Ada was officially desupported by Oracle in version 7.3. Starting with Oracle8, Pro*Ada was replaced by SQL*Module but appears to have not been updated since. SQL*Module is a module language that offers a different programming method from embedded SQL. SQL*Module supports the Ada83 language standard for Ada. C/C++ Pro*C became Pro*C/C++ with Oracle8. Pro*C/C++ is currently supported as of Oracle Database 11g. COBOL Pro*COBOL is currently supported as of Oracle Database 11g. Fortran Pro*FORTRAN is no longer updated as of Oracle8 but Oracle will continue to issue patch releases as bugs are reported and corrected. Pascal Pro*Pascal was not released with Oracle8. PL/I Pro*PL/I was not released with Oracle8. The Pro*PL/I Supplement to the Oracle Precompilers Guide, however, continued to make appearances in the Oracle Documentation Library until release 11g. As of release 12c, the Pro*PL/I has been removed from the Oracle Documentation Library.

PostgreSQL C/C++ ECPG is part of PostgreSQL since version 6.3. COBOL Cobol-IT is now distributing a COBOL precompiler for PostgreSQL Micro Focus provides support via their OpenESQL preprocessor

SAP Sybase SAP Sybase ASE 15.7 supports embedded SQL for C and COBOL as part of the Software Developer Kit Sybase. SAP Sybase SQL Anywhere supports embedded SQL for C and C++ as part of the SQL Anywhere database management system SQL Anywhere. SAP Sybase IQ supports embedded SQL for C and C++ as part of the Sybase IQ database management system Sybase IQ.

Embedded SQL through domain-specific languages LINQ-to-SQL embeds a SQL-like language into .NET languages. JPA embeds a SQL-like language through Criteria API into Java. jOOQ embeds a SQL-like language into Java.

See also Language binding Module SQL PL/SQL Pro*C/C++ SQL/OLB SQL PL Transact-SQL

References

External links Introduction to Pro*C Embedded SQL Embedded SQL with Pro*C SQL*Module for Ada Programmer's Guide, Release 8.0 ECPG, PostgreSQL Documentation ESQL/C, Informix Documentation' Embedded SQL in C, Mimer SQL Developer

Worked examples

Example 1 — a first encounter with Embedded SQL

Start with the simplest possible case. Write down what Embedded SQL claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Embedded SQL before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Embedded SQL ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Embedded SQL

In research
Embedded SQL appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Embedded SQL in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Embedded SQL is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data modeling languages, Database APIs, Declarative programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for Embedded SQL outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Embedded SQL” →

How to study Embedded SQL in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Embedded SQL means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Embedded SQL out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Embedded SQL in simple terms?

Embedded SQL is a method of combining the computing power of a programming language and the database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program source code, of the host language.

Why does Embedded SQL matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Embedded SQL?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Embedded SQL.

Tags

  • Data modeling languages
  • Database APIs
  • Declarative programming languages
  • Query languages
  • SQL
  • SQL data access

Keep exploring