SQL Commands - Docx - Watermark
SQL Commands - Docx - Watermark
SQL Commands:
▪ CREATE
▪ DROP
▪ ALTER
1 CREATE
Syntax
Example
Syntax
Example
2 DROP
This statement is used to drop an existing table. When you use this
statement, complete information present in the table will be lost.
Syntax
If you are adding values for all the columns of the table, you do not
need to specify the column names in the SQL query. However,
make sure the order of the values is in the same order as the
columns in the table.
Example
ALTER TABLE Customers
ADD Email varchar(255);
Example
ALTER TABLE Customers
DROP COLUMN Email;
SELECT
SELECT column1, column2, ...
FROM table_name;
FROM table_name
WHERE [condition]
OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
SC|DESC;
ORDER BY column1, column2, ... A
SELECT * FROM EMP
ORDER BY salary;
Example
GROUP BY Syntax
The GROUP BY statement groups rows that have the same values
into summary rows, like "find the number of customers in each
country".
SELECT column_name(s)
FROM table_name
[WHERE condition]
[GROUP BY column_name(s)]
[ORDER BY column_name(s)]
Example1
Example 2
Group by deptno;
or
Group by deptno
Order by deptno;
Example 3
Group by ename
Hiredate<1991
EMP Table
Department Table
IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
There are two wildcards often used in conjunction with the LIKE
operator:
Like ‘a%o’
HAVING Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
Example
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
UPDATE CUSTOMERS
SET ADDRESS = ‘PUNE’
WHERE ID = 2;
UPDATE Customers
SET Age=32;
UPDATE CUSTOMERS
SET ADDRESS = 'Pune' , SALARY = 10000.00, ;
UPDATE CUSTOMERS
SET ADDRESS = 'Pune', SALARY = 15000.00
WHERE ID IN(3,5,6);
UPDATE CUSTOMERS
SET ADDRESS = 'Pune'
SQL DELETE
UPDATE CUSTOMERS_VIEW
SET AGE = 35
WHERE name = 'Ramesh';
VIEWS In SQL
A view contains rows and columns, just like a real table. The fields
in a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a
view and present the data as if the data were coming from one
single table.
WHERE AGE>25;
+----------+-----+
| name | age |
+----------+-----+
| Ramesh | 32 |
| Khilan | 25 |
| kaushik | 23 |
| Chaitali | 25 |
| Hardik | 27 |
| Komal | 22 |
| Muffy | 24 |
+----------+-----+
Trigger Example 1
Trigger Example 2
Create