SQL Commands- Reference
SQL Commands- Reference
COMMANDS in SQL
DDL (Data Definition Language) COMMANDS
CREATE, DROP, ALTER, TRUNCATE, RENAME
DML (Data Manipulation Language) commands
SELECT, INSERT, UPDATE, DELETE
DQL (Data Query Language) commands
SELECT
DCL (Data Control Language) commands
GRANT, REVOKE
TCL (Transaction Control Language) commands
COMMIT, ROLLBACK
DDL COMMANDS
WORKING WITH DATABASE
1. CREATE DATABASE
CREATE DATABASE <database_name>;
Ex:
create database employee;
4. REMOVING DATABASE
DROP DATABASE <database_name>;
Ex:
drop database employee;
1. CREATING TABLE
CREATE TABLE <tb_name> (<col1> <dtype> size, <col2> <dtype> size,….)
Ex: create table empdet(empno int, empname varchar(10),dept varchar(10));
3. DROPPING TABLE
DROP TABLE <tb_name>
Ex : drop table employee;
4. ALTER TABLE
Let's consider a table sample with the following statement
create table sample(rno int, sname varchar(10),marks decimal(5,2));
ALTER command is used to
4.1. ADD a COLUMN to the existing table
4.2. DELETE a COLUMN from an existing table
4.3. MODIFY the definition of EXISTING COLUMN
4.4. RENAME EXISTING COLUMN
4.5. ADD a CONSTRAINT to the existing table
4.6. DROP a CONSTRAINT from the existing table
DELETE Command:
Delete command is used to delete the rows from the table.
It will not delete the structure of the table.
DELETE FROM <tablename> WHERE <condition>;
ORDER BY:
Select * from <tablename> order by <columnname1>[ASC|DESC][,<columnname2> [ASC|DESC]];
GROUP BY:
The GROUP BY clause combines all those records that have identical values in a particular field
Grouping can be done with aggregate functions.
Select <columnname> Aggregatefunction from <tablename> GROUP BY <columnname>;
HAVING clause
The having clause places conditions on groups in contrast to where clause that places conditions on individual rows.
SELECT <columnname>, Aggregate function FROM <tablename> GROUP BY <columnname> HAVING <condition>;
SELECT <columnname>, Aggregate function FROM <tablename> GROUP BY <columnname> HAVING aggregate function<condition>