0% found this document useful (0 votes)
112 views

SQL Qyeries-1notes

This document provides an overview of SQL (Structured Query Language). SQL is used to manage data in relational database management systems. It allows users to define, manipulate, and query data. Some key capabilities of SQL include creating and modifying database objects like tables and views, inserting, updating, and deleting records, and retrieving data using queries. The document also covers SQL syntax, commands, data types, and examples of SQL statements. It explains that SQL is not a database itself but a language used to interface with relational databases like MySQL, SQL Server, Oracle, and others.

Uploaded by

Smita Shet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

SQL Qyeries-1notes

This document provides an overview of SQL (Structured Query Language). SQL is used to manage data in relational database management systems. It allows users to define, manipulate, and query data. Some key capabilities of SQL include creating and modifying database objects like tables and views, inserting, updating, and deleting records, and retrieving data using queries. The document also covers SQL syntax, commands, data types, and examples of SQL statements. It explains that SQL is not a database itself but a language used to interface with relational databases like MySQL, SQL Server, Oracle, and others.

Uploaded by

Smita Shet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

SQL Tutorial

SQL tutorial provides basic and advanced concepts of SQL. Our SQL tutorial is designed for beginners and professionals.

SQL (Structured Query Language) is used to perform operations on the records stored in the database such as updating records,
deleting records, creating and modifying tables, views, etc.

SQL is just a query language; it is not a database. To perform SQL queries, you need to install any database, for example, Oracle,
MySQL, MongoDB, PostGre SQL, SQL Server, DB2, etc.

What is SQL

o SQL stands for Structured Query Language.


o It is designed for managing data in a relational database management system (RDBMS).
o It is pronounced as S-Q-L or sometime See-Qwell.
o SQL is a database language, it is used for database creation, deletion, fetching rows, and modifying rows, etc.
o SQL is based on relational algebra and tuple relational calculus.

All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, PostgreSQL, and SQL Server use SQL as standard database language.

Why SQL is required

SQL is required:

o To create new databases, tables and views


o To insert records in a database
o To update records in a database
o To delete records from a database
o To retrieve data from a database

What SQL does

o With SQL, we can query our database in several ways, using English-like statements.
o With SQL, a user can access data from a relational database management system.
o It allows the user to describe the data.
o It allows the user to define the data in the database and manipulate it when needed.
o It allows the user to create and drop database and table.
o It allows the user to create a view, stored procedure, function in a database.
o It allows the user to set permission on tables, procedures, and views.

SQL Syntax
SQL follows some unique set of rules and guidelines called syntax. Here, we are providing all the basic SQL syntax.
o SQL is not case sensitive. Generally SQL keywords are written in uppercase.
o SQL statements are dependent on text lines. We can place a single SQL statement on one or multiple text lines.
o You can perform most of the action in a database with SQL statements.
o SQL depends on relational algebra and tuple relational calculus.

SQL statement

SQL statements are started with any of the SQL commands/keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP etc. and
the statement ends with a semicolon (;).

Example of SQL statement:

1. SELECT "column_name" FROM "table_name";  

Why semicolon is used after SQL statements:

Semicolon is used to separate SQL statements. It is a standard way to separate SQL statements in a database system in which more
than one SQL statements are used in the same call.

In this tutorial, we will use semicolon at the end of each SQL statement.

SQL CREATE TABLE

SQL Commands

These are the some important SQL command:

o SELECT: it extracts data from a database.


o UPDATE: it updates data in database.
o DELETE: it deletes data from database.
o CREATE TABLE: it creates a new table.
o ALTER TABLE: it is used to modify the table.
o DROP TABLE: it deletes a table.
o CREATE DATABASE: it creates a new database.
o ALTER DATABASE: It is used to modify a database.
o INSERT INTO: it inserts new data into a database.
o CREATE INDEX: it is used to create an index (search key).
o DROP INDEX: it deletes an index.

SQL Data Types


Data types are used to represent the nature of the data that can be stored in the database table. For example, in a particular column
of a table, if we want to store a string type of data then we will have to declare a string data type of this column.

Data types mainly classified into three categories for every database.

o String Data types


o Numeric Data types
o Date and time Data types
Data Types in MySQL, SQL Server and Oracle Databases

MySQL Data Types

A list of data types used in MySQL database. This is based on MySQL 8.0.

MySQL String Data Types

CHAR(Size) It is used to specify a fixed length string that can contain numbers, letters,
and special characters. Its size can be 0 to 255 characters. Default is 1.

VARCHAR(Size) It is used to specify a variable length string that can contain numbers,
letters, and special characters. Its size can be from 0 to 65535 characters.

BINARY(Size) It is equal to CHAR() but stores binary byte strings. Its size parameter
specifies the column length in the bytes. Default is 1.

VARBINARY(Size) It is equal to VARCHAR() but stores binary byte strings. Its size parameter
specifies the maximum column length in bytes.

TEXT(Size) It holds a string that can contain a maximum length of 255 characters.

TINYTEXT It holds a string with a maximum length of 255 characters.

MEDIUMTEXT It holds a string with a maximum length of 16,777,215.

LONGTEXT It holds a string with a maximum length of 4,294,967,295 characters.

ENUM(val1, val2, It is used when a string object having only one value, chosen from a list of
val3,...) possible values. It contains 65535 values in an ENUM list. If you insert a
value that is not in the list, a blank value will be inserted.

SET( val1,val2,val3,. It is used to specify a string that can have 0 or more values, chosen from a
...) list of possible values. You can list up to 64 values at one time in a SET list.

BLOB(size) It is used for BLOBs (Binary Large Objects). It can hold up to 65,535 bytes.

MySQL Numeric Data Types

BIT(Size) It is used for a bit-value type. The number of bits per value is specified in size. Its
size can be 1 to 64. The default value is 1.

INT(size) It is used for the integer value. Its signed range varies from -2147483648 to
2147483647 and unsigned range varies from 0 to 4294967295. The size
parameter specifies the max display width that is 255.
INTEGER(size) It is equal to INT(size).

FLOAT(size, d) It is used to specify a floating point number. Its size parameter specifies the total
number of digits. The number of digits after the decimal point is specified
by d parameter.

FLOAT(p) It is used to specify a floating point number. MySQL used p parameter to


determine whether to use FLOAT or DOUBLE. If p is between 0 to24, the data
type becomes FLOAT (). If p is from 25 to 53, the data type becomes DOUBLE().

