Structured Query Language (SQL) is an institutionalized language that enables you to perform tasks on a database, for example, making passages, perusing content, refreshing substance, and erasing entries.

SQL is bolstered by practically any database you will probably utilize, and it enables you to compose database code freely of the basic database.

This part gives a diagram of SQL, which is an essential to comprehend JDBC ideas. Subsequent to experiencing this part, you will most likely Create, Create, Read, Update, and Delete (frequently alluded to as CRUD activities) information from a database.

Create Database

The CREATE DATABASE explanation is utilized for making another database. The grammar is −

SQL> CREATE DATABASE DATABASE_NAME;

Example

The following SQL explanation makes a Database named EMP −

SQL> CREATE DATABASE EMP;

Drop Database

The DROP DATABASE explanation is utilized for erasing a current database. The language structure is −

SQL> DROP DATABASE DATABASE_NAME;

Note: To make or drop a database you ought to have chairman benefit on your database server. Be cautious, erasing a database would misfortune every one of the information put away in the database.

Create Table

The CREATE TABLE articulation is utilized for making another table. The punctuation is −

SQL> CREATE TABLE table_name 

( 

column_name column_data_type, 

column_name column_data_type, 

column_name column_data_type 

... 

);

Example

The following SQL articulation makes a table named Employees with four sections −

SQL> CREATE TABLE Employees 

( 

id INT NOT NULL, 

age INT NOT NULL, 

first VARCHAR(255), 

last VARCHAR(255), 

Essential KEY ( id ) 

);

Drop Table

The DROP TABLE explanation is utilized for erasing a current table. The language structure is −

SQL> DROP TABLE table_name;

Example

The following SQL explanation erases a table named Employees −

SQL> DROP TABLE Employees;

INSERT Data

The language structure for INSERT, seems to be like the accompanying, where column1, column2, etc speaks to the new information to show up in the individual segments −

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

Example

The following SQL INSERT explanation embeds another column in the Employees database made before −

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

SELECT Data

The SELECT explanation is utilized to recover information from a database. The linguistic structure for SELECT is −

SQL> SELECT column_name, column_name, ... 

FROM table_name 

WHERE conditions;

The WHERE provision can utilize the correlation administrators, for example, =, !=, <, >, <=,and >=, just as the BETWEEN and LIKE operators.

Example

The following SQL explanation chooses the age, first and last sections from the Employees table, where id segment is 100 −

SQL> SELECT first, last, age 

FROM Employees 

WHERE id = 100;

The following SQL articulation chooses the age, first and last segments from the Employees table where first section contains Zara

SQL> SELECT first, last, age 

FROM Employees 

WHERE first LIKE '%Zara%';

UPDATE Data

The UPDATE proclamation is utilized to refresh information. The language structure for UPDATE is −

SQL> UPDATE table_name 

SET column_name = value, column_name = value, ... 

WHERE conditions;

The WHERE proviso can utilize the examination administrators, for example, =, !=, <, >, <=,and >=, just as the BETWEEN and LIKE operators.

Example

The following SQL UPDATE proclamation changes the age section of the worker whose id is 100 −

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

DELETE Data

The DELETE proclamation is utilized to erase information from tables. The linguistic structure for DELETE is −

SQL> DELETE FROM table_name WHERE conditions;

The WHERE statement can utilize the correlation administrators, for example, =, !=, <, >, <=,and >=, just as the BETWEEN and LIKE operators.

Example

The following SQL DELETE articulation erases the record of the representative whose id is 100 −

SQL> DELETE FROM Employees WHERE id=100;






© Javacodegeeks © 2019 - 2019
All Right Reserved and you agree to have read and accepted our term and condition. Python 3