Sie sind auf Seite 1von 4

DEPARTMENT OF COMPUTER SCIENCE

(University of Management and Technology, Sialkot)

DATABASE SYSTEMS

Name: Registration No:

LAB 02

Introduction to Database basic concepts and SQL SELECT statement

Relational Database: A relational database is a collection of relations or two-dimensional tables


to store information.

Entity: A thing of significance about which information needs to be known. Examples are
departments, employees, and orders.

Attribute: Something that describes or qualifies an entity. For example, for the employee entity,
the attributes would be the employee number, name, job title, hire date, department number, and
so on. Each of the attributes is either required or optional.

Relationship: A named association between entities showing optionality and degree. Examples
are employees and departments, and orders and items.

Primary Key: A primary key is a single attribute or a collection of attributes which is used to
distinguish—that is, uniquely identify the entity.

SQL SELECT Statement

A SELECT statement retrieves information from the database. With a SELECT statement, you
can use the following capabilities:

• Projection: Choose the columns in a table that are returned by a query. Choose as few or as
many of the columns as needed
• Selection: Choose the rows in a table that are returned by a query. Various criteria can be used
to restrict the rows that are retrieved.

• Joining: Bring together data that is stored in different tables by specifying the link between
them.

Syntax of SELECT statement is

Using Arithmatic Operator

Defining a NULL Value: A null is a value that is unavailable, unassigned, unknown, or


inapplicable. Arithmatic expressions containing a NULL value evaluates to NULL.

Using Column Alias: A column alias renames a column heading.

Concatenation Operator (||): It is used to link columns to other columns, arithmetic


expressions, or constant values to create a character expression. Columns on either side of the
operator are combined to make a single output column.

Literal Character Strings: A Literal is a character, a number or a date that is included in the
select list and that is not a column name or column alias. We can use literal with concatenation
operator and with column names. Date and character literals must be enclosed by single
quotation marks (' '); number literals need not be so enclosed.
Alternative Quote (q) Operator: Many SQL statements use character literals in expressions or
conditions. If the literal itself contains a single quotation mark, you can use the quote (q)
operator.

Use of DISTINCT Keyword

Displaying Structure of Table

LAB TASKS

1. The following SELECT statement executes successfully:

SELECT last_name, job_id, salary AS Sal FROM employees;

True/False

2. The following SELECT statement executes

successfully: SELECT * FROM job_grades;

True/False

3. There are four coding errors in the following statement. Can you identify them?

SELECT employee_id, last_name sal x 12 ANNUAL SALARY FROM

employees;

4. Write a query that return all columns and all records of department table.

5. Write a query that return only department_name and location_id.

6. Get all employees with their name and hire date, change the column heading of hire date
column.

7. Write a query that display all unique job codes from Employee table.
8. Write a query that print all employees and their job IDs, Display the last name concatenated
with the job ID (separated by a comma and space) and name of the column Employee and Title.

9. To familiarize yourself with the data in the EMPLOYEES table, create a query to display all
the data from that table. Separate each column output by a comma. Name the column title
THE_OUTPUT.

Das könnte Ihnen auch gefallen