Académique Documents
Professionnel Documents
Culture Documents
ICT118 Lecture 3 SQL command types Syntax for querying a table with the SELECT statement
Database Administration
Creating and maintaining tables according to the database design (schema) Creating and controlling users Applying constraints to tables to implement business rules Using SQL statements in the Database Management System ours is Oracle 11g Interfacing the database to application programs and middleware
22 July, 2010 ICT118 Database and Information Retrieval, Sem 2, 2010 3. 2
Architecture
multiclientTypically a multi-tier client-server architecture
Application Client Application Client Application Client Application Client
Database Server
Middleware Server
Legacy Files
22 July, 2010
3. 3
22 July, 2010
3. 4
22 July, 2010
3. 5
Application programmers
Write DML and TCL statements to access and populate the data structures needed by application programs During maintenance phase use DDL to create and alter tables Embed the statements in application program code Work with DBA to optimise TCL for security and performance
22 July, 2010 ICT118 Database and Information Retrieval, Sem 2, 2010 3. 6
Objectives
Create the initial database Identify keywords, mandatory clauses, and optional clauses in a SELECT statement Select and view all columns of a table Select and view one column of a table Display multiple columns of a table
22 July, 2010
3. 8
Objectives (continued)
Use a column alias to clarify the contents of a particular column Perform basic arithmetic operations in the SELECT clause Remove duplicate lists using either the DISTINCT or UNIQUE keyword Use concatenation to combine fields, literals, and other data
22 July, 2010 ICT118 Database and Information Retrieval, Sem 2, 2010 3. 9
22 July, 2010
3. 11
22 July, 2010
3. 12
22 July, 2010
3. 13
22 July, 2010
3. 14
22 July, 2010
3. 15
22 July, 2010
3. 16
22 July, 2010
3. 17
22 July, 2010
3. 18
22 July, 2010
3. 19
22 July, 2010
3. 20
22 July, 2010
3. 21
NULL Values
Null operand in any operation gives a null result
22 July, 2010
3. 22
22 July, 2010
3. 23
Using Concatenation
You can combine data in different columns with the concatenation operator || The data appear side by side For better formatting, you can include a space between the data with a string literal Any input enclosed in is interpreted literally An alias used with concatenation improves Heading readability
Concatenation Example
Concatenation symbol Alias
22 July, 2010
3. 25
Summary
A basic query in Oracle 11g SQL includes the SELECT and FROM clauses, the only mandatory clauses in a SELECT statement To view all columns in the table, specify an asterisk (*) or list all of the column names individually in the SELECT clause To display a specific column or set of columns, list the column names in the SELECT clause in the order in which you want them to appear and separated by commas
22 July, 2010 ICT118 Database and Information Retrieval, Sem 2, 2010 3. 26
Summary (continued)
A column alias is used to clarify the contents of a particular column If the alias contains spaces or special symbols, or If you want to display the column with any lowercase letters Thenyou must enclose the column alias in double quotation marks (" ") Indicate the table name following the FROM keyword
22 July, 2010 ICT118 Database and Information Retrieval, Sem 2, 2010 3. 27
Summary (continued)
Basic arithmetic operations can be performed in the SELECT clause NULL values indicate an absence of a value and nullify any operation results To remove duplicate listings, include either the DISTINCT or UNIQUE keyword To specify which table contains the desired columns, you must list the name of the table after the keyword FROM Use vertical bars ( || ) to combine, or concatenate, fields, literals, and other data
22 July, 2010 ICT118 Database and Information Retrieval, Sem 2, 2010 3. 28
10