Assoc. Prof. Dr. Ahmet Turan ÖZCERİT. Basic SQL syntax Data retrieve Data query Data...

Preview:

Citation preview

Introduction to Computer Engineering

WEEK-9SQL Programming

Assoc. Prof. Dr. Ahmet Turan ÖZCERİT

2

Basic SQL syntax

Data retrieve

Data query

Data conditions

Arithmetic operations on data

Data transactions

SQL Programming

You will learn:

The SQL Language

He/she can use SQL instructions to create and manage database tables

3

SQL is an ANSI and ISO standard (since 1986) computer language  for creating and manipulating databases

SQL allows the user to create, update, delete, and retrieve data from a database

SQL is very simple and easy to learn

SQL works with database programs like DB2, Oracle, MS Access, Sybase, MS SQL Server etc.

SQL is a keyword based language. Each statement in SQL begins with a unique keyword. These keywords are not case-sensitive.

SQL Instructions can be grouped in

• Data Defining Language• Data Manipulation Language• Data Control Language• Transaction Control Language• Data Query Language

Some instructions can be executed directly in SQL editor or they can be implemented by GUI of the DBMS

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

4

SELECT selects the fields in the tables

SELECT * FROM table_name (selects all fields and all rows or records)

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

5

SELECT OrtakNo, Ad, Soyad from Zkimlik1

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

6

SELECT * FROM Zkimlik1 ORDER BY Ad

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

7

SELECT * FROM Zkimlik1 ORDER BY Ad DESC

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

8

SELECT * FROM Zkimlik1 ORDER BY Ad,Soyad

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

9

SELECT * FROM Zkimlik1 WHERE ad=”AHMET”

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

10

SELECT * FROM Zkimlik1 WHERE Ad=”AHMET” OR Soyad=”MERT”

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

11

SELECT * FROM Zkimlik1 WHERE ad BETWEEN “AYDIN” AND “BEKİR”

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

12

SELECT * FROM zkimlik1 WHER ad IN('Ali','Bekir')

BASIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

13

SELECT * FROM ZKimlik1 WHERE adi LIKE ‘*C*’

ARITHMETIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

14

SUM : Addition of all recordsMAX : Maximum value in the recordsMIN : Minimum value in the recordsAVG : Average value of selected recordsCOUNT : The number of records in the table

SELECT ortakno, SUM(borc) as tborc, SUM(alacak) as talacak, sum(borc-alacak) as fark FROM tkart GROUP BY ortakno

ARITHMETIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

15

SELECT MAX(borc) as maxborc, MAX(alacak) as maxalacak FROM tkartSELECT MIN(borc) as maxborc, MIN(alacak) as maxalacak FROM tkart

ARITHMETIC SQL INSTRUCTIONS

He/she can use SQL instructions to create and manage database tables

16

SELECT AVG(borc) as ortborc, AVG(alacak) as ortalacak FROM tkart

SELECT COUNT(*) as KayıtSayısı FROM tkart

QUERRY FROM MULTIPLE TABLES

He/she can use SQL instructions to create and manage database tables

17

SELECT Zkimlik1.ortakno, zkimlik1.ad, zkimlik1.Soyad, zkimlik3.DTarihFROM Zkimlik1, zkimlik3WHERE zkimlik1.ortakno=zkimlik3.ortakno

DATA MANIPULATION

He/she can use SQL instructions to create and manage database tables

18

INSERT INTO Zkimlik1 ( ortakno, ad, soyad, BabaAd, DogYer,

meslekgrubu )VALUES ('2000', 'MEHMET', 'CAN', 'HASAN', 'SAKARYA',

2);

UPDATE zkimlik1 SET ad = 'Ayşe', soyad = 'öz', BabaAd =

'mehmet', dogYer = 'Bolu', meslekgrubu = 3

WHERE ortakno='2000';

DELETE *FROM zkimlik1WHERE ad='Ayşe';

QUESTIONS

19

Recommended