DOUBLE(size, It is a normal size floating point number. Its size parameter specifies the total
d) number of digits. The number of digits after the decimal is specified by d
parameter.

DECIMAL(size, It is used to specify a fixed point number. Its size parameter specifies the total
d) number of digits. The number of digits after the decimal parameter is specified
by d parameter. The maximum value for the size is 65, and the default value is 10.
The maximum value for d is 30, and the default value is 0.

DEC(size, d) It is equal to DECIMAL(size, d).

BOOL It is used to specify Boolean values true and false. Zero is considered as false, and
nonzero values are considered as true.

MySQL Date and Time Data Types

Features of Java - Javatpoint

DATE It is used to specify date format YYYY-MM-DD. Its supported range is from
'1000-01-01' to '9999-12-31'.

DATETIME(fsp) It is used to specify date and time combination. Its format is YYYY-MM-DD
hh:mm:ss. Its supported range is from '1000-01-01 00:00:00' to 9999-12-31
23:59:59'.

TIMESTAMP(fsp It is used to specify the timestamp. Its value is stored as the number of seconds
) since the Unix epoch('1970-01-01 00:00:00' UTC). Its format is YYYY-MM-DD
hh:mm:ss. Its supported range is from '1970-01-01 00:00:01' UTC to '2038-01-
09 03:14:07' UTC.

TIME(fsp) It is used to specify the time format. Its format is hh:mm:ss. Its supported range
is from '-838:59:59' to '838:59:59'

YEAR It is used to specify a year in four-digit format. Values allowed in four digit
format from 1901 to 2155, and 0000.
SQL Server Data Types

SQL Server String Data Type

char(n) It is a fixed width character string data type. Its size can be up to 8000 characters.

varchar(n) It is a variable width character string data type. Its size can be up to 8000
characters.

varchar(max It is a variable width character string data types. Its size can be up to 1,073,741,824
) characters.

text It is a variable width character string data type. Its size can be up to 2GB of text
data.

nchar It is a fixed width Unicode string data type. Its size can be up to 4000 characters.

nvarchar It is a variable width Unicode string data type. Its size can be up to 4000 characters.

ntext It is a variable width Unicode string data type. Its size can be up to 2GB of text data.

binary(n) It is a fixed width Binary string data type. Its size can be up to 8000 bytes.

varbinary It is a variable width Binary string data type. Its size can be up to 8000 bytes.

image It is also a variable width Binary string data type. Its size can be up to 2GB.

SQL Server Numeric Data Types

bit It is an integer that can be 0, 1 or null.

tinyint It allows whole numbers from 0 to 255.

Smallin It allows whole numbers between -32,768 and 32,767.


t

Int It allows whole numbers between -2,147,483,648 and 2,147,483,647.

bigint It allows whole numbers between -9,223,372,036,854,775,808 and


9,223,372,036,854,775,807.

float(n) It is used to specify floating precision number data from -1.79E+308 to 1.79E+308. The n
parameter indicates whether the field should hold the 4 or 8 bytes. Default value of n is
53.
real It is a floating precision number data from -3.40E+38 to 3.40E+38.

money It is used to specify monetary data from -922,337,233,685,477.5808 to


922,337,203,685,477.5807.

SQL Server Date and Time Data Type

datetime It is used to specify date and time combination. It supports range from January 1,
1753, to December 31, 9999 with an accuracy of 3.33 milliseconds.

datetime2 It is used to specify date and time combination. It supports range from January 1,
0001 to December 31, 9999 with an accuracy of 100 nanoseconds

date It is used to store date only. It supports range from January 1, 0001 to December 31,
9999

time It stores time only to an accuracy of 100 nanoseconds

timestam It stores a unique number when a new row gets created or modified. The time stamp
p value is based upon an internal clock and does not correspond to real time. Each table
may contain only one-time stamp variable.

SQL Server Other Data Types

Sql_variant It is used for various data types except for text, timestamp, and ntext. It stores
up to 8000 bytes of data.

XML It stores XML formatted data. Maximum 2GB.

cursor It stores a reference to a cursor used for database operations.

table It stores result set for later processing.

uniqueidentifie It stores GUID (Globally unique identifier).


r

Oracle Data Types

Oracle String data types

CHAR(size) It is used to store character data within the predefined length. It can be stored
up to 2000 bytes.

NCHAR(size) It is used to store national character data within the predefined length. It can
be stored up to 2000 bytes.

VARCHAR2(size) It is used to store variable string data within the predefined length. It can be
stored up to 4000 byte.

VARCHAR(SIZE) It is the same as VARCHAR2(size). You can also use VARCHAR(size), but it is
suggested to use VARCHAR2(size)

NVARCHAR2(size It is used to store Unicode string data within the predefined length. We have
) to must specify the size of NVARCHAR2 data type. It can be stored up to 4000
bytes.

Oracle Numeric Data Types

NUMBER(p, s) It contains precision p and scale s. The precision p can range from 1 to 38, and
the scale s can range from -84 to 127.

FLOAT(p) It is a subtype of the NUMBER data type. The precision p can range from 1 to
126.

BINARY_FLOAT It is used for binary precision( 32-bit). It requires 5 bytes, including length byte.

BINARY_DOUBL It is used for double binary precision (64-bit). It requires 9 bytes, including
E length byte.

Oracle Date and Time Data Types

DATE It is used to store a valid date-time format with a fixed length. Its range varies from
January 1, 4712 BC to December 31, 9999 AD.

TIMESTAM It is used to store the valid date in YYYY-MM-DD with time hh:mm:ss format.
P

Oracle Large Object Data Types (LOB Types)

BLOB It is used to specify unstructured binary data. Its range goes up to 2 32-1 bytes or 4 GB.

BFILE It is used to store binary data in an external file. Its range goes up to 2 32-1 bytes or 4
GB.

CLOB It is used for single-byte character data. Its range goes up to 2 32-1 bytes or 4 GB.

NCLOB It is used to specify single byte or fixed length multibyte national character set
(NCHAR) data. Its range is up to 232-1 bytes or 4 GB.
RAW(size) It is used to specify variable length raw binary data. Its range is up to 2000 bytes per
row. Its maximum size must be specified.

LONG It is used to specify variable length raw binary data. Its range up to 2 31-1 bytes or 2
RAW GB, per row.

