0% found this document useful (0 votes)
15 views

Basic Design and Implementation

SQL is a commonly used relational database language that works with programming languages like Visual Basic. It is used for data manipulation, definition, and administration through SQL statements. SQL represents data in tables with rows and columns and supports relational operations like selection, projection, and join to retrieve specific data from tables. Statements like SELECT, INSERT, UPDATE, DELETE allow querying, adding, modifying and removing data from database tables.

Uploaded by

Kemtsho Zongla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Basic Design and Implementation

SQL is a commonly used relational database language that works with programming languages like Visual Basic. It is used for data manipulation, definition, and administration through SQL statements. SQL represents data in tables with rows and columns and supports relational operations like selection, projection, and join to retrieve specific data from tables. Statements like SELECT, INSERT, UPDATE, DELETE allow querying, adding, modifying and removing data from database tables.

Uploaded by

Kemtsho Zongla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Basic Design and Implementation

An Overview of SQL
SQL stands for Structured Query Language. It is the most commonly used relational database language today. SQL works with a variety of different fourthgeneration (4GL) programming languages, such as Visual Basic.
2

SQL is used for:


Data Manipulation
Data Definition Data Administration All are expressed as an SQL statement or command.

SQL Requirements
SQL Must be embedded in a programming language, or used with a 4GL like VB SQL is a free form language so there is no limit to the the number of words per line or fixed line break.

Syntax statements, words or phrases are always in lower case; keywords are in uppercase.

Not all versions are case sensitive!

SQL is a Relational Database


A Fully Relational Database Management System must:
Represent all info in database as tables
Keep logical representation of data independent from its physical storage characteristics Use one high-level language for structuring, querying, and changing info in the database Support the main relational operations Support alternate ways of looking at data in tables

Provide a method for differentiating between unknown values and nulls (zero or blank)
Support Mechanisms for integrity, authorization, transactions, and recovery

SQL

Design
SQL represents all information in the form of tables
Supports three relational operations: selection, projection, and join. These are for specifying exactly what data you want to display or use

SQL is used for data manipulation, definition and administration


6

Table Design
Columns describe one characteristic of the entity Rows describe the Occurrence of an Entity

Name Karma Dorji Pema Sangay

Address Mongar Paro Thimphu

Data Retrieval (Queries)


Queries search the database, fetch info, and display it. This is done using the keyword SELECT SELECT * FROM employees;
user_id
0736 0987 1120

user_name
Leki Dorji Choki Dorji Lhamo

address
Samtse Yangtse Bumthang

age
54 34 45

The Operator asks for every column in the table.

Data Retrieval (Queries)


Queries can be more specific with a few more lines
SELECT * from empoyees where age = 45;
user_name Leki Dorji
Choki Dorji Lhamo

user_id 0736
0987 1120

address Samtse
Yangtse Bumthang

age 54
34 45

Only employees in 45 will be displayed


9

Data Input
Putting data into a table is accomplished using the keyword INSERT
INSERT INTO employee VALUES (0010, Sonam, Haa, 23); Keyword

Variable

pub_id user_id 0736 0010 0987 0736 1120 0987 1120

pub_name user_name New Age Books Sonam Binnet & Hardley Leki Dorji Algodata Infosys Choki Dorji Lhamo

address 1 1st Street Haa 2 2nd Street Samtse 3 3rd Street Yangtse Bumthang

state age MA 23 DC 54 CA 34 45

Table is updated with new information


10

Types of Tables
There are two types of tables which make up a relational database in SQL
User Tables: contain information that is the database management system System Tables: contain the database description, kept up to date by DBMS itself Relation Table
Tuple Attribute Row Column
11

Using SQL
SQL statements can be embedded into a program (cgi or perl script, Visual Basic, MS Access)
OR SQL statements can be entered directly at the command prompt of the SQL software being used (such as mySQL)

12

Domain Types in SQL


char(n). Fixed length character string, with user-specified length n. varchar(n). Variable length character strings, with userspecified maximum length n. int. Integer (a finite subset of the integers that is machinedependent). smallint. Small integer (a machine-dependent subset of the integer domain type). numeric(p,d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point.

real, double precision. Floating point and double-precision floating point numbers, with machine-dependent precision.
float(n). Floating point number, with user-specified precision of at least n digits. 13

Using SQL
To begin, you must first CREATE a database using the following SQL statement:

CREATE DATABASE database_name;


Depending on the version of SQL being used the following statement is needed to begin using the database:

USE database_name;

14

Using SQL
To create a table in the current database, use the CREATE TABLE keyword CREATE TABLE authors (auth_id int(9) not null, auth_name char(40) not null);
auth_id (9 digit int) auth_name (40 char string)

15

Using SQL
To insert data in the current table, use the keyword INSERT INTO
INSERT INTO authors values(000000001, John Smith);

Then issue the statement


SELECT * FROM authors;
auth_id 000000001 auth_name John Smith
16

Using SQL
If you only want to display the authors name and city from the following table:
auth_id auth_name auth_city Dearborn Taylor auth_state MI MI 123456789 Jane Doe 000000001 John Smith

SELECT auth_name, auth_city FROM authers;


auth_name Jane Doe
John Smith

auth_city Dearborn
Taylor
17

Using SQL
To delete data from a table, use the DELETE statement: DELETE from authors WHERE auth_name=John Smith;
auth_id auth_name auth_city Dearborn Taylor auth_state MI MI

123456789 Jane Doe 000000001 John Smith

18

Using SQL
To Update information in a database use the UPDATE keyword UPDATE authors SET auth_name=hello;
auth_id auth_name auth_city Dearborn Taylor auth_state MI MI

Hello Doe 123456789 Jane Hello Smith 000000001 John

Sets all auth_name fields to hello


19

Using SQL
To change a table in a database use ALTER TABLE. ADD adds a characteristic. ALTER TABLE authors Type ADD birth_date datetime null;
auth_id auth_name auth_city Dearborn Taylor auth_state MI MI
Initializer

birth_date . .

123456789 Jane Doe 000000001 John Smith

ADD puts a new column in the table called birth_date


20

Using SQL
To delete a column or row, use the keyword DROP ALTER TABLE authors DROP birth_date;
auth_id auth_name auth_city Dearborn Taylor auth_state MI MI auth_state . .

123456789 Jane Doe 000000001 John Smith

DROP removed the birth_date characteristic from the table


21

Using SQL
The DROP statement is also used to delete an entire database. DROP DATABASE authors
auth_id auth_name auth_city Dearborn Taylor auth_state MI MI

123456789 Jane Doe 000000001 John Smith

DROP removed the database and returned the memory to system


22

Conclusion
SQL is a versatile language that can integrate with numerous 4GL languages and applications SQL simplifies data manipulation by reducing the amount of code required.
More reliable than creating a database using files with linked-list implementation
23

You might also like