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

SQL_STATEMENTS

Skkks

Uploaded by

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

SQL_STATEMENTS

Skkks

Uploaded by

suryanshpal52
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

This SQL statement reads the data from the SQL database and shows it as the output to the

database
user.
Syntax of SELECT Statement:
SELECT column_name1, column_name2, .…, column_nameN
[ FROM table_name ] [ WHERE condition ] [ ORDER BY order_column_name1 [ ASC | DESC ], ..
.. ];
Example of SELECT Statement:
SELECT Emp_ID, First_Name, Last_Name, Salary, City FROM Employee_details
WHERE Salary = 100000 ORDER BY Last_Name;

This SQL statement changes or modifies the stored data in the SQL database.
Syntax of UPDATE Statement:
UPDATE table_name SET column_name1 = new_value_1, column_name2 = new_value_2, ...., co
lumn_nameN = new_value_N [ WHERE CONDITION ];
Example of UPDATE Statement:
UPDATE Employee_details SET Salary = 100000 WHERE Emp_ID = 10;

This SQL statement deletes the stored data from the SQL database.
Syntax of DELETE Statement:
DELETE FROM table_name [ WHERE CONDITION ];
Example of DELETE Statement:
DELETE FROM Employee_details WHERE First_Name = 'Sumit';
This example deletes the record of those employees from the Employee_details table
whose First_Name is Sumit in the table.

This SQL statement creates the new table in the SQL database.
Syntax of CREATE TABLE Statement:
CREATE TABLE table_name
( column_name1 data_type [column1 constraint(s)],column_name2 data_type [column2 constrain
t(s)],.....,..,..column_nameN data_type [columnN constraint(s)], PRIMARY KEY(one or more col));
Example of CREATE TABLE Statement:
CREATE TABLE Employee_details( Emp_Id NUMBER(4) NOT NULL, First_name VARCHAR(30),
Last_name VARCHAR(30),Salary FLOAT(8,2),City VARCHAR(30),PRIMARY KEY (Emp_Id));
This example creates the table Employee_details with five columns or fields in the SQL database. The
fields in the table are Emp_Id, First_Name, Last_Name, Salary, and City. The Emp_Id column in the
table acts as a primary key, which means that the Emp_Id column cannot contain duplicate values and
null values.

This SQL statement adds, deletes, and modifies the columns of the table in the SQL database.
Syntax of ALTER TABLE Statement:
ALTER TABLE table_name ADD column_name datatype[(size)];
The above SQL alter statement adds the column with its datatype in the existing database table.
ALTER TABLE table_name MODIFY column_name column_datatype[(size)];
The above 'SQL alter statement' renames the old column name to the new column name of the existing
database table.
ALTER TABLE table_name DROP COLUMN column_name;
The above SQL alter statement deletes the column of the existing database table.
Example of ALTER TABLE Statement:
ALTER TABLE Employee_details ADD Designation VARCHAR(18);
This example adds the new field whose name is Designation with size 18 in
the Employee_details table of the SQL database.
This SQL statement deletes or removes the table and the structure, views, permissions, and triggers
associated with that table.
Syntax of DROP TABLE Statement:
DROP TABLE [ IF EXISTS ]
table_name1, table_name2, ……, table_nameN;
The above syntax of the drop statement deletes specified tables completely if they exist in the database.
Example of DROP TABLE Statement:
DROP TABLE Employee_details;
This example drops the Employee_details table if it exists in the SQL database. This removes the
complete information if available in the table.

This SQL statement creates the new database in the database management system.
Syntax of CREATE DATABASE Statement:
CREATE DATABASE database_name;
Example of CREATE DATABASE Statement:
CREATE DATABASE Company;
The above example creates the company database in the system.

This SQL statement deletes the existing database with all the data tables and views from the database
management system.
Syntax of DROP DATABASE Statement:
DROP DATABASE database_name;
Example of DROP DATABASE Statement:
DROP DATABASE Company;
The above example deletes the company database from the system.

This SQL statement inserts the data or records in the existing table of the SQL database. This statement
can easily insert single and multiple records in a single query statement.
Syntax of insert a single record:
INSERT INTO table_name ( column_name1,column_name2, .…,column_nameN )
VALUES (value_1,value_2, ..…, value_N);
Example of insert a single record:
INSERT INTO Employee_details (Emp_ID,First_name,Last_name,Salary,City)
VALUES (101,”Akhil”,
“Sharma”,40000,”Bangalore” );
This example inserts 101 in the first column, Akhil in the second column, Sharma in the third
column, 40000 in the fourth column, and Bangalore in the last column of the table Employee_details.
Syntax of inserting a multiple records in a single query:
INSERT INTO table_name ( column_name1, column_name2, .…, column_nameN)
VALUES (value_1, value_2, ..…, value_N), (value_1, value_2, ..…, value_N),….;
Example of inserting multiple records in a single query:
INSERT INTO Employee_details ( Emp_ID, First_name, Last_name, Salary, City )
VALUES (101, “Amit”, “Gupta”, 50000, “Mumbai”), (101,”John”, “Aggarwal”,45000,”Calcutta”),(101,”
Sidhu”,” Arora”, 55000, “Mumbai”);
This example inserts the records of three employees in the Employee_details table in the single query
statement.
This SQL statement deletes all the stored records from the table of the SQL database.
Syntax of TRUNCATE TABLE Statement:
TRUNCATE TABLE table_name;
Example of TRUNCATE TABLE Statement:
TRUNCATE TABLE Employee_details;
This example deletes the record of all employees from the Employee_details table of the database.

This SQL statement tells something about the specified table or view in the query.
Syntax of DESCRIBE Statement:
DESCRIBE table_name | view_name;
Example of DESCRIBE Statement:
DESCRIBE Employee_details;
This example explains the structure and other details about the Employee_details table.

This SQL statement shows the distinct values from the specified columns of the database table. This
statement is used with the SELECT keyword.
Syntax of DISTINCT Clause:
SELECT DISTINCT column_name1, column_name2, ... FROM table_name;
Example of DISTINCT Clause:
SELECT DISTINCT City, Salary FROM Employee_details;
This example shows the distinct values of the City and Salary column from the Employee_details table.

This SQL statement selects the existing SQL database. Before performing the operations on the database
table, you have to select the database from the multiple existing databases.
Syntax of USE Statement:
USE database_name;
Example of USE DATABASE Statement:
USE Company;
This example uses the company database.

You might also like