sql database development part 1

20
SQL Database Development

Upload: sqlperfomance

Post on 04-Jul-2015

222 views

Category:

Technology


0 download

DESCRIPTION

Do you want to learn how to develop a SQL Database from the scratch? Here is the complete guidence. Start develope your own SQL Database right now!

TRANSCRIPT

Page 1: Sql database development part 1

SQL Database Development

Page 2: Sql database development part 1

Overview Define a database using SQL data definition language

Work with Views

Write single table queries

Establish referential integrity

Page 3: Sql database development part 1

SQL Overview Structured Query Language

The standard for relational database management systems (RDBMS)

SQL-92 and SQL-99 Standards – Purpose: Specify syntax/semantics for data definition and

manipulation

Define data structures

Enable portability

Specify minimal (level 1) and complete (level 2) standards

Page 4: Sql database development part 1

What Is SQL Developer? SQL Developer is a graphical tool that enhances

productivity and simplifies database development tasks.

You can connect to any target database schema by using standard database authentication.

SQL Developer

Page 5: Sql database development part 1

Specifications of SQL Developer Developed in Java

Supports Windows, Linux, and Mac OS X platforms

Default connectivity by using the JDBC Thin driver

Does not require an installer Unzip the downloaded SQL Developer kit and double-click sqldeveloper.exe to start SQL Developer.

Connects to Oracle Database version 9.2.0.1 and later

Freely downloadable from the following link: http://www.oracle.com/technology/products/database/sql_develop

er/index.html

Needs JDK 1.5 installed on your system that can be downloaded from the following link: http://java.sun.com/javase/downloads/index_jdk5.jsp

Page 6: Sql database development part 1

Installing SQL Developer Download the Oracle SQL Developer kit and unzip it

into any directory on your machine.

Page 7: Sql database development part 1

SQL Developer 1.2 Interface

Page 8: Sql database development part 1

Creating a Database Connection You must have at least one database connection to use

SQL Developer.

You can create and test connections for: Multiple databases

Multiple schemas

SQL Developer automatically imports any connections defined in the tnsnames.ora file on your system.

You can export connections to an Extensible Markup Language (XML) file.

Each additional database connection created is listed in the Connections Navigator hierarchy.

Page 9: Sql database development part 1

Creating a Database Connection1

2

3

Page 10: Sql database development part 1

SQL Environment

Page 11: Sql database development part 1

SQL Environment Catalog

A set of schemas that constitute the description of a database Schema

The structure that contains descriptions of objects created by a user (base tables, views, constraints)

Data Definition Language (DDL) Commands that define a database, including creating,

altering, and dropping tables and establishing constraints Data Manipulation Language (DML)

Commands that maintain and query a database Data Control Language (DCL)

Commands that control a database, including administering privileges and committing data

Page 12: Sql database development part 1

SQL Data types String types

CHAR(n) – fixed-length character data, n characters long Maximum length = 2000 bytes

VARCHAR2(n) – variable length character data, maximum 4000 bytes

LONG – variable-length character data, up to 4GB. Maximum 1 per table

Numeric types NUMBER(p,q) – general purpose numeric data type

INTEGER(p) – signed integer, p digits wide

FLOAT(p) – floating point in scientific notation with p binary digits precision

Date/time type DATE – fixed-length date/time in dd-mm-yy form

Page 13: Sql database development part 1

Design components Tables

Indexes

Views

Transactions

Access Authorities

Stored Procedures

Functions

Page 14: Sql database development part 1
Page 15: Sql database development part 1

SQL Database Definition

Data Definition Language (DDL)

Major CREATE statements: CREATE SCHEMA – defines a portion of the database

owned by a particular user

CREATE TABLE – defines a table and its columns

CREATE VIEW – defines a logical table from one or more views

Other CREATE statements: CHARACTER SET, COLLATION, TRANSLATION, ASSERTION, DOMAIN

Page 16: Sql database development part 1

Relational Data Model

Page 17: Sql database development part 1

Sample CREATE VIEW

CREATE VIEW EXPENSIVE_STUFF_V AS

SELECT PRODUCT_ID, PRODUCT_NAME, UNIT_PRICE

FROM PRODUCT_T

WHERE UNIT_PRICE >300

WITH CHECK_OPTION;

View has a name

View is based on a SELECT statement

CHECK_OPTION works only for updateable views and prevents updates that would create rows not included in the view

Page 18: Sql database development part 1

Changing and Removing Tables

ALTER TABLE statement allows you to change column specifications:

ALTER TABLE CUSTOMER_T ADD (TYPE VARCHAR(2))

DROP TABLE statement allows you to remove tables from your schema:

DROP TABLE CUSTOMER_T

Page 19: Sql database development part 1

Schema Definition Control processing/storage efficiency:

Choice of indexes File organizations for base tables File organizations for indexes Data clustering Statistics maintenance

Creating indexes Speed up random/sequential access to base table data Example

CREATE INDEX NAME_IDX ON CUSTOMER_T(CUSTOMER_NAME)

This makes an index for the CUSTOMER_NAME field of the CUSTOMER_T table