Sei sulla pagina 1di 19

SQL

DATATYPES
VARCHAR2(say) : Deiken uzunluklu alfasaysal verilerin

tutulduu alanlar iin kullanlr. NUMBER(n, p) : Tamsay ve gerel saylar iin kullanlan saysal veri tipidir.
(Number having precision p and scale s. The precision p can range from 1 to 38. The scale s can range from

-84 to 127.)

CHAR(say) : Sabit uzunluktaki alfasaysal verilerin

tutulabildii alanlar iin kullanlr. Eer, say ile ifade edilen numaradan daha ksa uzunlukta veriler girilirse Oracle kaydn sonuna boluk ekleyerek sabit uzunlua kadar getirir.

ALTER SESSION
The purpose of the ALTER SESSION statement is "to specify

or modify any of the conditions or parameters that affect your connection to the database. The statement stays in effect until you disconnect from the database.

ALTER TABLE
After you create your tables, you may need to change the table

structures because you omitted a column or your column definition needs to be changed. You can do this by using the ALTER TABLE statement.

ALTER TABLE dept30

ADD(job VARCHAR2(9));
ALTER TABLE dept30

MODIFY (ename VARCHAR2(15));


ALTER TABLE dept30

DROP COLUMN job ;

DROP TABLE
DROP TABLE dept30;
DROP TABLE <table name> [CASCADE CONSTRAINTS]

CONSTRAINTS
NOT NULL CREATE TABLE emp( empno NUMBER(4), ename VARCHAR2(10) NOT NULL, job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(7,2) NOT NULL);

CONSTRAINTS (2)
UNIQUE KEY
A UNIQUE key integrity constraint requires that every value in a column or set of columns (key) be unique. CREATE TABLE dept( deptno NUMBER(2), dname VARCHAR2(14), loc VARCHAR2(13), CONSTRAINT dept_dname_uk UNIQUE(dname));

CONSTRAINTS (3)
PRIMARY KEY
The PRIMARY KEY constraint is a column or set of columns that uniquely identifies each row in a table. CREATE TABLE dept( deptno NUMBER(2), dname VARCHAR2(14), loc VARCHAR2(13), CONSTRAINT dept_dname_uk UNIQUE (dname), CONSTRAINT dept_deptno_pk PRIMARY KEY(deptno));

CONSTRAINTS (4)
FOREIGN KEY - REFERENCES
CREATE TABLE emp( empno NUMBER(4), ename VARCHAR2(10) NOT NULL, job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(7,2) NOT NULL, CONSTRAINT emp_deptno_fk FOREIGN KEY (deptno) REFERENCES dept (deptno));

CONSTRAINTS (5)
The CASCADE CONSTRAINTS clause is used along with

the DROP COLUMN clause.


The CASCADE CONSTRAINTS clause drops all

referential integrity constraints that refer to the


primary and unique keys defined on the dropped columns.

CONSTRAINTS (6)
ON DELETE CASCADE indicates that when the row in

the parent table is deleted, the dependent rows in the child table will also be deleted.
Without the ON DELETE CASCADE option, the row in

the parent table cannot be deleted if it is referenced in the child table.

CONSTRAINTS (7)
CHECK

Defines a condition that each row must satisfy.

deptno

NUMBER(2),

CONSTRAINT emp_deptno_ck CHECK (DEPTNO BETWEEN 10 AND 99),...

ADDING A CONSTRAINT
ALTER TABLE table

ADD [CONSTRAINT constraint] type (column);


Ex: ALTER TABLE emp ADD CONSTRAINT emp_mgr_fk FOREIGN KEY(mgr) REFERENCES emp(empno);

DROPPING A CONSTRAINT
ALTER TABLE

DROP CONSTRAINT

emp emp_mgr_fk;

DISABLING/ENABLING CONSTRAINTS
ALTER TABLE emp

DISABLE CONSTRAINT emp_empno_pk CASCADE;

Apply the CASCADE option to disable dependent integrity constraints.


ALTER TABLE emp

ENABLE CONSTRAINT emp_empno_pk;

VIEW
In SQL, a VIEW is a virtual relation based on the result-set of a

SELECT statement.
Tablolarn grnm

Sanal tablo

CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition

VIEW (2)
Example: Create a view with title and year and made by

Paramount studio.

CREATE VIEW ParamountMovie AS

SELECT title, year FROM Movie WHERE studioName = Paramount;

MODIFYING VIEW
INSERT
INSERT INTO ParamountMovie

VALUES (Star Trek, 1979);

DELETE
DELETE FROM ParamountMovie

WHERE title LIKE %Trek%; DELETE FROM Movie WHERE title LIKE %Trek% AND studioName = Paramount;

MODIFYING VIEW (2)


UPDATE
UPDATE ParamountMovie

SET year = 1979 WHERE title = Star Trek the Movie;

DROP VIEW ParamountMovie

Potrebbero piacerti anche