SoFunction
Updated on 2025-03-08

JDBC SQL Syntax

Structured Query Language (SQL) is a standardized language that allows you to perform operations on a database such as creating projects, reading content, updating content and deleting entries.

SQL is all code that may use almost any database support, which allows writing to the database independent of the underlying database.

This tutorial gives SQL, which is a prerequisite for understanding the JDBC overview. This tutorial provides enough SQL to be able to create, read, update, and delete data (often called CRUD operations) from a database.

For more information about SQL, please read ourMySQL Tutorial

Create a database:

Copy the codeThe code is as follows:

CREATE DATABASE

Statements are used to create a new database. The syntax is:
Copy the codeThe code is as follows:

SQL> CREATE DATABASE DATABASE_NAME;

example:

The following SQL statement creates an EMP database:

Copy the codeThe code is as follows:

SQL> CREATE DATABASE EMP;

Delete the database:

Use the DROP DATABASE statement to delete an existing database. The syntax is:

Copy the codeThe code is as follows:

SQL> DROP DATABASE DATABASE_NAME;

Note: To create or delete a database with administrator privileges on the database server. Note that deleting the database stores all data that is lost in the database.

Create a table:

The CREATE TABLE statement is used to create a new table. The syntax is:

Copy the codeThe code is as follows:

SQL> CREATE TABLE table_name
(
   column_name column_data_type,
   column_name column_data_type,
   column_name column_data_type
   ...
);

example:
The following SQL statement creates a table with four columns named Employees:

Copy the codeThe code is as follows:

SQL> CREATE TABLE Employees
(
   id INT NOT NULL,
   age INT NOT NULL,
   first VARCHAR(255),
   last VARCHAR(255),
   PRIMARY KEY ( id )
);

Delete the table:
The DROP TABLE statement is used to delete an existing table. The syntax is:

Copy the codeThe code is as follows:

SQL> DROP TABLE table_name;

example:
The following SQL statement deletes a table named Employees:

Copy the codeThe code is as follows:

SQL> DROP TABLE Employees;

Insert data:

The syntax INSERT is similar to the following, where column1, column2, and so on means that new data appears in each column:

Copy the codeThe code is as follows:

SQL> INSERT INTO table_name VALUES (column1, column2, ...);

example:
Insert the previously created Employees database into the following SQL INSERT statement:

Copy the codeThe code is as follows:

SQL> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');

SELECT data:
The SELECT statement is used to retrieve data from a database. The SELECT of this syntax is:

Copy the codeThe code is as follows:

SQL> SELECT column_name, column_name, ...
     FROM table_name
     WHERE conditions;
    
The WHERE clause can use comparison operators such as =, !=, <, >, <=, >=, and BETWEEN and LIKE operators.

example:
The following SQL statement selects the first and last column names from the Employees table where id =100:

Copy the codeThe code is as follows:

SQL> SELECT first, last, age
     FROM Employees
     WHERE id = 100;
    
The following SQL statements are from the Employees table, where the first column selects age, and the first column contains Zara:
Copy the codeThe code is as follows:

SQL> SELECT first, last, age
     FROM Employees
     WHERE first LIKE '%Zara%';
    
UPDATE data:
The UPDATE statement is used to update data. The UPDATE syntax is:
Copy the codeThe code is as follows:

SQL> UPDATE table_name
     SET column_name = value, column_name = value, ...
     WHERE conditions;
    
The WHERE clause can use comparison operators such as =,! =, <,>, <=, and >=, as well as the BETWEEN and LIKE operators.

example:

The following SQL UPDATE statement changes the age column of the employee whose ID is 100:

Copy the codeThe code is as follows:

SQL> UPDATE Employees SET age=20 WHERE id=100;

DELETE data:
The DELETE statement is used to delete data in the table. The syntax DELETE is:
Copy the codeThe code is as follows:

SQL> DELETE FROM table_name WHERE conditions;

The WHERE clause can use comparison operators such as =,! =, <,>, <=, and >=, as well as the BETWEEN and LIKE operators.

example:
The following SQL DELETE statement deletes the records of employees with ID 100:

Copy the codeThe code is as follows:

SQL> DELETE FROM Employees WHERE id=100;