Upload
samantha-walters
View
212
Download
0
Embed Size (px)
Citation preview
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 (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)
);
Adding Constraints
Table Level Using ALTER Table command
Syntax:
ALTER TABLE <table_name>ADD CONSTRAINTS <const_name>
Dropping Constraints
To drop a constraint we useALTER table command
Ex.ALTER TABLE student
DROP constraint GPA_ck;
Insert In the Tables
Syntax
INSERT INTO <table_name>[(column[,column,..])]
values (‘…’,’ …’, …. );
Only one row is inserted at a time with this syntax.
Updating Rows’ Values Syntax:
UPDATE <table_name>SET <column> = value
[,column=value, …][WHRER condition];
Delete
Syntax:DELETE FROM <table_name>
[WHERE condition];
Basic Queries in SQL
SQL has one basic statement for retrieving information from a database
The Select Statement
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
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.