Learn SQL and Create a Database With Only Your Web Browser
By Stephen Bucaro
Introduction to SQL and WebSQL
SQL (Structured Query Language) is a language used for performing operations on a relational database.
A relational database is data organized in a set of tables. It's called a relational database
because the tables (or the collection of data in them) have relationships between them. A relationship,
in the context of databases, is when a table has a foreign key that references the primary key of another table.
There are three types of relationships: One-to-one, where the primary key relates to only one record
in the related table; One-to-many: where the primary key relates to many records in the related table;
Many-to-many: where each record in both tables can relate to any number of records in the other table.
There are many other types of databases besides relational. Some use a key-value method to store data.
Some use wide columns, like a spreadsheet, to store data, Some use a tree-like structure (hierarchical)
to store data. But no other type is as powerful or efficient as a relational database. However, efficient
relational databases are difficult to design, that's why the average database developer's salary is
over $100,000 per year.
To learn SQL usually requires that you install a RDBMS (Relational Database Management System), like
MS SQL Server or MySQL on your computer. I don't know about you, but my computer is over-loaded with
applications, so I'm reluctant to install such a huge application on it. That's where WebSQL comes in.
WebSQL is an API (Application Program Interface) built-in to Google's Chrome web browser that allows
you to use JavaScript to create and manage SQL (Relational) databases. It's mind-boggling to me that
I can create and manage an SQL database with nothing more than my web browser (and a text editor).
WebSQL is based on SQLite, a high-reliability, full-featured, public-domain, SQL database engine.
SQLite is the most used database engine in the world.
The down side is that WebSQL is supported only in Chrome and Safari (and Android and iOS by extension).
Since 2010, it has been deprecated by the W3C (World Wide Web Consortium) because the other browser
developers (Microsoft and Mozilla) didn't participate in the working committee. So if you want a
cross-browser standard, you'll have to use IndexedDB, which is nothing more than a larger storage area for cookies.
On the other hand, Chrome, Safari, iOS, and Android are the most popular browsers and operating
systems on the planet, and knowing what Google and Apple plan to use WebSQL for, I don't expect
them to drop it any time soon. In fact, I think when Microsoft and Mozilla wake up and figure out
what's going on, they'll quickly dedicate the required resources. But, in any case, this provides a
great opportunity to learn SQL with nothing more than Google Chrome web browser (and a text editor).
How to Test for WebSQL Support
To test for WebSQL Support, type the code shown below into a plain text editor (Windows Notepad) and
save the file with a name with the .htm extnsion, e.g. test.htm. Then open the file in your web browser.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script>
if (!window.openDatabase)
{
alert("Sorry! Your Browser does not support WebSql Database.")
}
else
{
alert("Congratulation Your Browser supports WebSql Database.")
}
</script>
</head>
<body>
</body>
</html>
|