SQL Operators
SQL statements generally contain some reserved words or characters that are used to perform operations such as comparison and
arithmetical operations etc. These reserved words or characters are known as operators.

Generally there are three types of operators in SQL:

1. SQL Arithmetic Operators


2. SQL Comparison Operators
3. SQL Logical Operators

SQL Arithmetic Operators:

Let's assume two variables "a" and "b". Here "a" is valued 50 and "b" valued 100.

Example:

Operator Descriptions Examples


s

+ It is used to add containing values of both operands a+b will give 150

- It subtracts right hand operand from left hand operand a-b will give -50

* It multiply both operand's values a*b will give


5000

/ It divides left hand operand by right hand operand b/a will give 2

% It divides left hand operand by right hand operand and returns b%a will give 0
reminder

SQL Comparison Operators:

Let's take two variables "a" and "b" that are valued 50 and 100.

Operator Description Example

= Examine both operands value that are equal or not,if yes condition (a=b) is not
become true. true

!= This is used to check the value of both operands equal or not,if not (a!=b) is true
condition become true.
<> Examines the operand's value equal or not, if values are not equal (a<>b) is true
condition is true

> Examine the left operand value is greater than right Operand, if yes (a>b) is not
condition becomes true true

< Examines the left operand value is less than right Operand, if yes (a<=""
condition becomes true td="">

>= Examines that the value of left operand is greater than or equal to the (a>=b) is not
value of right operand or not,if yes condition become true true

<= Examines that the value of left operand is less than or equal to the (a<=b) is true
value of right operand or not, if yes condition becomes true

!< Examines that the left operand value is not less than the right operand (a!<=""
value td="">

!> Examines that the value of left operand is not greater than the value of (a!>b) is true
right operand

SQL Logical Operators:

This is the list of logical operators used in SQL.

C++ vs Java

Operator Description

ALL this is used to compare a value to all values in another value set.

AND this operator allows the existence of multiple conditions in an SQL statement.

ANY this operator is used to compare the value in list according to the condition.

BETWEEN this operator is used to search for values, that are within a set of values

IN this operator is used to compare a value to that specified list value

NOT the NOT operator reverse the meaning of any logical operator

OR this operator is used to combine multiple conditions in SQL statements

EXISTS the EXISTS operator is used to search for the presence of a row in a specified table

LIKE this operator is used to compare a value to similar values using wildcard operator

SQL CREATE Database


The SQL CREATE DATABASE statement is used by a developer to create a database.

Let's see the syntax of SQL CREATE DATABASE:

1. CREATE DATABASE database_name;  

If you want to add tables in that database, you can use CREATE TABLE statement.
Create Database in MySQL

In MySQL, same command is used to create a database.

1. CREATE DATABASE database_name;  

Create Database in Oracle

You don't need to create database in Oracle. In Oracle database, you can create tables directly.

You can also rename, drop and select database that is covered in next pages.

C++ vs Java

We should always remember that database name should be unique in the RDBMS.

SQL DROP Database


SQL DROP statement is used to delete or remove indexes from a table in the database.

If you want to delete or drop an existing database in a SQL schema, you can use SQL DROP DATABASE

Let's see the syntax of SQL DROP DATABASE:

1. DROP DATABASE database_name;  

If you delete or drop the database, all the tables and views will also be deleted. So be careful while using this command.

SQL RENAME Database


SQL RENAME DATABASE is used when you need to change the name of your database. Sometimes it is used because you think that
the original name is not more relevant to the database or you want to give a temporary name to that database.

Let's see how to rename MySql and SQL Server databases.

Rename MySQL database

To rename the mysql database, you need to follow the following syntax:

1. RENAME DATABASE old_db_name TO new_db_name;  
Rename SQL server database using T-SQL

This command is useful for SQL server 2005, 2008, 2008R2 and 2012.

1. ALTER DATABASE old_name MODIFY NAME = new_name  

If you are using SQL server 2000, you can also use this command to rename the database. But, Microsoft phased out it.

1. EXEC sp_renamedb 'old_name' , 'new_name'  

SQL SELECT Database


In MySQL database, you need to select a database first before executing any query on table, view etc. To do so, we use following
query:

1. USE DATABASE database_name;  

In oracle, you don't need to select database.

SQL Table
Table is a collection of data, organized in terms of rows and columns. In DBMS term, table is known as relation and row as tuple.

Note: A table has a specified number of columns, but can have any number of rows.

Table is the simple form of data storage. A table is also considered as a convenient representation of relations.

Let's see an example of an employee table:

Employee

EMP_NAME ADDRESS SALARY

Ankit Lucknow 15000

Raman Allahabad 18000

Mike New York 20000

In the above table, "Employee" is the table name, "EMP_NAME", "ADDRESS" and "SALARY" are the column names. The combination
of data of multiple columns forms a row e.g. "Ankit", "Lucknow" and 15000 are the data of one row.

SQL TABLE Variable

The SQL Table variable is used to create, modify, rename, copy and delete tables. Table variable was introduced by Microsoft.
It was introduced with SQL server 2000 to be an alternative of temporary tables.

It is a variable where we temporary store records and results. This is same like temp table but in the case of temp table we need to
explicitly drop it.

Table variables are used to store a set of records. So declaration syntax generally looks like CREATE TABLE syntax.

1. create table "tablename"  
2. ("column1" "data type",  
3. "column2" "data type",  
4. ...  
5. "columnN" "data type");  

When a transaction rolled back the data associated with table variable is not rolled back.

A table variable generally uses lesser resources than a temporary variable.

Table variable cannot be used as an input or an output parameter.

Topics of SQL TABLE Statement

SQL TABLE Variable

What TABLE variable can do?

SQL CREATE TABLE

How to create a table using SQL query>

SQL DROP TABLE

How to drop a table?

SQL DELETE TABLE

How to delete all the records of a table?

SQL RENAME TABLE

How to rename a table?

SQL TRUNCATE TABLE

How to truncate a table?

SQL COPY TABLE

How to copy a table?


SQL TEMP TABLE

What is temporary table? What are the advantage of temporary table?

SQL ALTER TABLE

How to add, modify, rename and drop column.

SQL CREATE TABLE


SQL CREATE TABLE statement is used to create table in a database.

If you want to create a table, you should name the table and define its column and each column's data type.

Let's see the simple syntax to create the table.

1. create table "tablename"  
2. ("column1" "data type",  
3. "column2" "data type",  
4. "column3" "data type",  
5. ...  
6. "columnN" "data type");  

The data type of the columns may vary from one database to another. For example, NUMBER is supported in Oracle database for
integer value whereas INT is supported in MySQL.

Let us take an example to create a STUDENTS table with ID as primary key and NOT NULL are the constraint showing that these
fields cannot be NULL while creating records in the table.

1. SQL> CREATE TABLE STUDENTS (  
2. ID INT                           NOT NULL,  
3. NAME VARCHAR (20) NOT NULL,  
4. AGE INT                         NOT NULL,  
5. ADDRESS CHAR (25),  
6. PRIMARY KEY (ID)  
7. );  

You can verify it, if you have created the table successfully by looking at the message displayed by the SQL Server, else you can use
DESC command as follows:

SQL> DESC STUDENTS;

FIELD TYPE NULL KEY DEFAULT EXTRA

ID Int(11) NO PRI

NAME Varchar(20) NO

AGE Int(11) NO
ADDRESS Varchar(25) YES NULL

4 rows in set (0.00 sec)

Now you have the STUDENTS table available in your database and you can use to store required information related to students.

SQL CREATE TABLE Example in MySQL

Let's see the command to create a table in MySQL database.

1. CREATE TABLE Employee  
2. (  
3. EmployeeID int,  
4. FirstName varchar(255),  
5. LastName varchar(255),  
6. Email varchar(255),  
7. AddressLine varchar(255),  
8. City varchar(255)  
9. );  

SQL CREATE TABLE Example in Oracle

Let's see the command to create a table in Oracle database.

1. CREATE TABLE Employee  
2. (  
3. EmployeeID number(10),  
4. FirstName varchar2(255),  
5. LastName varchar2(255),  
6. Email varchar2(255),  
7. AddressLine varchar2(255),  
8. City varchar2(255)  
9. );  

SQL CREATE TABLE Example in Microsoft SQLServer

Let's see the command to create a table in SQLServer database. It is same as MySQL and Oracle.

1. CREATE TABLE Employee  
2. (  
3. EmployeeID int,  
4. FirstName varchar(255),  
5. LastName varchar(255),  
6. Email varchar(255),  
7. AddressLine varchar(255),  
8. City varchar(255)  
9. );  
Create a Table using another table

We can create a copy of an existing table using the create table command. The new table gets the same column signature as the old
table. We can select all columns or some specific columns.

If we create a new table using an old table, the new table will be filled with the existing value from the
old table.

The basic syntax for creating a table with the other table is:

1. CREATE TABLE table_name  AS  
2. SELECT column1, column2,...   
3. FROM old_table_name WHERE ..... ;  
4. The following SQL creates a copy of the employee table.  
5. CREATE TABLE EmployeeCopy AS  
6. SELECT EmployeeID, FirstName, Email  
7. FROM Employee;  

SQL Primary Key with CREATE TABLE Statement

The following query creates a PRIMARY KEY on the "D" column when the "Employee" table is created.

MySQL
1. CREATE TABLE Employee(  
2. EmployeeID NOT NULL,  
3. FirstName varchar(255) NOT NULL,  
4. LastName varchar(255),  
5. City varchar(255),  
6. PRIMARY KEY (EmployeeID)  
7. );  

SQL Server / Oracle / MS Access


1. CREATE TABLE Employee(  
2. EmployeeID NOT NULL PRIMARY KEY,  
3. FirstName varchar(255) NOT NULL,  
4. LastName varchar(255),  
5. City varchar(255)  
6. );  

Use the following query to define a PRIMARY KEY constraints on multiple columns, and to allow naming of a PRIMARY KEY
constraints.

For MySQL / SQL Server /Oracle / MS Access


1. CREATE TABLE Employee(  
2. EmployeeID NOT NULL,  
3. FirstName varchar(255) NOT NULL,  
4. LastName varchar(255),  
5. City varchar(255),  
6. CONSTRAINT     PK_Employee PRIMARY KEY (EmployeeID, FirstName)  
7. );  
SQL DROP TABLE
A SQL DROP TABLE statement is used to delete a table definition and all data from a table.

This is very important to know that once a table is deleted all the information available in the table is lost forever, so we have to be
very careful when using this command.

Let's see the syntax to drop the table from the database.

1. DROP TABLE "table_name";  

Let us take an example:

First we verify STUDENTS table and then we would delete it from the database.

1. SQL> DESC STUDENTS;  

FIELD TYPE NULL KEY DEFAULT EXTRA

ID Int(11) NO PRI

NAME Varchar(20) NO

AGE Int(11) NO

ADDRESS Varchar(25) YES NULL

1. 4 rows in set (0.00 sec)  

This shows that STUDENTS table is available in the database, so we can drop it as follows:

Triggers in SQL (Hindi)

1. SQL>DROP TABLE STUDENTS;  

Now, use the following command to check whether table exists or not.

1. SQL> DESC STUDENTS;  

1. Query OK, 0 rows affected (0.01 sec)  

As you can see, table is dropped so it doesn't display it.

SQL DROP TABLE Example in MySQL

Let's see the command to drop a table from the MySQL database.

1. DROP TABLE table_name;  
SQL DROP TABLE Example in Oracle

Let's see the command to drop a table from Oracle database. It is same as MySQL.

1. DROP TABLE table_name;  

SQL DROP TABLE Example in Microsoft SQLServer

Let's see the command to drop a table from SQLServer database. It is same as MySQL.

1. DROP TABLE table_name;  

SQL DELETE TABLE


The DELETE statement is used to delete rows from a table. If you want to remove a specific row from a table you should use WHERE
condition.

1. DELETE FROM table_name [WHERE condition];  

But if you do not specify the WHERE condition it will remove all the rows from the table.

1. DELETE FROM table_name;  

There are some more terms similar to DELETE statement like as DROP statement and TRUNCATE statement but they are not exactly
same there are some differences between them.

Difference between DELETE and TRUNCATE statements

There is a slight difference b/w delete and truncate statement. The DELETE statement only deletes the rows from the table based on
the condition defined by WHERE clause or delete all the rows from the table when condition is not specified.

But it does not free the space containing by the table.

The TRUNCATE statement: it is used to delete all the rows from the table and free the containing space.

Triggers in SQL (Hindi)

Let's see an "employee" table.

Emp_id Name Address Salary

1 Aryan Allahabad 22000

2 Shurabhi Varanasi 13000

3 Pappu Delhi 24000

Execute the following query to truncate the table:


1. TRUNCATE TABLE employee;  

Difference b/w DROP and TRUNCATE statements

When you use the drop statement it deletes the table's row together with the table's definition so all the relationships of that table
with other tables will no longer be valid.

When you drop a table:

o Table structure will be dropped


o Relationship will be dropped
o Integrity constraints will be dropped
o Access privileges will also be dropped

On the other hand when we TRUNCATE a table, the table structure remains the same, so you will not face any of the above
problems.

SQL RENAME TABLE


SQL RENAME TABLE syntax is used to change the name of a table. Sometimes, we choose non-meaningful name for the table. So it
is required to be changed.

Let's see the syntax to rename a table from the database.

1. ALTER TABLE table_name   
2. RENAME TO new_table_name;  

Optionally, you can write following command to rename the table.

1. RENAME old_table _name To new_table_name;  

Let us take an example of a table named "STUDENTS", now due to some reason we want to change it into table name "ARTISTS".

Table1: students

Name Age City

Amrita gill 25 Amritsar

Amrender sirohi 22 Ghaziabad

Divya khosla 20 Delhi

You should use any one of the following syntax to RENAME the table name:

1. ALTER TABLE STUDENTS  
2. RENAME TO ARTISTS;  

Or
1. RENAME STUDENTS TO ARTISTS;  
2. After that the table "students" will be changed into table name "artists"  

SQL TRUNCATE TABLE


A truncate SQL statement is used to remove all rows (complete data) from a table. It is similar to the DELETE statement with no
WHERE clause.

TRUNCATE TABLE Vs DELETE TABLE

Truncate table is faster and uses lesser resources than DELETE TABLE command.

TRUNCATE TABLE Vs DROP TABLE

Drop table command can also be used to delete complete table but it deletes table structure too. TRUNCATE TABLE doesn't delete
the structure of the table.

Let's see the syntax to truncate the table from the database.

1. TRUNCATE TABLE table_name;  

For example, you can write following command to truncate the data of employee table

1. TRUNCATE TABLE Employee;  

SQL ALTER TABLE


The ALTER TABLE statement is used to add, modify or delete columns in an existing table. It is also used to rename a table.

You can also use SQL ALTER TABLE command to add and drop various constraints on an existing table.

SQL ALTER TABLE Add Column

If you want to add columns in SQL table, the SQL alter table syntax is given below:

1. ALTER TABLE table_name ADD column_name column-definition;  

If you want to add multiple columns in table, the SQL table will be

1. ALTER TABLE table_name   
2. ADD (column_1 column-definition,  
3.            column_2 column-definition,  
4.            .....  
5.            column_n column-definition);  

SQL ALTER TABLE Modify Column

If you want to modify an existing column in SQL table, syntax is given below:

1. ALTER TABLE table_name MODIFY column_name column_type;  

If you want to modify multiple columns in table, the SQL table will be

Difference between JDK, JRE, and JVM

1. ALTER TABLE table_name   
2. MODIFY (column_1 column_type,  
3.                   column_2 column_type,  
4.                  .....  
5.                   column_n column_type);  

SQL ALTER TABLE DROP Column

The syntax of alter table drop column is given below:

1. ALTER TABLE table_name DROP COLUMN column_name;  

SQL ALTER TABLE RENAME Column

The syntax of alter table rename column is given below:

1. ALTER TABLE table_name  
2. RENAME COLUMN old_name to new_name; 

SQL SELECT
The most commonly used SQL command is SELECT statement. It is used to query the database and retrieve selected data that
follow the conditions we want.

In simple words, we can say that the select statement used to query or retrieve data from a table in the database.

Let's see the syntax of select statement.

1. SELECT expressions  
2. FROM tables  
3. WHERE conditions;  

Here expression is the column that we want to retrieve.


Tables indicate the tables, we want to retrieve records from.

Optional clauses in SELECT statement

There are some optional clauses in SELECT statement:

Hello Java Program for Beginners

[WHERE Clause] : It specifies which rows to retrieve.

[GROUP BY Clause] : Groups rows that share a property so that the aggregate function can be applied to each group.

[HAVING Clause] : It selects among the groups defined by the GROUP BY clause.

[ORDER BY Clause] : It specifies an order in which to return the rows.

For example, let a database table: student_details;

ID First_name Last_name Age Subject Hobby

1 Amar Sharma 20 Maths Cricket

2 Akbar Khan 22 Biology Football

3 Anthony Milton 25 Commerce Gambling

From the above example, select the first name of all the students. To do so, query should be like this:

1. SELECT first_name FROM student_details;  

Note: the SQL commands are not case sensitive. We can also write the above SELECT statement as:

1. select first_name from student_details;  

Now, you will get following data:


Amar

Akbar

Anthony

We can also retrieve data from more than one column. For example, to select first name and last name of all the students, you need
to write

1. SELECT first_name, last_name FROM student_details;  

Now, you will get following data:

Amar Sharma

Akbar Khan
Anthony Milton

We can also use clauses like WHERE, GROUP BY, HAVING, ORDER BY with SELECT statement.

Here a point is notable that only SELECT and FROM statements are necessary in SQL SELECT statements. Other clauses like WHERE,
GROUP BY, ORDER BY, HAVING may be optional.

SQL SELECT UNIQUE


Actually, there is no difference between DISTINCT and UNIQUE.

SELECT UNIQUE is an old syntax which was used in oracle description but later ANSI standard defines DISTINCT as the official
keyword.

After that oracle also added DISTINCT but did not withdraw the service of UNIQUE keyword for the sake of backward compatibility.

In simple words, we can say that SELECT UNIQUE statement is used to retrieve a unique or distinct element from the table.

Let's see the syntax of select unique statement.

1. SELECT UNIQUE column_name  
2. FROM table_name;  

SQL SELECT DISTINCT statement can also be used for the same cause.

SQL SELECT DISTINCT


The SQL DISTINCT command is used with SELECT key word to retrieve only distinct or unique data.

In a table, there may be a chance to exist a duplicate value and sometimes we want to retrieve only unique values. In such scenarios,
SQL SELECT DISTINCT statement is used.

Note: SQL SELECT UNIQUE and SQL SELECT DISTINCT statements are same.

Let's see the syntax of select distinct statement.

1. SELECT DISTINCT column_name ,column_name  
2. FROM  table_name;  

Let's try to understand it by the table given below:

Student_Name Gender Mobile_Number HOME_TOWN

Rahul Ojha Male 7503896532 Lucknow

Disha Rai Female 9270568893 Varanasi

Sonoo Jaiswal Male 9990449935 Lucknow


Here is a table of students from where we want to retrieve distinct information For example: distinct home-town.

1. SELECT DISTINCT home_town  
2. FROM students  

Now, it will return two rows.

HOME_TOWN

Lucknow

Varanasi

SQL SELECT COUNT


The SQL COUNT() function is used to return the number of rows in a query.

The COUNT() function is used with SQL SELECT statement and it is very useful to count the number of rows in a table having
enormous data.

For example: If you have a record of the voters in selected area and want to count the number of voters then it is very difficult to do
it manually but you can do it easily by using the SQL SELECT COUNT query.

Let's see the syntax of SQL COUNT statement.

1. SELECT COUNT (expression)  
2. FROM tables  
3. WHERE conditions;  

Let's see the examples of sql select count function.

SQL SELECT COUNT(column_name)


1. SELECT COUNT(name) FROM employee_table;  

It will return the total number of names of employee_table. But null fields will not be counted.

SQL SELECT COUNT(*)


1. SELECT COUNT(*) FROM employee_table;  

The "select count(*) from table" is used to return the number of records in table.
SQL SELECT COUNT(DISTINCT column_name)
1. SELECT COUNT(DISTINCT name) FROM employee_table;  

It will return the total distinct names of employee_table.

SQL SELECT AS
SQL AS is used to assign temporarily a new name to a table column.

It makes easy presentation of query results and allows the developer to label results more accurately without permanently renaming
table columns.

Let's see the example of select as:

1. SELECT day_of_order AS "Date"  
2. Customer As "Client",  
3. Product,  
4. Quantity,  
5. FROM orders;  

Let us take a table named orders, it contains:

Day_of_order Customer Product Quantity

11-09-2001 Ajeet Mobile 2

13-12-2001 Mayank Laptop 20

26-12-2004 Balaswamy Water cannon 35

After applying this SQL AS example syntax

1. SELECT day_of_order AS "Date"    
2. Customer As "Client",    
3. Product,    
4. Quantity,    
5. FROM orders;    

Result will be shown as this table:

Date Client Product Quantity

11-09-2001 Ajeet Mobile 2

13-12-2001 Mayank Laptop 20

26-12-2004 Balaswamy Water cannon 35


Note: SQL AS is same as SQL ALIAS.

SQL SELECT IN
SQL IN is an operator used in a SQL query to help reduce the need to use multiple SQL "OR" conditions.

It is used in SELECT, INSERT, UPDATE or DELETE statement.

Advantage of SQL SELECT IN

It minimizes the use of SQL OR operator.

Let's see the syntax for SQL IN:

1. Expression IN (value 1, value 2 ... value n);  

Take an example with character values.

1. SELECT *  
2. FROM students  
3. WHERE students_name IN ( Amit , Raghav, Rajeev)  

Let's take another example with numeric values.

1. SELECT *  
2. FROM marks  
3. WHERE roll_no IN (001, 023, 024);  

SQL SELECT from Multiple Tables


This statement is used to retrieve fields from multiple tables. To do so, we need to use join query to get data from multiple tables.

Let's see the example for the select from multiple tables:

1. SELECT orders.order_id, suppliers.name   
2. FROM suppliers  
3. INNER JOIN orders  
4. ON suppliers.supplier_id = orders.supplier_id  
5. ORDER BY order_id;  

Let us take three tables, two tables of customers named customer1 and customer2 and the third table is product table.

Customer1 table
Cus_id Name1

1 Jack

2 Jill

Customer2 table

Cus_id Name2

1 Sandy

2 Venus

Product table

Triggers in SQL (Hindi)

P_id Cus_id P_name

1 1 Laptop

2 2 Phone

3 P1 Pen

4 P2 Notebook

Example syntax to select from multiple tables:

1. SELECT p. p_id, p.cus_id, p.p_name, c1.name1, c2.name2  
2. FROM product AS p  
3. LEFT JOIN customer1 AS c1  
4. ON p.cus_id=c1.cus_id  
5. LEFT JOIN customer2 AS c2  
6. ON p.cus_id = c2.cus_id  

P_id Cus_id P_name P_name P_name

1 1 Laptop Jack NULL

2 2 Phone Jill NULL

3 P1 Pen NULL Sandy

4 P2 Notebook NULL Venus

SQL SELECT DATE


SQL SELECT DATE is used to retrieve a date from a database. If you want to find a particular date from a database, you can use this
statement.

For example: let's see the query to get all the records after '2013-12-12'.
1. SELECT * FROM   
2. table-name WHERE your date-column >= '2013-12-12'  

Let's see the another query to get all the records after '2013-12-12' and before '2013-12-13' date.

1. SELECT* FROM   
2. table-name where your date-column < '2013-12-13' and your date-column >= '2013-12-12'  

If you want to compare the dates within the query, you should use BETWEEN operator to compare the dates.

1. SELECT * FROM   
2. table_name WHERE yourdate BETWEEN '2012-12-12' and '2013-12-12'  

Or if you are looking for one date in particular you can use. You should change the date parameter into the acceptable form.

1. SELECT* FROM   
2. table_name WHERE cast (datediff (day, 0, yourdate) as datetime) = '2012-12-12'  

SQL INSERT STATEMENT


SQL INSERT statement is a SQL query. It is used to insert a single or a multiple records in a table.

There are two ways to insert data in a table:

1. By SQL insert into statement


1. By specifying column names
2. Without specifying column names
2. By SQL insert into select statement

1) Inserting data directly into a table

You can insert a row in the table by using SQL INSERT INTO command.

There are two ways to insert values in a table.

HTML Tutorial

In the first method there is no need to specify the column name where the data will be inserted, you need only their values.

1. INSERT INTO table_name  
2. VALUES (value1, value2, value3....);  

The second method specifies both the column name and values which you want to insert.

1. INSERT INTO table_name (column1, column2, column3....)  
2. VALUES (value1, value2, value3.....);  
Let's take an example of table which has five records within it.

1. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
2. VALUES (1, ABHIRAM, 22, ALLAHABAD);  
3. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
4. VALUES (2, ALKA, 20, GHAZIABAD);  
5. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
6. VALUES (3, DISHA, 21, VARANASI);  
7. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
8. VALUES (4, ESHA, 21, DELHI);  
9. INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)  
10. VALUES (5, MANMEET, 23, JALANDHAR);  

