120 likes | 206 Views
SQL. Lecture No. 8. Thursday, September 13, 2000 “Structured Query Language”. SQL. Table definition Find what tables exist Select * from tab;. Create new table create table NAMES (SSN integer not null, NAME varchar(40) not null, GENDER char(1));.
E N D
SQL Lecture No. 8 Thursday, September 13, 2000 “Structured Query Language”
SQL • Table definition • Find what tables exist • Select * from tab; • Create new table • create table NAMES (SSN integer not null, • NAME varchar(40) not null, • GENDER char(1)); • Review table definition • desc NAMES;
SQL • Table definition (contd.) • Alter table • Alter table names add (dob date not null); • Alter table names modify (gender char(3)); • Alter table names drop COLUMN dob; • Drop table • drop table NAMES;
SQL • Teaser • LETTER (From, To, Subject); • create table LETTER (From varchar(40) not null, • To varchar(40) not null, • Subject char(1)); • Error: ORA-00904: invalid column name
SQL • Inserting records • Inserting values for all columns • insert into names values (1234, ‘arul’,’M’); • Inserting values for selected columns • insert into names (SSN, Names) values (1234, ‘arul’) • Teaser: • insert into names values (1234, “M”,”Arul”); • ORA-00984: column not allowed here
SQL • Select statement • NAMES (SSN, NAME, GENDER, DOB) • SALARY (SSN, Salary) • List all names in ascending order of those that have salary less than 4000$ • select name from • names n, salary s • where n.SSN = s.ssn and • s.Salary > 4000 • order by n.name asc;
SQL • Date manipulation • To_date • insert into names values (1234, ‘arul’,’M’, • to_date (‘08/11/1974’,’mm/dd/yyyy)); • To_char • select to_char(dob, ‘mm/dd/yyyy’)
SQL • Views • Create or replace view SALVIEW as • (select name from • names n, salary s • where n.SSN = s.ssn and • s.Salary > 4000);
SQL • COMMIT • AUTOCOMMIT • Set AUTOCOMMIT ON/OF • COMMIT • Commit • ROLLBACK • Rollback
SQL • Index • Create index • create index ssn_idx on NAMES (SSN); • Advantages and disadvantages of using index. • Guide lines for creating an index
SQL • TIPS • PASSWORD • HELP • / • ed • Query performance
SQL • Preview • SQL Loader • Embedded SQL • PL/ SQL • Dynamic SQL • Meta data