Sei sulla pagina 1di 27

MS SQL Server

Beginner To Advance Tutorial


What Is SQL

SQL stands for Structured Query Language.

SQL lets you access and manipulate databases.

SQL became a standard of the American National Standards

Institute (ANSI) in 1986, and of the International

Organization for Standardization (ISO) in 1987


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


What Can SQL Do

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


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


Important SQL Commands

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)


SQL Statements

Most of the actions you need to perform on a database are done with SQL

statements

Example

SELECT * FROM Customers;


SQL Select Statements

The SELECT statement is used to select data from a database.

Example

SELECT * FROM table_name;


SQL SelectDistrict
SQL Select Statements
Statements

The
The SELECT
SELECTDISTINCT statement
statement is usedistoused to return
select only distinct
data from (different) values
a database.

Example

SELECT DISTINCT
SELECT * FROM column1, column2, ...
table_name;
FROM table_name;
SQL Select Statements

The SELECT statement is used to select data from a database.

Example

SELECT * FROM table_name;


SQL Where Clause
The WHERE clause is used to filter records.

Example

SELECT column1, column2, ...


FROM table_name
WHERE condition;
SQL AND Operator
The AND operator displays a record if all the conditions separated by AND

are TRUE

Example

SELECT column1, column2, ...


FROM table_name
WHERE condition1 AND condition2
AND condition3 ...;
SQL OR Operator
The OR operator displays a record if any of the conditions separated by OR

is TRUE

Example

SELECT column1, column2, ...


FROM table_name
WHERE condition1 OR condition2
OR condition3 ...;
SQL NOT Operator
The NOT operator displays a record if the condition(s) is NOT TRUE

Example

SELECT column1, column2, ...


FROM table_name
WHERE NOT condition;
SQL ORDER By
The ORDER BY keyword is used to sort the result-set in ascending or

descending order

Example

SELECT column1, column2, ...


FROM table_name
ORDER BY column1, column2,
... ASC|DESC;
SQL Like Operator
The LIKE operator is used in a WHERE clause to search for a specified

pattern in a column

Example

SELECT column1, column2, ...


FROM table_name
WHERE columnN LIKE pattern;
SQL Like Operator
The LIKE operator is used in a WHERE clause to search for a specified

pattern in a column

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


_ - The underscore represents a single character

Example
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
SQL Like Operator
The LIKE operator is used in a WHERE clause to search for a specified

pattern in a column

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


_ - The underscore represents a single character

Example
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
SQL Like Operator
The LIKE operator is used in a WHERE clause to search for a specified

pattern in a column

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


_ - The underscore represents a single character

Example
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
SQL Between
The BETWEEN operator selects values within a given range. The values can

be numbers, text, or dates

Example

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN
value1 AND value2;
SQL Joins

A JOIN clause is used to combine rows from two or more tables, based on a

related column between them


Inner Join
The INNER JOIN keyword selects records that have matching values in both

tables

Example

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.
column_name;
Left Join
The LEFT JOIN keyword returns all records from the left table (table1), and

the matched records from the right table (table2). The result is NULL from

the right side, if there is no match

Example

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.
column_name;
Right Join
The RIGHT JOIN keyword returns all records from the right table (table2),

and the matched records from the left table (table1). The result is NULL

from the left side, when there is no match

Example

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.
column_name;
Outer Join
The FULL OUTER JOIN keyword returns all records when there is a match in

left (table1) or right (table2) table records

Example

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.
column_name
WHERE condition;
Store Procedure
A stored procedure is a prepared SQL code that you can save, so the code

can be reused over and over again

Example
CREATE PROCEDURE procedure_name
AS
sql_statement
GO;
Execute Store Procedure
EXEC procedure_name;
Thank YOU!
We Are Creating Content For You Free Of Cost

Our Website: https://www.techringe.com/

Our Official Page: https://www.facebook.com/techprofree

Potrebbero piacerti anche