It will show the following table as the final result.

ROLL_NO NAME AGE CITY

1 ABHIRAM 22 ALLAHABAD

2 ALKA 20 GHAZIABAD

3 DISHA 21 VARANASI

4 ESHA 21 DELHI

5 MANMEET 23 JALANDHAR

You can create a record in CUSTOMERS table by using this syntax also.

1. INSERT INTO CUSTOMERS   
2. VALUES (6, PRATIK, 24, KANPUR);  

The following table will be as follow:

ROLL_NO NAME AGE CITY

1 ABHIRAM 22 ALLAHABAD

2 ALKA 20 GHAZIABAD

3 DISHA 21 VARANASI

4 ESHA 21 DELHI

5 MANMEET 23 JALANDHAR

6 PRATIK 24 KANPUR

2) Inserting data through SELECT Statement

SQL INSERT INTO SELECT Syntax

1. INSERT INTO table_name  
2. [(column1, column2, .... column)]  
3. SELECT column1, column2, .... Column N  
4. FROM table_name [WHERE condition];  

Note: when you add a new row, you should make sure that data type of the value and the column
should be matched.

If any integrity constraints are defined for the table, you must follow them.

SQL INSERT MULTIPLE ROWS


Many times developers ask that is it possible to insert multiple rows into a single table in a single statement. Currently developers
have to write multiple insert statement when they insert values in a table. It is not only boring, also time consuming. To get rid from
this you should try this syntax. Actually there are three different methods to insert multiple values into a single table.

