Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

SQL Server

(Lecture 5)
SQL Syntax
Aga Private Institute for Computer Science
Programing Department
5th Stage
INSERT INTO ?

SELECT ?

ORDER BY?

2/67
INSERT INTO
The SQL INSERT INTO Statement is used to add new rows of
data to a table in the database.

Syntax: Or :

INSERT INTO Table_name INSERT INTO Table_name


VALUES (column1, column2,...columnN)
(value1, value2,...valueN) ; VALUES
(value1, value2,...valueN) ;

To show all records were inserted :

SELECT * FROM Table_name ;

3
INSERT INTO

Example:
INSERT INTO CUSTOMERS
VALUES (7 , 'Muffy’ , 24 , 'Indore‘ , 10000.00 );

Example:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)


VALUES (2, 'Khilan', 25, 'Delhi', 1500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)


VALUES (3, 'kaushik', 23, 'Kota', 2000.00 );

4
Note

The strings should be given inside single


quotes ( ‘ ) where as numeric values should
be given without any quote .
INSERT INTO

Insert exists data’s from a tabale into another.

INSERT INTO first_table_name


Syntax: (column1, column2, ... columnN)
SELECT column1, column2, ...columnN
FROM second_table_name ;
INSERT INTO ORDERS
Example: SELECT * FROM CUSTOMERS ;

Note : Copy all data in a table into another table, must be columns have
the same data types, So can be use condition.

6
SELECT

SQL SELECT Statement is used to fetch the data from a database table.

Syntax 1 : SELECT * FROM table_name ;


To fetch all the fields available in the
table.

Syntax 2 : SELECT column1, column2, …. FROM table_name;


To fetch some specific fields available in the table.

7
SELECT

Example : SELECT * FROM CUSTOMERS ;

Example : SELECT ID, Name, Salary FROM CUSTOMERS ;

8
ORDER BY

The ORDER BY keyword is used to sort the result-set by one or more


columns.

Syntax : SELECT * FROM Tbl_name ORDER BY Col_name;

Example : SELECT * FROM CUSTOMER ORDER BY LastName ;

By default is ascending sort, can be use DESC for descending.

Example : SELECT * FROM CUSTOMER ORDER BY LastName ASC|


DESC ;

9
DISTINCT

The DISTINCT keyword can be used to return only distinct (different)


values.

Syntax :

SELECT DISTINCT Col_name FROM Tbl_name ;


Example :

SELECT DISTINCT FirstName FROM CUSTOMER ;

10

You might also like