SQL COMMANDS

  • What is SQL?
    SQL is a standard database language used to access and manipulate data in databases. SQL stands for Structured Query Language. By executing queries SQL can create, update, delete, and retrieve data in databases like MySQL, Oracle, PostgreSQL, etc. Overall SQL is a query language that communicates with databases.Types of SQL CommandsThere are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.

UPDATE:
Updating all rows from data in a table at a time or a specific row data in a table by using ‘Where’ condition.DL ( Data Defination Language):Data Definition Language is used to define the database structure or schema. DDL is also used to specify additional properties of the data. The storage structure and access methods used by the database system by a set of statements in a special type of DDL called a data storage and definition language. These statements define the implementation details of the database schema, which are usually hidden from the users. The data values stored in the database must satisfy certain consistency constraints.

Create: CREATE TABLE statement is used to create a new table in the database.

To create a table, you have to name that table and define its columns and datatype for each column.

Example:


CREATE DATABASE HRDB;
GO
USE HRDB;
GO
CREATE TABLE HR_EMPLOYEES
(
EMP_ID INT,
EMP_FNAME VARCHAR(30),
EMP_LNAME VARCHAR(30),
EMP_MNUMBER INT,
EMP_SAL INT,
EMP_LOCATION VARCHAR(20),
EMP_PINCODE INT,
);
GO

  1. Alter: ALTER TABLE statement specifies how to add, modify, drop or delete columns in a table. It is also used to rename a table.

   Example:

Alter Table [dbo].[HR_EMPLOYEES] add EMP_MAILID Varchar(15);

  1. DROP: Dropping a table from the database permanently.

   Example:

Drop Table [dbo].[HR_EMPLOYEES];

  1. TRUNCATE: Deleting rows from the table but not structure of the table. By using truncate command we cannot delete a specific row from the table because it doesn’t support ‘WHERE’ clause condition.

   Example:

Truncate Table  [dbo].[HR_EMPLOYEES]

Data Query Language:

DQL is used to fetch the data from the database.

It uses only one command:

    • SELECT

   SELECT: The SELECT statement is used to select data from a database.

Example:

SELECT * FROM HR_EMPLOYEES;

DML (Data Manipulation Language) :

DML statements are used for managing data with in schema objects.
Below are the commands which comes under DML.

    INSERT : The INSERT statement is used to insert new records in a table.

Example:

Insert into[dbo].[HR_EMPLOYEES] values
(1,'Ashwin','Kumar',9986543,40000,'Guntur',500489),
(2,'Rubina','Khan',735948,70000,'Pune',500489),
(3,'Karthik','Alla',6979582,43000,'Hyderabad',500048),
(4,'Srivani','Nallabolu',9948637,38000,'Warangal',500476),
(5,'Bhargavi','Jarupula',6372596,26000,'Hyderabad',500067),
(6,'Sudha','Varma',9550326,34000,'Banglore',560037),
(7,'Tarun','Srivasthav',6377858,70000,'Mumbai',400001),
(8,'Ragini','Duggirala',7989623,55000,'Delhi',110005),
(9,'Swetha','Sangam',8989453,84000,'Banglore',560001),
(10,'Mohan','Devula',9986766,65000,'Kurnool',518002);