1. Traditional method (simple insert)


2. SQL insert select
3. SQL server 2008+ Row Construction

Insert multiple values in SQL server

1. CREATE TABLE student (ID INT VALUE VARCHAR (100));  

1. SQL INSERT: (TRADITIONAL INSERT)

1. INSERT INTO student (ID, NAME)  
2. VALUES (1, 'ARMAAN');  
3. INSERT INTO student (ID, NAME)  
4. VALUES (2, 'BILLY');  
5. INSERT INTO student (ID, NAME)  
6. VALUES (3, 'CHARLIE');  

TO CLEAN-UP:

1. TRUNCATE TABLE student;  

2. INSERT SELECT: (SELECT UNION INSERT)

1. INSERT INTO student (ID, NAME)  
2. SELECT 1, 'ARMAAN'  
3. UNION ALL   
4. SELECT 2, 'BILLY'  
5. UNION ALL  
6. SELECT 3, 'CHARLIE';  
7. TO CLEAN-UP:  
8. TRUNCATE TABLE student;  

3.SQL Server 2008+ Row Construction

Difference between JDK, JRE, and JVM

1. INSERT INTO student (ID, NAME)  
2. VALUES (1, 'ARMAAN'), (2, 'BILLY'), (3, 'CHARLIE');  
3. TO CLEAN-UP:  
4. DROP TABLE student;  

