Embedded SQL

What Does Embedded SQL Mean?

Embedded SQL is a method of inserting inline SQL statements or queries into the code of a programming language, which is known as a host language. Because the host language cannot parse SQL, the inserted SQL is parsed by an embedded SQL preprocessor.


Embedded SQL is a robust and convenient method of combining the computing power of a programming language with SQL’s specialized data management and manipulation capabilities.

Techopedia Explains Embedded SQL

Embedded SQL is not supported by all relational database management systems (RDBMS). Oracle DB and PostgreSQL provide embedded SQL support. MySQL, Sybase and SQL Server 2008 do not, although support was provided by earlier versions of SQL Server (2000 and 2005).

The C programming language is commonly used for embedded SQL implementation. For example, a commercial bank’s information system (IS) has a front-end user interface created in the C language, and the IS interfaces with a back-end Oracle DB database. One of the front-end interface modules allows quick viewing and commission calculation for sales agents during specified periods. An inefficient approach to handling this process would be to store each commission value in a database table. However, a more effective solution is to calculate and return commission values based on unique user requests on specified dates. The application accomplishes this by embedding a SQL query within the C code, as follows:


In this example, the SQL statement calculates and returns 20 percent of the sale amount from a TOTAL_SALES table, while the user is expected to input the SALE_DATE and AGENT_NO values. This SQL query is then inserted inline into the C code of the front-end module. The C code and SQL query work together to deliver seamless user results.


Related Terms

Margaret Rouse
Technology Expert

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.