including transaction control, exception and error handling, row processing, and declared variables.
Code named Yukon in development, SQL Server 2005 was released in November 2005. The 2005 product is said to provide enhanced flexibility, scalability, reliability, and security to database applications, and to make them easier to create and deploy, thus reducing the complexity and tedium involved in database management. SQL Server 2005 also includes more administrative support.
The original SQL Server code was developed by Sybase; in the late 1980s, Microsoft, Sybase and Ashton-Tate collaborated to produce the first version of the product, SQL Server 4.2 for OS/2. Subsequently, both Sybase and Microsoft offered SQL Server products. Sybase has since renamed their product Adaptive Server Enterprise.
What can Sql Do.
- SQL can execute queries against a database
- SQL can retrieve data from a database
- SQL can insert records in a database
- SQL can update records in a database
- SQL can delete records from a database
- SQL can create new databases
- SQL can create new tables in a database
- SQL can create stored procedures in a database
- SQL can create views in a database
- SQL can set permissions on tables, procedures, and views
Sql Select Statement
The select command is the most important for most users. Its purpose is to retrieve data.
select * from table_name
or
select columnlist
from tablelist
Sql Distinct Statement
The SQL DISTINCT command used along with the SELECT keyword retrieves only unique data entries depending on the column list you have specified after it.
select distinct columnlist
from tablelist
Sql where Clause
The WHERE clause is used to extract only those records that fulfill a specified criterion.
select * from table_name
where column_name
or
select * from tablelist
where columnlist
Sql And & OR Operators
The AND operator displays a record if both the first condition and the second condition is true.
SELECT * FROM table_name
WHERE column_name
OR column_name
The OR operator displays a record if either the first condition or the second condition is true.
SELECT * FROM table_name
WHERE column_name
OR column_name
Combine use of AND & OR Operators
You can also combine AND and OR (use parenthesis to form complex expressions).
SELECT * FROM Persons WHERE
column_name
AND (column_name OR column_name)
Sql ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set.
The ORDER BY keyword is used to sort the result-set by a specified column.
The ORDER BY keyword sort the records in ascending order by default.
If you want to sort the records in a descending order, you can use the DESC keyword.
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC
DESC
Sql INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.
There is two form of INSERT INTO statement.
The first form doesn’t specify the column names where the data will be inserted, only their values:-
INSERT INTO table_name
Values (Value 1,Value 2,Value 3,…..)
The second form specifies both the column names and the values to be inserted:-
INSERT INTO table_name
(column1, column2, column3,…)
Values (Value 1,Value 2,Value 3,…..)
Sql UPDATE statement
The UPDATE statement is used to update records in a table.
UPDATE table_name
SET column1=value, column2=value2,…
WHERE some_column=some_value
Sql DELETE Statement
The DELETE statement is used to delete records in a table.
DELETE FROM table_name
WHERE some_column=some_value
Sql ALL Commands
SQL Statement | Syntax |
AND / OR | SELECT column_name(s) |
FROM table_name | |
WHERE condition | |
AND|OR condition | |
ALTER TABLE | ALTER TABLE table_name |
ADD column_name datatype | |
or | |
ALTER TABLE table_name | |
DROP COLUMN column_name | |
AS (alias) | SELECT column_name AS column_alias |
FROM table_name | |
or | |
SELECT column_name | |
FROM table_name AS table_alias | |
BETWEEN | SELECT column_name(s) |
FROM table_name | |
WHERE column_name | |
BETWEEN value1 AND value2 | |
CREATE DATABASE | CREATE DATABASE database_name |
CREATE TABLE | CREATE TABLE table_name |
( | |
column_name1 data_type, | |
column_name2 data_type, | |
column_name2 data_type, | |
... | |
) | |
CREATE INDEX | CREATE INDEX index_name |
ON table_name (column_name) | |
or | |
CREATE UNIQUE INDEX index_name | |
ON table_name (column_name) | |
CREATE VIEW | CREATE VIEW view_name AS |
SELECT column_name(s) | |
FROM table_name | |
WHERE condition | |
DELETE | DELETE FROM table_name |
WHERE some_column=some_value | |
or | |
DELETE FROM table_name | |
(Note: Deletes the entire table!!) | |
DELETE * FROM table_name | |
(Note: Deletes the entire table!!) | |
DROP DATABASE | DROP DATABASE database_name |
DROP INDEX | DROP INDEX table_name.index_name (SQL Server) |
DROP INDEX index_name ON table_name (MS Access) | |
DROP INDEX index_name (DB2/Oracle) | |
ALTER TABLE table_name | |
DROP INDEX index_name (MySQL) | |
DROP TABLE | DROP TABLE table_name |
GROUP BY | SELECT column_name, aggregate_function(column_name) |
FROM table_name | |
WHERE column_name operator value | |
GROUP BY column_name | |
HAVING | SELECT column_name, aggregate_function(column_name) |
FROM table_name | |
WHERE column_name operator value | |
GROUP BY column_name | |
HAVING aggregate_function(column_name) operator value | |
IN | SELECT column_name(s) |
FROM table_name | |
WHERE column_name | |
IN (value1,value2,..) | |
INSERT INTO | INSERT INTO table_name |
VALUES (value1, value2, value3,....) | |
or | |
INSERT INTO table_name | |
(column1, column2, column3,...) | |
VALUES (value1, value2, value3,....) | |
INNER JOIN | SELECT column_name(s) |
FROM table_name1 | |
INNER JOIN table_name2 | |
ON table_name1.column_name=table_name2.column_name | |
LEFT JOIN | SELECT column_name(s) |
FROM table_name1 | |
LEFT JOIN table_name2 | |
ON table_name1.column_name=table_name2.column_name | |
RIGHT JOIN | SELECT column_name(s) |
FROM table_name1 | |
RIGHT JOIN table_name2 | |
ON table_name1.column_name=table_name2.column_name | |
FULL JOIN | SELECT column_name(s) |
FROM table_name1 | |
FULL JOIN table_name2 | |
ON table_name1.column_name=table_name2.column_name | |
LIKE | SELECT column_name(s) |
FROM table_name | |
WHERE column_name LIKE pattern | |
ORDER BY | SELECT column_name(s) |
FROM table_name | |
ORDER BY column_name [ASC|DESC] | |
SELECT | SELECT column_name(s) |
FROM table_name | |
SELECT * | SELECT * |
FROM table_name | |
SELECT DISTINCT | SELECT DISTINCT column_name(s) |
FROM table_name | |
SELECT INTO | SELECT * |
INTO new_table_name [IN externaldatabase] | |
FROM old_table_name | |
or | |
SELECT column_name(s) | |
INTO new_table_name [IN externaldatabase] | |
FROM old_table_name | |
SELECT TOP | SELECT TOP number|percent column_name(s) |
FROM table_name | |
TRUNCATE TABLE | TRUNCATE TABLE table_name |
UNION | SELECT column_name(s) FROM table_name1 |
UNION | |
SELECT column_name(s) FROM table_name2 | |
UNION ALL | SELECT column_name(s) FROM table_name1 |
UNION ALL | |
SELECT column_name(s) FROM table_name2 | |
UPDATE | UPDATE table_name |
SET column1=value, column2=value,... | |
WHERE some_column=some_value | |
WHERE | SELECT column_name(s) |
FROM table_name | |
WHERE column_name operator value |
0 comments:
Post a Comment