Note:Row Constructor is a new feature for SQL Server 2008. It is not supported by SQL Server 2005.

Next Topic SQL Update

SQL UPDATE
The SQL commands (UPDATE and DELETE) are used to modify the data that is already in the database. The SQL DELETE command
uses a WHERE clause.

SQL UPDATE statement is used to change the data of the records held by tables. Which rows is to be update, it is decided by a
condition. To specify condition, we use WHERE clause.

The UPDATE statement can be written in following form:

1. UPDATE table_name SET [column_name1= value1,... column_nameN = valueN] [WHERE condition]  

Let's see the Syntax:

1. UPDATE table_name  
2. SET column_name = expression  
3. WHERE conditions  

Let's take an example: here we are going to update an entry in the source table.

SQL statement:

Difference between JDK, JRE, and JVM

1. UPDATE students  
2. SET User_Name = 'beinghuman'  
3. WHERE Student_Id = '3'  

Source Table:

Student_Id FirstName LastName User_Name

1 Ada Sharma sharmili

2 Rahul Maurya sofamous

3 James Walker jonny

See the result after updating value:

Student_Id FirstName LastName User_Name

1 Ada Sharma sharmili


2 Rahul Maurya sofamous

3 James Walker beinghuman

Updating Multiple Fields:

If you are going to update multiple fields, you should separate each field assignment with a comma.

