Your SlideShare is downloading. ×
13 Sql i php
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

13 Sql i php

121

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
121
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Introduction to SQL
  • 2. SQL  SQL (Structure Query Language) It is relational database language that enables you to create and operate on relational database.
  • 3. Feature of SQL  It is a non procedural language.  It is a 4GL programming language. (i.e. only What to do? not How to do?).  It is a case insensitive language.
  • 4. Constraints of SQL  A constraint is a condition or check that is applied to a column or set of columns in a table.  Null Constraint: It means a Unknown Value. Eg. mobile number(10) null  Not Null Constraint: It means always a Known Value. Eg. name varchar2(20) not null
  • 5.  Unique Constraint: It ensures that no two rows have the same value in the specified column(s). i.e Known Value (Distinct) or Unknown Value. Eg. ecode number(5) unique  Primary Key Constraint: It is similar to Unique constraint except that the Primary Key can not allow Null values so that this constraint must be applied to columns declared as Not Null. i.e Always Known Value (Distinct). Eg. empid char(5) primary key Constraints of SQL
  • 6.  Default Constraint: A default value can be specified for a column using default clause when a user does not enter a value for that column. Eg. grade char(2) default ‘E1’ Constraints of SQL
  • 7. Foreign Key Constraint:  Whenever two tables are related by a common column then Foreign Key is present in the Child table (Related Table or Detail Table) and it is derived from primary key of Parent Table (Primary Table or Master Table).  Eg. Two Tables:  Items (Itemno, Description, Price)  Orders (Orderno, Orderdate, Itemno, Qty)  where Itemno & Orderno are Primary Key and Itemno is Foreign Key. i.e both the tables are related through common column Itemno.  Note: It may be possible that Primary Key and Foreign Key are same.  Eg. create table Items  ( Itemno char(5) Primary Key,  …………….);  create table Orders  ( Orderno number(5) Primary Key,  Itemno char(5),  constraint fk foreign key (itemno) references items(itemno)  …………….  ); Constraints of SQL (Contd:)
  • 8. Classification of SQL Commands  DDL Commands  DML Commands  DCL Commands  Query Language
  • 9. DDL Commands DDL (Data Definition Language):  It provides commands for defining various database objects (i.e defining relation schemas, deleting relations, creating indexes, and modifying relation schemas etc.)  Eg. Create, Alter, Drop etc.
  • 10.  The tables are created by using Create Table command and also its columns are named, data types and sizes are supplied for each column.  Syntax: create table <table_name>  (  <col1> <datatype> [<size>] [<constraint>],  <col2> <datatype> [<size>] [<constraint>],  ………..  <coln> <datatype> [<size>] [<constraint>]  );  Eg. create table emp1  (  empid char(4) primary key,  ename varchar2(20) not null,   ); Create Command
  • 11. EmpidEmpid EnameEname SalSal E001E001 SmithSmith 50005000 E002E002 JohnJohn 1000010000 E003E003 JamesJames 25002500
  • 12. Alter Command  Altering Table: The alter table command is used to modify the structure of existing table. (i.e adding a column, add an integrity constraint etc.).  Adding Columns: The new column will be added with NULL values for all rows currently in table.  Syntax: alter table <table_name>  add column(<col1> <datatype> <size> [<constraint>],  <col2> <datatype> <size> <constraint>] …….);  Eg. alter table emp  add column(tel_number number(11) );
  • 13. Alter table  Modifying Column Definitions: To change datatype, size, default value and NOT NULL column constraint of a column definition.  Syntax:  alter table <table_name>  modify <col_name> <new_datatype> <new_size>;  Eg. alter table emp  modify tel_number int(13) ;
  • 14. Alter table (Contd:)  Deleting Column: To change datatype, size, default value and NOT NULL column constraint of a column definition.  Syntax:  alter table <table_name>  drop <col_name>;  Eg. alter table emp  drop tel_number;
  • 15. Drop table  Drop Table Command: It removes a table from the database .  Syntax:  drop table <table_name>;  Eg. Drop table emp;
  • 16. Data Manipulation Language(DML)  (Data Manipulation Language): It enables users to manipulate data (i.e commands to insert, delete, and modify tuples in the database).  Eg. Insert, Update, Delete etc.
  • 17. Insert table  Inserting Data into Table  The data can be inserted in a table using Insert Into command.  Syntax: insert into <table_name> [<column_lists>]  values (<value1>, <value2>, …………….);  Eg. insert into emp1  values(‘E001’,’Vipin’,5000);  Note: Here the order of values matches the order of columns in the create table command of the table.  Or insert into emp1 (empid, ename, sal)  values(‘E001’,’Vipin’,5000); Note: The columns not listed in the insert into command will have their default values or null values.
  • 18.  Modifying Data with Update Command  This is a DML statement used to modify or change some or all of the values in an existing row of a table.  Syntax: update <table_name>  set col1 = <new_value>,  col2 = < new_value>,  …..coln = <new_value>  [where <condition>];  Eg. update emp  set sal= 400; ‘updates all rows  Eg. update emp  set sal= sal*2, ename= ‘JONES’  where empno = 7844; ‘update only one row Update table
  • 19.  This is also a DML statement used to remove row(s) of a table.  Syntax: delete from <table_name>  [where <condition>];  Eg. delete from emp  where sal < 5000; Delete table

×