Sie sind auf Seite 1von 7

Some of The Most Important SQL Commands

 SELECT - extracts data from a database


 UPDATE - updates data in a database
 DELETE - deletes data from a database
 INSERT INTO - inserts new data into a database
 CREATE DATABASE - creates a new database
 ALTER DATABASE - modifies a database
 CREATE TABLE - creates a new table
 ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index

SELECT CustomerName,City FROM Customers where postalcode = 12209;

SELECT DISTINCT Country FROM Customers;

SELECT COUNT(DISTINCT Country) FROM Customers;


SELECT * FROM Customers
WHERE Country='Mexico';

SELECT * FROM Customers


WHERE CustomerID=1;

The SQL AND, OR and NOT Operators


The WHERE clause can be combined with AND, OR, and NOT operators.

The AND and OR operators are used to filter records based on more than one
condition:

 The AND operator displays a record if all the conditions separated by AND
is TRUE.
 The OR operator displays a record if any of the conditions separated by
OR is TRUE.

The NOT operator displays a record if the condition(s) is NOT TRUE.


AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

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;

Example

SELECT * FROM Customers


WHERE Country='Germany' AND City='Berlin';

SELECT * FROM Customers


WHERE City='Berlin' OR City='München';

SELECT * FROM Customers


WHERE NOT Country='Germany';

SELECT * FROM Customers


WHERE Country='Germany' AND (City='Berlin' OR City='München');

SELECT * FROM Customers


WHERE NOT Country='Germany' AND NOT Country='USA';

SELECT * FROM Customers


WHERE NOT City ='Berlin' AND (Country='Germany' OR PostalCode= 12209);

The SQL ORDER BY Keyword


The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort
the records in descending order, use the DESC keyword.

SELECT * FROM Customers


ORDER BY Country;

SELECT * FROM Customers


ORDER BY Country DESC;

SELECT * FROM Customers


ORDER BY Country, CustomerName;

SELECT * FROM Customers


ORDER BY Country ASC, CustomerName DESC;

NOTE:- Preference sort is Country(A-Z) as it is written first. Priority of Sort


country OVER CustomerName.

INSERT INTO Syntax

INSERT INTO Customers (CustomerName, ContactName, Address, City,


PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen
21', 'Stavanger', '4006', 'Norway');

INSERT INTO Customers (CustomerName, City, Country)


VALUES ('Cardinal', 'Stavanger', 'Norway');

What is a NULL Value?


A field with a NULL value is a field with no value.

If a field in a table is optional, it is possible to insert a new record or update a


record without adding a value to this field. Then, the field will be saved with a
NULL value.

Note: It is very important to understand that a NULL value is different from a


zero value or a field that contains spaces. A field with a NULL value is one that
has been left blank during record creation!
How to Test for NULL Values?
It is not possible to test for NULL values with comparison operators, such as =,
<, or <>.

We will have to use the IS NULL and IS NOT NULL operators instead.

SELECT LastName, FirstName, Address FROM Persons


WHERE Address IS NULL;

SELECT LastName, FirstName, Address FROM Persons


WHERE Address IS NOT NULL;

The UPDATE statement is used to modify the existing records in a table.

Note: Be careful when updating records in a table! Notice the WHERE clause in
the UPDATE statement. The WHERE clause specifies which record(s) that should
be updated. If you omit the WHERE clause, all records in the table will be
updated!

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';

LIKE Operator
There are two wildcards used in conjunction with the LIKE operator:

 % - The percent sign represents zero, one, or multiple characters


 _ - The underscore represents a single character
The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates.

The BETWEEN operator is inclusive: begin and end values are included.

SELECT * FROM Products


WHERE Price BETWEEN 10 AND 20;

Proudest moment
Growing as a student you always have a desire of being praised by your
mentors. During my 9th and 10th class CBSE introduced a new pattern for
assessment of marks which was totally based on the projects given to the
student.

It was a good platform for me to exhibit my creative skills and ideas. I was
very much praised by my teachers for thinking out of the box which motivates
me a lot. My four projects were sent to the CBSE as they were best projects
of the school and it was a proud moment for me.

WHY COMMUTATUS
Being as a IT student, Digital products fascinates me a lot i always try to
think something new which will improve the existing product and make the life
easier through innovation and technology. I believe that my logical,
technical and creative skill are best match with the company profile
commutatus can provide me a platform to showcase my ideas and knowledge which
will be immensely useful at the firm and help me and company grow.

PROBLEM I SOLVED
Recently during my internship at BSES Delhi, I handled a case where there was
an extremely old couple (both 95+ of age). They had submitted an application
for electricity meter load reduction but due to shaky handwriting in elderly
application was not readable so i contacted him by phone and asked for
problem and necessary details. Due to health issues of his wife they were
temporarily shifted near to the hospital and there want BSES to reduce the
sectioned load from 14 kW to 1 kW as there was no one in the house from last
3 months. They were paying rent of meter for 14 kW which was of no use. So i
concerned the department about the issue and solved the problem immediately.
Customer was very much satisfied with my work and expressed his gratitude for
the service i provided him.

Das könnte Ihnen auch gefallen