Beruflich Dokumente
Kultur Dokumente
SQL is a very powerful and diverse database language use to storing data
into databases. SQL is loosely typed language so you can learn easily.
In this SQL tutorial, we use command line examples to know about executing
speed of SQL. It's take very bit of time for executing and retrieving result.
SQL is a greater tool with web languages such as PHP, Python, Java, ASP et
cetera to build dynamic web applications.
Before starting SQL, relational databases have several point that are
important to keep in mind.
1. RDBMS stands for Relational Database Management System.
2. Data Integrity : Store data only once and avoiding data duplication.
3. SQL Constraints : Constraints are the rules which are apply to table
columns to store valid data and prevents the user to storing/entering
invalid data into table columns.
4. Better security : Assign grant or privilege to a individual User. Using
this grant user can store confidential data into table by using
username or password.
5. Database Normalization : Database normalization is the process to
store database data very efficiently. No need to store same data more
then one time and reduce the Data redundancy.
6. Different types of relationships : One to one, One to many, Many to
many
1. One to one relationship : merging for two tables.
2. One to many relationship : create a foreign key from an parent
table to the child table.
3. Many to many relationship : create a new relation table.
Keep in your mind...
When you execute SQL query come to a SQL Server. SQL Server work is
managing database, load balancing, transaction management etc. SQL
server call to a actual physical database table and return the result. This
process is take small bit of time and depend of query and SQL server load.
Use forward slash(/) once at the end of each script, to tell SQL that
there is not more lines of code. you can't use forward slash(/) at the
middle of the script.
Data definition statement are use to define the database structure or table.
Statement
Description
CREATE
ALTER
DROP
Deletes a database/table.
TRUNCATE
RENAME
Description
SELECT
INSERT
UPDATE
DELETE
MERGE
LOCK TABLE
CALL
EXPLAIN PLAN
Description
GRANT
REVOKE
ANALYZE
AUDIT
COMMENT
Description
COMMIT
ROLLBACK
SAVEPOINT
SET
TRANSACTION
Description
ALTER SESSION
SET ROLE
Oracle database provide built-in SQL data types also you can make user
define types for letter use as data types. Every database define a column
data type for each and every tables.
SQL data types are two type scaler type or non scalar type. Scalar SQL data
types haven't internal components. It's like linear data types. Whereas non
scalar SQL data types have internal component to store multiple values and
easily you can manipulate the data.
Oracle SQL Data types
Built-in Oracle SQL data types are following,
1. Numeric Datatypes
2. Character Datatypes
3. LONG and ROW Datatypes
4. ROWID Datatypes
5. Datetime Datatypes
6. Large Object Datatypes
Number Datatypes
Following are numeric data types in SQL
Data Type
Description
Maximum
Precision
INTEGER
38 digits
INT
38 digits
SMALLINT
38 digits
FLOAT [ (size) ]
126 binary
digits
FLOAT(126)
DOUBLE PRECISION
126 binary
digits
FLOAT(126)
REAL
63 binary
digits
FLOAT(63)
DECIMAL[(precision
38 digits
[, scale ])]
NUMERIC[(precision
38 digits
[, scale ])]
Oracle Data
types
NUMBER(p,0)
NUMBER(p,s)
BINARY_FLOAT
BINARY_DOUBLE
Character Datatypes
Description
Storage(Maxim
um)
CHAR
[ (size) ]
2000 bytes
NCHAR
[ (size) ]
2000 bytes
4000 bytes
Data Type
Description
RAW(size)
LONG
upto 2
gigabytes
ROWID Datatypes
ROWID data type represent actual storage address of a row. following are
ROWID datatypes in Oracle SQL:
Storage(Maxim
um)
Data Type
Description
ROWID
Range
Jan 1, 4712
BC to
Dec 31,
9999 AD
DATE
TIMESTA
MP
Example :
CREATE TABLE time_table(
start_time TIMESTAMP,
time1
Variable that has interval data type hold value call intervals. Following are
Interval data types in SQL:
Data Type
Description
INTERVAL
YEAR TO
MONTH
INTERVAL
DAY TO
SECOND
Description
Storage(Maximum
)
BFILE
Size: up to 4GB
(232 - 1 bytes)
Directory name:
30 character
File name: 255
characters
BLOB
Size: 8 TB to 128
TB
(4GB - 1) *
DB_BLOCK_SIZE
CLOB
Size: 8 TB to 128
TB
(4GB - 1) *
DB_BLOCK_SIZE
Size: 8 TB to 128
TB
(4GB - 1) *
DB_BLOCK_SIZE
SQL Syntax is easy and most of the database action you can done using SQL
statement. Following are fewer most frequently useful SQL Query syntax,
1. CREATE DATABASE Syntax
2. DROP DATABASE Syntax
3. CREATE TABLE Syntax
4. DESCRIBE TABLE Column Syntax
5. INSERT Syntax
6. UPDATE Syntax
7. DELETE Syntax
8. SELECT Syntax
9. ALTER TABLE Syntax
10.
11.
COMMIT Syntax
12.
ROLLBACK Syntax
13.
Example :
SQL> INSERT INTO users_info (no,name,address)
VALUES (1, 'Opal Kole', '63 street Ct.');
4 rows created.
UPDATE table_name
SET column_name1 = value1, column_name2 = value2 , ...
[ WHERE condition ]
[ LIMIT number ];
Example :
SQL> UPDATE users_info
SET name = "Beccaa Moss" , address ="2500 green city."
WHERE no = 3;
Example :
We have to fetch all table columns using asterisk (*),
SQL> SELECT * FROM users_info WHERE no = 3;