MySQL SQL Programming

  • Filter
  • Time
  • Show
Clear All
new posts

    MySQL SQL Programming

    SQL means, Structured Query Language. This is a computer language used in programming relational databases. Each database server has its own particular structured query language. The language differs slightly as you move from one database server to another. In this article I explain the use of SQL in the MySQL server.

    Straightforward Use
    The straightforward use of SQL statements is to do things like create database, create tables, insert table row, update table row, delete table row and select (display) table data (rows).

    Need for Programming
    Imagine that you have a shop database with a table called, SaleDetails and another called Products. The SaleDetails table has the name and the number of particular items sold. The Products table has the names and quantity of items in stock.

    Assume that you sell five of a particular item. That information has to be inserted as a row in the SaleDetails table. The number, five, for the sold item, has to be subtracted from the Products table, for inventory. You need a program code to do that automatically. In other words, you need a set of special SQL statements to do that. The special set of SQL statements follow a format called, TRIGGER.

    Stored Procedure
    You may want to call a trigger such as the one described above; you may then want to check whether the item in the Products table has reached re-order level so that you inform the manager by placing a row in a table of his, which he reads every morning. You may also want to display all the purchases that have been made by the customer in the month. You may want to have all that done automatically when a customer makes a purchase. In this case you need programming code that is larger than that for the trigger.

    Such code is termed, a procedure, and needs special SQL statements. Such a procedure is normally saved (stored) in the hard disk and called whenever it is needed. That is why, it is called, Stored Procedure.

    The triggers and procedures are saved in the same hard disk as the MySQL server and database.

    The main things you do with SQL as a computer language is to write triggers and procedures. You also use SQL for data definition and manipulation; however, in that form, it does not look like programming. There are a few other things you can do with SQL, but I will not go into that, in this article. However, you will learn a lot on MySQL SQL as you read the tutorials I have prepared for you.

    SQL is normally executed in the same computer as the MySQL server.

    Before you learn SQL for triggers and stored procedures and general database programming, you need to have learned SQL for data definition and data manipulation. If you have done that, then know that I have a new tutorial series ready for you. The series will teach you SQL programming in MySQL server. The series has been written in a step-by-step fashion and the tutorials are well formatted, without any missing special character. To start the series, just click the following hyperlink:

    MySQL SQL Programming