Overview of SQL Commands and PDO Operations

Structured Query Language, or SQL, is a widely used language the allows users to query and manage data in a database. Databases such as MySQL, MariaDB, SQLite, PostgreSQL, Oracle, and Microsoft SQL Server are all based on the SQL standard, with some slight variations. This resource uses the MySQL flavor of SQL.

I've created an overview resource to quickly be able to reference the appropriate syntax for the most popular SQL commands, and code to use the PDO class in PHP to securely connect to and work with a database.

The logo in this article is of Sequel Pro, an awesome free MySQL GUI for Mac.

Contents

Create Database

Drop Database

Create Table

Datatypes

Constraints

Alter Table

Drop Table

Select Rows

Select Distinct Rows

Joins

Aggregate Functions

Conditions

Insert Rows

Update Rows

Delete Rows

PDO: Open Connection

PDO Datatypes

PDO: Select Rows

PDO: Insert Row

PDO: Update Row

PDO: Delete Row

SQL

Common SQL syntax and statements.

Create Database

Create a new database.

CREATEDATABASEIFNOTEXISTS database_name

Drop Database

Delete an existing database.

DROPDATABASEIFEXISTS database_name

Create Table

Creates a new table with corresponding structure. The structure schema consists of a comma separated list of column name, followed by the datatype, followed by any constraints (optional) and a default value (optional).

Conclusion

Join the newsletter

I write about JavaScript, programming, and front-end design. Join over 6,000 other developers in keeping up with my content. Unsubscribe whenever. Never any spam, ads, or affiliate links.

I'm Tania, a full-stack software developer specializing in modern JavaScript. I make
open source coding projects and write free, quality articles and tutorials that help
thousands of people daily. No ads, no sponsored posts, no bullshit.