Table 2-1 Core SQL:2003 Commands
Table 2-1 Core SQL:2003 Commands
Table 2-1 Core SQL:2003 Commands
CREATE VIEW
SELECT column_name,column_name
FROM table_name;
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
Example
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
Update Warning!
Be careful when updating records. If we had omitted the WHERE clause, in the
example above, like this:
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg';
SQL DELETE Statement
DELETE FROM table_name
WHERE some_column=some_value;
Example
DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria
Anders';
DELETE FROM table_name; - BRISE SVE PODATKE
SQL Injection
Server Code
txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId;
Example
SELECT * FROM Customers
WHERE City LIKE 's%'; ILI NOT LIKE %nekoime% %-wild card zamenjue sve
moguce karaktere
SQL Wildcards
Wildcard Description
% A substitute for zero or more characters
Example
SELECT * FROM Customers
WHERE City LIKE 'ber%';
Example
SELECT * FROM Customers
WHERE City LIKE '%es%';
Example
SELECT * FROM Customers
WHERE City LIKE '_erlin';
The following SQL statement selects all customers with a City starting with "b",
"s", or "p":
Example
SELECT * FROM Customers
WHERE City LIKE '[bsp]%';
Example
SELECT * FROM Customers
WHERE City LIKE '[a-c]%';
SQL IN Operator
SQL IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...); slicno kao where or
Example
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
Example
SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;
Example
SELECT * FROM Products
WHERE ProductName BETWEEN 'C' AND 'M';
SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;
SQL Aliases
SQL Alias Syntax for Columns
SELECT column_name AS alias_name
FROM table_name;
SQL Joins
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
INNER JOIN: Returns all rows when there is at least one match in BOTH
tables
LEFT JOIN: Return all rows from the left table, and the matched rows from
the right table
RIGHT JOIN: Return all rows from the right table, and the matched rows
from the left table
FULL JOIN: Return all rows when there is a match in ONE of the tables
Example
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;