Learning Journal Week 6

 Embedded SQL is pretty neat because it lets you mix SQL commands right into other programming languages like C or COBOL. You start off with EXEC SQL to mark where those commands go. Essentially, you compile your program in two steps: first, a precompiler translates the SQL into the host language, and then the regular compiler turns that into something you can actually run. When it comes to talking to a database, you use connection statements like CONNECT, SET CONNECTION, and DISCONNECT. You can also share variables between SQL and your program by declaring them between BEGIN DECLARE SECTION and END DECLARE SECTION. If you’re running queries that give back more than one row, you’ll want to use cursors to handle the results with commands like DECLARE, OPEN, FETCH, and CLOSE. Want more flexibility? That’s where dynamic SQL comes in, letting you create and run SQL statements on the fly with PREPARE and EXECUTE.

Now, let’s talk about Procedural SQL. It takes things up a notch by adding programming elements like procedures, functions, conditionals, and loops, which help you tackle more complex tasks in the database. These procedures, known as stored procedures, live in the database and can be called from other procedures or even external programs. You create them using CREATE PROCEDURE, and they can accept parameters that either bring in data (IN), send out data (OUT), or do both (INOUT). They often have a bunch of commands grouped together between BEGIN and END.
There are also stored functions, which are kind of like stored procedures but simpler since they just return one value with RETURN. You define them with CREATE FUNCTION, and they take input parameters, specifying what type they’ll return using RETURNS. Think of these like the built-in SQL functions, like COUNT(). While stored procedures can give back multiple values, stored functions are handy for when you need to compute a single value right inside your queries.
So, mixing embedded and procedural SQL really helps programs communicate efficiently and easily with relational databases.

Comments

Popular posts from this blog

Journal week 6

Journal Entry Week 2

CST334 Operating Systems Week 1