SQL Programming
SQL introduction
SQL (Structured Query Language) is a database computer language created for managing data in Relational Database Management Systems (RDBMS). It was originally developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s, initially called SEQUEL, in order to manipulate and retrieve data stored in IBM's original relational database management system.
The SQL language is used to operate databases including database creation, data query, update, schema creation and modification as well as data access control. It is an ANSI (American National Standards Institute) standard language with different versions for Relational Database System. The RDBMS (such as MySQL, MS SQL Server, IBM DB2, Sybase, PostgreSQL, SQLite, Oracle, MS Access) use SQL as their standard database language.
Basic SQL statements
SELECT c1,c2,...; --SELECT some fields FROM table1 WHERE (a clause to filter records)...
FROM table1;
WHERE condition;
GROUP by column-name;
ORDER by column-name;
SELECT * FROM table1; --SELECT all fields FROM table1...
SELECT column_name(s) FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name; --select records with matching values in both tables.
LEFT JOIN table2 ON table1.column_name = table2.column_name;
--generate all records from the left table (table1) & the matched records from the right table (table2).
RIGHT JOIN table2 ON table1.column_name = table2.column_name;
--generate all records from the right table (table2) & the matched records from the left table (table1).
FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;
--generate all records if there is a match in either left (table1) or right (table2) table records.
SELECT column_name(s) FROM table1 T1, table1 T2 --The table is joined with itself.
WHERE condition;
SQL vs NoSQL
The database technology has two main types of databases including SQL (structured query language) and NoSQL (“non SQL" or “Not only SQL"), which refer to relational databases and non-relational databases, respectively. Unlike SQL, NoSQL databases are document-oriented instead of tables. Thus, the unstructured data (such as articles, photos, videos, and web content etc.) are stored in a single document that is different from SQL databases (SQL & NoSQL Databases, 2019).
NoSQL databases have an advantage of ease of access by the app developers while relational databases are not easily accessible to the applications developed using the object-oriented programming languages such as Python and PHP (Hypertext Preprocessor).
The most popular databases
- Microsoft SQL Server: This database management engine can work on both cloud-based servers and local servers. It is stable and fast. However, the cost may be high for many organizations.
- PostgreSQL: PostgreSQL is a free popular database and is often used for web databases. It is one of the first database management systems and can be used for managing both structured and unstructured data. It can support JSON, is scalable and is able to handle terabytes of data. PostgreSQL is a free popular database and is often used for web databases. It is one of the first database management systems and can be used for managing both structured and unstructured data. It can support JSON, is scalable and is able to handle terabytes of data.
- MySQL: MySQL is also one of the most popular databases for web-based applications. It is a freeware but there are also different paid editions available for commercial use.
- Oracle Database: Oracle database management tool is no doubt robust, it can be used for the cloud and be hosted on a single or multiple servers. It is enabled to manage databases with billions of records. However, the cost of Oracle may be prohibitive for small companies.
- MongoDB: MongoDB is also a free database but has a commercial version. It is designed for managing both structured and unstructured data. MongoDB is easy to use and runs fast, it can support JSON and other NoSQL documents. However, SQL can not used as a query language but tools are available for translating SQL to MongoDB queries.
- MariaDB: MariaDB database management system has a free and a paid versions. There are a variety of plugins available for it, and it is the fastest growing open source database.
The most popular web services for cloud databases
- Amazon Web Service (AWS): The services from Amazon include: (1) Amazon RDS: this service provides the database products for Microsoft SQL Server, MySQL, PostgreSQL, Oracle, MariaDB, etc. (2) Amazon SimpleDB: it is a NoSQL data store. (3) Amazon DynamoDB: it is a key-value and document database capable of delivering single-digit millisecond performance at any scale.
- Microsoft Azure: MS Azure is a cloud platform across 55 regions that build and run web-based applications, smart client applications, and XML web services.
- Google Cloud Platform: Google Cloud Platform (GCP) is a suite of cloud computing services that Google uses for Search, Gmail, YouTube and many other modular cloud services such as computing, data storage, data analytics and machine learning. Other cloud databases with enterprise-scale database technology include MongoDB Atlas, Oracle Database and IBM DB2.