10
Constraints Constraints are used to enforce rules at table level. Constraints prevent the deletion of a table if there is dependencies. The following constraints types are valid in : Not Null Default Unique Primary key Foreign key

Constraints Constraints are used to enforce rules at table level. Constraints prevent the deletion of a table if there is dependencies. The following

Embed Size (px)

Citation preview

Page 1: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Constraints Constraints are used to enforce rules at table level.

Constraints prevent the deletion of a table if there is dependencies.

The following constraints types are valid in :

• Not Null• Default• Unique• Primary key• Foreign key

Page 2: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Constraints (Example)

CREATE TABLE student( ID Number(8),

Name Varchar2(15), GPA Number(3,2), Major Varchar2(5) Not Null, DOB Date,PRIMARY KEY (ID),UNIQUE (Name)

);

Page 3: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Adding Constraints

Table Level Using ALTER Table command

Syntax:

ALTER TABLE <table_name>ADD CONSTRAINTS <const_name>

Page 4: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Dropping Constraints

To drop a constraint we useALTER table command

Ex.ALTER TABLE student

DROP constraint GPA_ck;

Page 5: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Insert In the Tables

Syntax

INSERT INTO <table_name>[(column[,column,..])]

values (‘…’,’ …’, …. );

Only one row is inserted at a time with this syntax.

Page 6: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Updating Rows’ Values Syntax:

UPDATE <table_name>SET <column> = value

[,column=value, …][WHRER condition];

Page 7: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Delete

Syntax:DELETE FROM <table_name>

[WHERE condition];

Page 8: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

Basic Queries in SQL

SQL has one basic statement for retrieving information from a database

The Select Statement

Page 9: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

The basic form of select statement is formed of three clauses SELECT , FROM and WHERE

SELECT <attribute list> FROM <table list> WHERE <condition>;

The SELECT-FROM-WHERE structure

Page 10: Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following

SQL Statement <attribute list> is a list of attribute

names whose values are to be retrieved by the query.

<table list> is a list of the relation (table) names required to process the query.

<Condition> is a conditional (Boolean) expression that identifies the records to be retrieved by the query.