SQL UPDATE statement for multiple fields:

1. UPDATE students  
2. SET User_Name = 'beserious', First_Name = 'Johnny'  
3. WHERE Student_Id = '3'  

Result of the table is given below:

Student_Id FirstName LastName User_Name

1 Ada Sharma sharmili

2 Rahul Maurya sofamous

3 Johnny Walker beserious

MYSQL SYNTAX FOR UPDATING TABLE:

1. UPDATE table_name  
2. SET field1 = new-value1, field2 = new-value2,  
3. [WHERE CLAUSE]  

SQL UPDATE SELECT:

SQL UPDATE WITH SELECT QUERY:

We can use SELECT statement to update records through UPDATE statement.

SYNTAX:

1. UPDATE tableDestination  
2. SET tableDestination.col = value  
3. WHERE EXISTS (  
4. SELECT col2.value  
5. FROM  tblSource  
6. WHERE tblSource.join_col = tblDestination. Join_col  
7. AND  tblSource.Constraint = value)  

You can also try this one -

1. UPDATE   
2. Table   
3. SET  
4. Table.column1 = othertable.column 1,  
5. Table.column2 = othertable.column 2  
6. FROM   
7. Table  
8. INNER JOIN  
9. Other_table  
10. ON  
11. Table.id = other_table.id  

My SQL SYNTAX:

If you want to UPDATE with SELECT in My SQL, you can use this syntax:

Let's take an example having two tables. Here,

First table contains -

Cat_id, cat_name,

And the second table contains -

Rel_cat_id, rel_cat_name

SQL UPDATE COLUMN:

We can update a single or multiple columns in SQL with SQL UPDATE query.

SQL UPDATE EXAMPLE WITH UPDATING SINGLE COLUMN:

1. UPDATE students  
2. SET student_id = 001  
3. WHERE student_name = 'AJEET';  

This SQL UPDATE example would update the student_id to '001' in the student table where student_name is 'AJEET'.

SQL UPDATE EXAMPLE WITH UPDATING MULTIPLE COLUMNS:

To update more than one column with a single update statement:

