Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts Thursday, September 13, 2000 “Structured Query Language” Lecture No. 8 SQL
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts 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;
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts 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;
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts 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
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts 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
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts 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;
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts 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’)
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts SQL Views Create or replace view SALVIEW as (select name from names n, salary s where n.SSN = s.ssn and s.Salary > 4000);
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts SQL COMMIT AUTOCOMMIT Set AUTOCOMMIT ON/OF COMMIT Commit ROLLBACK Rollback
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts SQL Index Create index create index ssn_idx on NAMES (SSN); Advantages and disadvantages of using index. Guide lines for creating an index
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts SQL TIPS PASSWORD HELP / ed Query performance
Kansas State University Department of Computing and Information Sciences CIS 560: Database System Concepts SQL Preview SQL Loader Embedded SQL PL/ SQL Dynamic SQL Meta data