Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL/SyBase Programming. A Database is... A collection of related tables containing data and definitions of database objects. The “table” is a paradigm.

Similar presentations


Presentation on theme: "SQL/SyBase Programming. A Database is... A collection of related tables containing data and definitions of database objects. The “table” is a paradigm."— Presentation transcript:

1 SQL/SyBase Programming

2 A Database is... A collection of related tables containing data and definitions of database objects. The “table” is a paradigm which describes the data stored within the database.

3 The Relational Model Codd’s 12 RulesCodd’s 12 Rules –Information rule - everything is a table –Data independence –Comprehensive data sublanguage –Support relational operations (select, project, join) –View updating rule –Systematic null value support –Integrity independence

4 Tables Tables contain:Tables contain: –Rows = Records –Columns = Fields –Primary Key = Unique Identifier –Data Elements = Value

5 Occupation Table

6 Two Kinds of Tables User TablesUser Tables –contain user loaded data –primary query tables –created, modified, maintained by user System TablesSystem Tables –contain database and table descriptions –maintained by database system –can be queried like any other table

7 Structured Query Language (SQL) SQL specifies syntax features for retrieval update and definition of the database.SQL specifies syntax features for retrieval update and definition of the database. –SELECT - query data in the database –INSERT - Add a single row –UPDATE - Alter attribute values in rows –DELETE - Delete rows of data from a table

8 Select Statement Its syntax is : SELECT (select-list - attributes or derived data) FROM (table name or names) WHERE (sets up conditions) SELECT and FROM are required SELECT Name FROM OCCUPATIONS WHERE ID = 101;

9 Select Examples PNAME NUT BOLT CARAVAN PARTNO P1 P2 P3 PRICE $0.20 $1.00 $5000.00 QOH 20 40 3 SELECT * FROM PART; Selects all column values for all rows SELECT PARTNO, PNAME FROM PART WHERE PRICE >= 0.2; Selects rows where price >=.2 SELECT PARTNO, PNAME FROM PART WHERE PNAME LIKE (’CAR%'); Selects rows where pname has a value starting with CAR PART

10 Insert Statement This command allows data to be inserted, one row at a time, into an existing table Syntax: Insert into (list of attributes) values (list of values) Note: The list of attributes can be ignored providing the order of attribute values, and completeness of attribute instances, is as per the table list. example: insert into emp(name, sal, byear) values(‘Jones, Bill’, 45000,1967); values(‘Jones, Bill’, 45000,1967); or(see note) insert into emp values(‘Jones, Bill’, 45000,1967);

11 Update Statement UPDATE tablename SET colname = expression {, colname = expression} [ WHERE search_condition ] [ WHERE search_condition ] Replaces values of the specified columns with expression values for all rows satisfying the search-condition.Replaces values of the specified columns with expression values for all rows satisfying the search-condition. Expressions in the set clause may be constants or column values from the UPDATE tablename or FROM tablenameExpressions in the set clause may be constants or column values from the UPDATE tablename or FROM tablename Example: UPDATE PART SET price = price * 1.1 SET price = price * 1.1 WHERE price < 20; WHERE price < 20;

12 Delete Statement DELETE FROM tablename [ WHERE search-condition ] [ WHERE search-condition ] Delete one or many rows in a table.In general search-condition and qualification may not involve a sub select on tablename. DELETE FROM PART WHERE qoh < 4.00;

13 Joining Tables EMPDEP SELECT e.empno AS Number, e.ename AS Name, d.dname AS Department FROM emp e, dep d WHERE e.deptno = d.deptno; EMPNO E1 E2 E3 ENAME RED BLUE BROWN MGRNO E1 DEPTNO D1 D2 DEPTNO D1 D2 D3 DNAME TAX PAY LEAVE Number E1 E2 E3 Name RED BLUE BROWN Department TAX PAY

14 A Search and Join Condition For each prime minister born in or after 1900, give his name, birth year and party. SELECT P.PM_NAME, BIRTH_YR, PARTY FROM PRIME_MINISTER P, MINISTRY M WHERE P.PM_NAME = M.PM_NAME AND BIRTH_YR >= 1900; PM_NAME BIRTH_YR PARTY Holt H E 1908 Liberal McEwen J 1900 Country Gorton J G 1911 Liberal


Download ppt "SQL/SyBase Programming. A Database is... A collection of related tables containing data and definitions of database objects. The “table” is a paradigm."

Similar presentations


Ads by Google