Professional Documents
Culture Documents
DBMS Unit 4
DBMS Unit 4
SQL query
Syntax:
DROP TABLE table_name;
Example:
DROP TABLE EMPLOYEE;
Syntax:
1. INSERT INTO table_name VALUES (value1, value2, value3);
2. INSERT INTO table_name (column1, column2, column3) VALUES ( value1, value2, value3);
Example:
1. INSERT INTO Student VALUES ('5','harsh','west bengal','xxxxxxxxxx','19');
2. INSERT INTO Student (Roll_no, Name, age) VALUES ('5','pratik','19');
The fields for which values are not provided will get null.
Example:
1. UPDATE Customer SET CustomerName = 'Nitin' WHERE Age = 22;
2. UPDATE Customer SET CustomerName = 'Satyam', Country = 'USA' WHERE CustomerID = 1;
3. UPDATE Customer SET CustomerName = 'Shubham';
Example:
1. DELETE FROM employees WHERE name = 'Rithvik';
Delete all the records:
1. DELETE FROM employees;
2. DELETE * FROM employees;
Example:
SELECT * FROM Customer;
SELECT CustomerName FROM Customer where Age = '21';
SELECT * FROM Customers WHERE Country = 'Germany‘ AND City = 'Berlin‘ AND PostalCode >
12000;
SELECT * FROM Customers WHERE Country = 'Germany‘ OR Country = India‘;
Return all customers from a city that contains the letter 'L':
SELECT * FROM Customers WHERE city LIKE '%L%';
Return all customers that starts with 'a' or starts with 'b':
SELECT * FROM Customers WHERE CustomerName LIKE 'a%' OR CustomerName LIKE 'b%';
Return all customers that starts with "b" and ends with "s":
SELECT * FROM Customers WHERE CustomerName LIKE 'b%s';
Return all customers that starts with "a" and are at least 3 characters in length:
SELECT * FROM Customers WHERE CustomerName LIKE 'a__%';
Return all customers starting with "a", "b", "c", "d", "e" or "f":
SELECT * FROM Customers WHERE CustomerName LIKE '[a-f]%';
The MAX() function returns the largest value of the selected column.
Return all products with a higher price than the average price:
SELECT * FROM Products WHERE price > (SELECT AVG(price) FROM Products);