You are on page 1of 8

John Mishael B.

Orejola August 10, 2017


BSIT Irreg

SQL Server

- Create Database
The SQL CREATE DATABASE statement is used to create a new SQL database.

- Syntax
The basic syntax of this CREATE DATABASE statement is as follows:

- Example SQL> CREATE DATABASE <ActivityDB>;

- Use Database
The SQL USE statement is used to select any existing database in the SQL schema.

- Syntax
USE DatabaseName;

- Example USE ActivityDB;


- Create table
The SQL CREATE TABLE statement is used to create a new table.
-Syntax
Create table Employees (EMPID int Primary key, NAME varchar(50), HOME varchar(50),
Birthday date, CONTACTNO varchar(50), POSITION varchar(50),SALARY int);
-Example

- Insert into
The SQL INSERT INTO Statement is used to add new rows of data to a table in the
database.
- Syntax
insert into Employees values
(51, 'John Bautista', 'Sariaya Quezon', '1993-01-02', 09358811032, 'System Analyst',
150000);
- Example
- Select Query
The SQL SELECT statement is used to fetch the data from a database table which returns
this data in the form of a result table. These result tables are called result-sets.
- Syntax
Select NAME , HOME, CONTACTNO from Employees;
- Example

- Where Clause
The SQL WHERE clause is used to specify a condition while fetching the data from a single
table or by joining with multiple tables. If the given condition is satisfied, then only it
returns a specific value from the table. You should use the WHERE clause to filter the
records and fetching only the necessary records.
- Syntax
Select NAME, SALARY from Employees where SALARY > 12000;
- Example
- AND & OR Conjunction
The SQL AND & OR operators are used to combine multiple conditions to narrow data in
an SQL statement. These two operators are called as the conjunctive operators.
These operators provide a means to make multiple comparisons with different operators
in the same SQL statement.
- AND operator
The AND operator allows the existence of multiple conditions in an SQL statement's
WHERE clause.

- Syntax
Select NAME, SALARY from Employees where SALARY >1200 and NAME like '%A';

- Or
The OR operator is used to combine multiple conditions in an SQL statement's WHERE
clause.
- SYNTAX
Select NAME, SALARY from Employees where SALARY >= 50000 or SALARY < 15000;
- EXAMPLE
- UPDATE
The SQL UPDATE Query is used to modify the existing records in a table. You can use the
WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows
would be affected.
- SYNTAX
UPDATE Employees Set Home = 'Sariaya Quezon' Where EMPID = 1;
- EXAMPLE

- LIKE
The SQL LIKE clause is used to compare a value to similar values using wildcard
operators. There are two wildcards used in conjunction with the LIKE operator.
- SYNTAX
Select NAME from Employees where NAME LIKE '%JOHN%';
- EXAMPLE

- TOP
The SQL TOP clause is used to fetch a TOP N number or X percent records from a table.
- SYNTAX
Select TOP 5 * from Employees;
- EXAMPLE
- LIMIT
LIMIT clause to fetch a limited number of records, while Oracle uses the ROWNUM
command to fetch a limited number of records.

- ORDER BY
The SQL ORDER BY clause is used to sort the data in ascending or descending order,
based on one or more columns. Some databases sort the query results in an ascending
order by default.
- SYNTAX
Select NAME, SALARY from Employees Order by NAME ASC;
-EXAMPLE

- GROUP BY
The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange
identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT
statement and precedes the ORDER BY clause.
- SYNTAX
Select NAME, SUM(SALARY) as PAYOUT from Employees Group by NAME;
- EXAMPLE
- SELECT DISTINCT
The SQL DISTINCT keyword is used in conjunction with the SELECT statement to
eliminate all the duplicate records and fetching only unique records.
- SYNTAX
Select distinct SALARY from Employees Order by SALARY DESC;
- EXAMPLE

- SORTING
The SQL ORDER BY clause is used to sort the data in ascending or descending order,
based on one or more columns. Some databases sort the query results in an ascending
order by default.
- SYNATAX
Select * From Employees Order by NAME , SALARY;
- EXAMPLE

- BOOLEAN EXPRESSION
SQL Boolean Expressions fetch the data based on matching a single value. Following is the
syntax:
- SYNTAX
Select * From Employees Where SALARY = 150000;
-EXAMPLE
- NUMERIC EXPRESSION
These expressions are used to perform any mathematical operation in any query. Following
is the syntax:
- SYNTAX
Select NAME, SALARY + (15) AS ADDTIONAL from Employees;
- EXAMPLE

- DATE EXPRESSION
Date Expressions return the current system date and time values:
- SYNTAX
Select CURRENT_TIMESTAMP;
- EXAMPLE

You might also like