1. UPDATE students  
2. SET student_name = 'AJEET',  
3. Religion = 'HINDU'  
4. WHERE student_name = 'RAJU';  

This SQL UPDATE statement will change the student name to 'AJEET' and religion to 'HINDU' where the student name is 'RAJU'.

SQL UPDATE with JOIN


SQL UPDATE JOIN means we will update one table using another table and join condition.

Let us take an example of a customer table. I have updated customer table that contains latest customer details from another source
system. I want to update the customer table with latest data. In such case, I will perform join between target table and source table
using join on customer ID.

Let's see the syntax of SQL UPDATE query with JOIN statement.

1. UPDATE customer_table  
2. INNER JOIN  
3. Customer_table  
4. ON customer_table.rel_cust_name = customer_table.cust_id  
5. SET customer_table.rel_cust_name = customer_table.cust_name  

How to use multiple tables in SQL UPDATE statement with JOIN

Let's take two tables, table 1 and table 2.

Create table1

1. CREATE TABLE table1 (column1 INT, column2 INT, column3 VARCHAR (100))  
2. INSERT INTO table1 (col1, col2, col3)  
3. SELECT 1, 11, 'FIRST'  
4. UNION ALL  
5. SELECT 11,12, 'SECOND'  
6. UNION ALL   
7. SELECT 21, 13, 'THIRD'  
8. UNION ALL   
9. SELECT 31, 14, 'FOURTH'  

Create table2

SQL CREATE TABLE

1. CREATE TABLE table2 (column1 INT, column2 INT, column3 VARCHAR (100))  
2. INSERT INTO table2 (col1, col2, col3)  
3. SELECT 1, 21, 'TWO-ONE'  
4. UNION ALL  
5. SELECT 11, 22, 'TWO-TWO'  
6. UNION ALL   
7. SELECT 21, 23, 'TWO-THREE'  
8. UNION ALL   
9. SELECT 31, 24, 'TWO-FOUR'  

Now check the content in the table.

1. SELECT * FROM table_1  
1. SELECT * FROM table_2  

Col 1 Col 2 Col 3


1 1 11 First

2 11 12 Second

3 21 13 Third

4 31 14 Fourth

Col 1 Col 2 Col 3

1 1 21 Two-One

2 11 22 Two-Two

3 21 23 Two-Three

4 31 24 Two-Four

Our requirement is that we have table 2 which has two rows where Col 1 is 21 and 31. We want to update the value from table 2 to
table 1 for the rows where Col 1 is 21 and 31.

We want to also update the values of Col 2 and Col 3 only.

The most easiest and common way is to use join clause in the update statement and use multiple tables in the update statement.

1. UPDATE table 1  
2. SET Col 2 = t2.Col2,  
3. Col 3 = t2.Col3  
4. FROM table1 t1  
5. INNER JOIN table 2 t2 ON t1.Col1 = t2.col1  
6. WHERE t1.Col1 IN (21,31)  

Check the content of the table

SELECT FROM table 1

SELECT FROM table 2

Col 1 Col 2 Col 3

1 1 11 First

2 11 12 Second
3 21 23 Two-Three

4 31 24 Two-Four

Col 1 Col 2 Col 3

1 1 21 First

2 11 22 Second

3 21 23 Two-Three

4 31 24 Two-Four

Here we can see that using join clause in update statement. We have merged two tables by the use of
join clause.

SQL UPDATE DATE


How to update a date and time field in SQL?

If you want to update a date & time field in SQL, you should use the following query.

let's see the syntax of sql update date.

1. UPDATE table   
2. SET Column_Name = 'YYYY-MM-DD HH:MM:SS'  
3. WHERE Id = value  

Let us check this by an example:

Firstly we take a table in which we want to update date and time fields.

If you want to change the first row which id is 1 then you should write the following syntax:

Features of Java - Javatpoint

1. UPDATE table   
2. SET EndDate = '2014-03-16 00:00:00.000'   
3. WHERE Id = 1   

<pNote: you should always remember that SQL must attach default 00:00:00.000 automatically.

This query will change the date and time field of the first row in that above assumed table.

</p
SQL DELETE
The SQL DELETE statement is used to delete rows from a table. Generally DELETE statement removes one or more records from a
table.

SQL DELETE Syntax

Let's see the Syntax for the SQL DELETE statement:

1. DELETE FROM table_name [WHERE condition];  

Here table_name is the table which has to be deleted. The WHERE clause in SQL DELETE statement is optional here.

SQL DELETE Example

Let us take a table, named "EMPLOYEE" table.

ID EMP_NAME CITY SALARY

101 Adarsh Singh Obra 20000

102 Sanjay Singh Meerut 21000

103 Priyanka Sharma Raipur 25000

104 Esha Singhal Delhi 26000

Example of delete with WHERE clause is given below:

1. DELETE FROM EMPLOYEE WHERE ID=101;  

Resulting table after the query:

Prime Ministers of India | List of Prime Minister of India (1947-2020)

ID EMP_NAME CITY SALARY

102 Sanjay Singh Meerut 21000

103 Priyanka Sharma Raipur 25000

104 Esha Singhal Delhi 26000


Another example of delete statement is given below

1. DELETE FROM EMPLOYEE;  

Resulting table after the query:

ID EMP_NAME CITY SALARY

It will delete all the records of EMPLOYEE table.

It will delete the all the records of EMPLOYEE table where ID is 101.

The WHERE clause in the SQL DELETE statement is optional and it identifies the rows in the column that gets deleted.

WHERE clause is used to prevent the deletion of all the rows in the table, If you don't use the WHERE clause you might loss all the
rows.

Invalid DELETE Statement for ORACLE database

You cannot use * (asterisk) symbol to delete all the records.

1. DELETE * FROM EMPLOYEE;  

Topics of SQL DELETE Statement

SQL DELETE TABLE

How to delete the table and what is the difference between DELETE and TRUNCATE statement?

SQL DELETE ROW

How to delete a row from the database?

SQL DELETE All Rows

How to delete all the rows of a table?

SQL DELETE Duplicate Rows

How to use distinct keyword to delete all the duplicate rows from the table?

SQL DELETE DATABASE

There is not used DELETE statement to delete the database. But, there is used DROP statement to delete the database.

SQL DELETE VIEW


How to delete the view from the database?

SQL DELETE JOIN

How to use delete statement with INNER JOIN?

You might also like