Sunteți pe pagina 1din 27

Chapter 1: What is a Relational Database There is a three-phase process in developing a database: o Logical design: defining tables, fields, Primary

and Foreign keys, establishing table relationships and levels of data integrity. o Implementation of the logical design: using a DBMS to create tables and their relationships, using the tools to implement levels of data integrity. o Development of end-user application. There are two types of databases: Operational and Analytical. Operational is used in everyday businesses, institutions and organizations. They are primarily used to store data that is collected, maintained and modified (dynamic data). Analytical is used to track historical data (static data). Track trends, view statistical data. In a RDM, data are stored in a relation or table (those terms may be used interchangeably.) Each table contains rows or records, (also called tuples), and columns which represent attributes or fields. Each record or row is repres ented by a unique field known as the Primary key. The Categories of relationships in a RDM are one-to-one, one-to-many, and many-to many Data is retrieved by specifying fields and tables using a standard query language known as Structured Query Language (SQL). Most DBMSs (Database Managements Systems) use SQL to build, modify, maintain and manipulate databases.

Chapter 2: Design Objectives There are three traditional design methods: A requirements analysis phase involves examining the business being modeled, interviewing users and management to assess the current system and to analyze future needs and determining information requirements for the business as a whole A data modeling phase involves modeling the database structure itself by using a method such as entity relationship diagramming (ER diagramming). This provides a means of visually representing various aspects of the database structure, such as the tables, table relationships and relationship characteristics The Normalization phase is the process of decomposing large tables into smaller tables in order to eliminate redundant data, duplicate data and avoid problems with inserting, modifying or deleting data.

Chapter 3: Terminology Four categories of terms are described in this chapter: value-related, structure-related, relationship-related, and integrity-related. Value Related Terms o Data are the values that are stored in the database. They are static in the sense that they remain in the same state until they are modified. o Information is data that has been processed in a way that makes it meaningful. It can be shown as the result of a query, either displayed on-screen, or printed on a report. o Null is a value that is either missing or unknown. A null value represents neither zero nor blank, as they are actual values and can be meaningful in certain circumstances. A drawback to null values is that they cannot be evaluated by mathetatical expressions. Structure Related Terms o A table is the main structure in a relational database. It always represents a single, specific subject, which can be an object or an event A Primary key is a field that uniquely identifies a record within a table. A Foreign key is the field that is used to establish a relationship between a pair of tables Relationship-related Terms Relationships establish a connection between a pair of tables. This relationship exists when a pair of tables is connected by a Primary and Foreign key. Types of Relationships One-to-One: Exists between a pair of tables if a single record in the first table is related to one and only one record in the second table. EMPLOYEES Employee ID Emp First Name Emp Last Name Home Phone 100 Zachary Erlich 553-3992 101 Susan McLain 790-3992 102 Joe Rosales 551-4993 COMPENSATION Employee ID Hourly Rate 100 25.00 101 19.75 102 22.50

Commission Rate 50% 3.5% 5.0%

One-to-Many: Exists between a pair of tables if a single record in the first table is related to one or more records in the second table, but a single record in the second table can be related to only one record in the first table. This is the most common type of relationship. STUDENTS

Student ID 60003 60928 60765

Student First Name Zachary Susan Joe

Student Last Name Erlich McLain Rosales

Student Phone 553-3992 790-3992 551-4993

INSTRUMENTS Instrument ID Desc 11128 Stratocaster 11185 Pro 11147 Many-to-Many :

Student ID 60003 60765 60765

Instrument Type Guitar Drums Guitar

Instrument

Ludwig Les Paul

A many-to-many relationship is modelled with tree tables. Two 'source' tables and one junction table. The primary key of the junction table A_B is a composite key. It is made of two fields: the two foreign key fields that refer to the primary key of table A and table B.

All primary keys must be unique. This implies that the combination of field A and B must be unique in table A_B. The database design example below shows you the tables that could exist in the many-to-many relationship between Belgian beer brands and their distributors in the Netherlands. Notice how all combinations of beer_id and distibutor_id are unique in the junction table.

Beer tables

Persistent (Base tables are permanent) : Base tables are sometimes called main, persistent, or permanent tables because they are a permanent part of the database until you drop them explicitly. They remain in the database over user disconnects, server restart, and recovery. Base tables and the data in them are accessible to all users who have the appropriate permissions. Non-persistent in-memory tables : Non-persistent in-memory tables are not written to disk when the server shuts down. Therefore, any time that the server shuts down, whether normally or abnormally, the data in non-persistent tables is lost. Their data is not logged or checkpointed. That makes them irrecoverable but remarkably faster than persistent tables. There are two different types of non-persistent in-memory tables: Transient Tables and Temporary Tables. Transient Tables : Transient Tables last until the database server shuts down. Multiple users may use the same Transient Table, and each user will see all other users' data. Temporary Tables : The data in Temporary Tables is visible only to the connection that inserted the data, and the data is retained only for the duration of the connection. Temporary Tables are like private scratchpads that no one else can see.

Column : An individual piece of data stored in a table. Row : A set of columns that together completely describe an entity or some action on an entity. Table: A set of rows, held either in memory (nonpersistent) or on permanent storage (persistent). Result set Another name for a nonpersistent table, generally the result of an SQL query.

KEYS :
Superkey - An attribute or a combination of attribute that is used to identify the records uniquely is known as Super Key. A table can have many SuperKeys. E.g. of SuperKey 1 ID 2 ID, Name 3 ID, Address 4 ID, Department_ID 5 ID, Salary 6 Name, Address 7 Name, Address, Department_ID So on as any combination which can identify the records uniquely will be a SuperKey. Candidate key - It can be defined as minimal Super Key or irreducible Super Key. In other words an attribute or a combination of attribute that identifies the record uniquely but none of its proper subsets can identify the records uniquely. E.g. of Candidate Key 1 Code 2 Name, Address For above table we have only two Candidate Keys (i.e. Irreducible Super Key) used to identify the records from the table uniquely. Code Key can identify the record uniquely and similarly combination of Name and Address can identify the record uniquely, but neither Name nor Address can be used to identify the records uniquely as it might be possible that we have two employees with similar name or two employees from the same house. Note :A candidate key can qualify as a primary key and it can be a single column or combination of columns Primary key A Candidate Key that is used by the database designer for unique identification of each row in a table is known as Primary Key. A Primary Key can consist of one or more attributes of a table.It cannot be null

E.g. of Primary Key - Database designer can use one of the Candidate Key as a Primary Key. In this case we have Code and Name, Address as Candidate Key, we will consider Code Key as a Primary Key as the other key is the combination of more than one attribute. Foreign key A foreign key is an attribute or combination of attribute in one base table that points to the candidate key (generally it is the primary key) of another table. The purpose of the foreign key is to ensure referential integrity of the data i.e. only values that are supposed to appear in the database are permitted. E.g. of Foreign Key Let consider we have another table i.e. Department Table with Attributes Department_ID, Department_Name, Manager_ID, Location_ID with Department_ID as an Primary Key. Now the Department_ID attribute of Employee Table (dependent or child table) can be defined as the Foreign Key as it can reference to the Department_ID attribute of the Departments table (the referenced or parent table), a Foreign Key value must match an existing value in the parent table or be NULL.

Composite key - If we use multiple attributes to create a Primary Key then that Primary Key is called Composite Key (also called a Compound Key or Concatenated Key). E.g. of Composite Key, if we have used Name, Address as a Primary Key then it will be our Composite Key. Note : A composite key is combination of columns.

Alternate key - can be any of the Candidate Keys except for the Primary Key. E.g. of Alternate Key is Name, Address as it is the only other Candidate Key which is not a Primary Key. Secondary key -The attributes that are not even the Super Key but can be still used for identification of records (not unique) are known as Secondary Key. E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can identify the records but they might not be unique.

Normalization : The process of refining a database design to ensure that each independent piece of information is in only one place (except for foreign keys) is known as normalization . In the example, choosing fname /lname as the primary key would be referred to as a natural key , whereas the choice of cust_id would be referred to as a surrogate key . The decision whether to employ natural or surrogate keys is a topic of widespread debate, but in this particular case the choice is clear, since a person's last name may change (such as when a person adopts a spouse's last name), and primary key columns should never be allowed to change once a value has been assigned.

SQL Statement Classes :

1)

SQL schema statements (DDL :Data definition language)

CREATE - to create objects in the database ALTER - alters the structure of the database DROP - delete objects from the database TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed COMMENT - add comments to the data dictionary RENAME - rename an object Note :All database elements created via SQL schema statements are stored in a special set of tables called the data dictionary

2)

SQL data statements(DML:data manipulating language)

SELECT - retrieve data from the a database INSERT - insert data into a table UPDATE - updates existing data within a table DELETE - deletes all records from a table, the space for the records remain MERGE - UPSERT operation (insert or update) CALL - call a PL/SQL or Java subprogram EXPLAIN PLAN - explain access path to data LOCK TABLE - control concurrency

3)

SQL transaction statements(TCL :Transaction Control Language)

COMMIT - save work done SAVEPOINT - identify a point in a transaction to which you can later roll back ROLLBACK - restore database to original since the last COMMIT SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use Note : not specifically specified DCL(data control language) GRANT - gives user's access privileges to database REVOKE - withdraw access privileges given with the GRANT command What is the difference between procedural and nonprocedural language? Procedural languages are used in the traditional programming that is based on algorithms or a logical step-by-step process for solving a problem. A procedural programming language provides a programmer a means to define precisely each step in the performance of a task Non-procedural programming languages allow users and professional programmers to specify the results they want without specifying how to solve the problem. Procedural language determines WHAT & HOW a process should be done, Non-procedural language is concerned with the WHAT not the HOW. Examples of Procedural Language : Assembler, Fortran, Cobol, C,java Examples of Non-Procedural Language :database manipulations like SQL, Visual Basic

Print Current Date :

1)

SELECT now();

2)With some database servers, you won't be able to issue a query without a from

clause that names at least one table. Oracle Database is a commonly used server for which this is true. For cases when you only need to call a function, Oracle provides a table called dual, which consists of a single column called dummy that contains a single row of data. In order to be compatible with Oracle Database, MySQL also provides a dual table. The previous query to determine the current date and time could therefore be written as:
SELECT now() FROM dual;

MYSQL Data Types : Character Data Type :


Character data can be stored as either fixed-length or variable-length strings; the difference is that fixed-length strings are right-padded with spaces and always consume the same number of bytes, and variable-length strings are not right-padded with spaces and don't always consume the same number of bytes. When defining a character column, you must specify the maximum size of any string to be stored in the column. For example, if you want to store strings up to 20 characters in length, you could use either of the following definitions: char(20) /* fixed-length */ varchar(20) /* variable-length */ The maximum length for char columns is currently 255 bytes, whereas varchar columns can be up to 65,535 bytes. If you need to store longer strings (such as emails, XML documents, etc.), then you will want to use one of the text types (mediumtext and longtext),

NOTE :
1) Oracle Database is an exception when it comes to the use of varchar. Oracle users should use the varchar2 type when defining variable-length character columns.

2) Text data

: If you need to store data that might exceed the 64 KB limit for varchar columns, you will need to use one of the text types. Text type Tinytext Text Mediumtext Longtext : : : : Maximum number of bytes 255 65,535 16,777,215 4,294,967,295

3) NOTE : Oracle Database allows up to 2,000 bytes for char columns and 4,000 bytes for varchar2 columns. SQL Server can handle up to 8,000 bytes for both char and varchar data.

Numeric Data :

1) For Integer :

2)

For Float :

When using a floating-point type, you can specify a precision (the total number of allowable digits both to the left and to the right of the decimal point) and a scale (the number of allowable digits to the right of the decimal point), but they are not required. These values are represented in Table 2-4 as p and s. If you specify a precision and scale for your floating-point column, remember that the data stored in the column will be rounded if the number of digits exceeds the scale and/or precision of the column. For example, a column defined as float(4,2) will store a total of four digits, two to the left of the decimal and two to the right of the decimal. Therefore, such a column would handle the numbers 27.44 and 8.19 just fine, but the number 17.8675 would be rounded to 17.87, and attempting to store the number 178.375 in your float(4,2) column would generate an error. Note :Like the integer types, floating-point columns can be defined as unsigned, but this designation only prevents negative numbers from being stored in the column rather than altering the range of data that may be stored in the column.

3)

Temporal Data : Storing date and Time is referred as temporal data.

Note :A column that tracks when a user last modified a particular row in a table would use the timestamp type. The timestamp type holds the same information as the datetime type (year, month, day, hour, minute, second), but a timestamp column will automatically be populated with the current date/time by the MySQL server when a row is added to a table or when a row is later modified.

Table Creation : In the below table person we have a char for gender which stores only one character.

After Adding the constraint in gender the create table command looks like

CREATE TABLE person (person_id SMALLINT UNSIGNED, fname VARCHAR(20), lname VARCHAR(20), gender ENUM('M','F'), birth_date DATE, street VARCHAR(30), city VARCHAR(20), state VARCHAR(20), country VARCHAR(20), postal_code VARCHAR(20), CONSTRAINT pk_person PRIMARY KEY (person_id) ); To view all tables : mysql> SHOW TABLES To view the Table use the mysql command as DESC person;

Favorite Food Table :

Auto Increment Values of primary key in person table i.e person id is : sql) ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT; ----> The auto increment is show in the extra column in below table

Insert Command : Inserting value in person table : mysql> INSERT INTO person -> (person_id, fname, lname, gender, birth_date) -> VALUES (null, 'William','Turner', 'M', '1972-05-27'); Query OK, 1 row affected (0.01 sec) To view the saved data :

Inserting value in favorite_food table :

To view the saved data with order :

Update Command : In the above insert we have not added the address details related to person_id 1.In the update

command we provide his address details mysql> UPDATE person SET street = '1225 Tremont St.', city = 'Boston',state = 'MA', country = 'USA', postal_code = '02138' WHERE person_id = 1; Depending on the conditions in your where clause, it is also possible to modify more than one row using a single statement. Consider, for example, what would happen if your where clause looked as follows: WHERE person_id < 10

Delete Command : mysql:> delete from person where person_id=1; Just similar to update we can delete more than one column mysql:> delete from person where person_id<10; Drop Command : mysql> DROP TABLE favorite_food;

Invalid Date Conversions :


If you construct a string with which to populate a date column, and that string does not match the expected format, you will receive error. mysql> UPDATE person SET birth_date = 'DEC-21-1980' WHERE person_id = 1; ERROR 1292 (22007): Incorrect date value: 'DEC-21-1980' for column 'birth_date' at row 1 In general, it is always a good idea to explicitly specify the format string rather than relying on the default format. Here's another version of the statement that uses the str_to_date function to specify which format string to use:

mysql> UPDATE person SET birth_date = str_to_date('DEC-211980' , '%b-%d-%Y') WHERE person_id = 1;

Arithmetic Operators :

Operator Priority :

SELECT OrderID, ProductID,UnitPrice*Quantity AS "Regular Price",UnitPrice*Quantity-UnitPrice*Quantity*Discount AS "Price After Discount" FROM order_details;

Modulo division : SELECT UnitsInStock, UnitsInStock%3 AS "Modulo by 3" FROM products;

Division : SELECT 11 DIV 4; Result : 2 SELECT 11.5 DIV 4; Result : 3 Uniary Minus : SELECT -2*-3; Result :6

Steps Followed in Executing Queries :


First establish the connection. Once the server has verified your user name and password and issued you a connection, you are ready to execute queries (along with other SQL statements). Each time

a query is sent to the server, the server checks the following things prior to statement execution: ->Do you have permission to execute the statement? ->Do you have permission to access the desired data? ->Is your statement syntax correct? If your statement passes these three tests, then your query is handed to the query optimizer,whose job it is to determine the most efficient way to execute your query. The optimizer will look at such things as the order in which to join the tables named in your from clause and what indexes are available, and then picks an execution plan, which the server uses to execute your query. Once the server has finished executing your query, the result set is returned to the calling application. Result set is just another table containing rows and columns

Column Aliases : mysql> SELECT emp_id, 'ACTIVE' status, emp_id * 3.14159 empid_x_pi,UPPER(lname) last_name_upper FROM employee; +--------+--------+------------+-----------------+ |emp_id | status | empid_x_pi | last_name_upper | +--------+--------+------------+-----------------+ | 1 | ACTIVE | 3.14159 | SMITH | | 2 | ACTIVE | 6.28318 | BARKER | | 3 | ACTIVE | 9.42477 | TYLER | | 4 | ACTIVE | 12.56636 | HAWTHORNE | | 5 | ACTIVE | 15.70795 | GOODING | | 6 | ACTIVE | 18.84954 | FLEMING | | 7 | ACTIVE | 21.99113 | TUCKER | | 8 | ACTIVE | 25.13272 | PARKER | | 9 | ACTIVE | 28.27431 | GROSSMAN | | 10 | ACTIVE | 31.41590 | ROBERTS | | 11 | ACTIVE | 34.55749 | ZIEGLER | | 12 | ACTIVE | 37.69908 | JAMESON | | 13 | ACTIVE | 40.84067 | BLAKE | | 14 | ACTIVE | 43.98226 | MASON | | 15 | ACTIVE | 47.12385 | PORTMAN |

| 16 | ACTIVE | 50.26544 | MARKHAM | | 17 | ACTIVE | 53.40703 | FOWLER | | 18 | ACTIVE | 56.54862 | TULMAN | The above query can be written with AS keyword

mysql> SELECT emp_id,'ACTIVE' AS status,emp_id * 3.14159 AS


empid_x_pi,UPPER(lname) AS last_name_upper FROM employee;

Distinct Keyword : This keyword is used to remove


duplicate values and displays unique value.

All Keyword : If we are sure that there is no duplicate


values present we can use all keyword. Its keyword and need not be named explicitly. a default

Views : A view is a query that is stored in the data dictionary. It


looks and acts like a table, but there is no data associated with a view (this is why I call it a virtual table). The basic CREATE VIEW syntax is as follows: CREATE VIEW view_name AS SELECT column1, column2..... FROM table_name WHERE [condition]; Example: Consider CUSTOMERS table is having following records: +----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 |

| 7 | Muffy

| 24 | Indore

| 10000.00 |

Now, following is the example to create a view from CUSTOMERS table. This view would be used to have customer name and age from CUSTOMERS table: SQL > CREATE VIEW CUSTOMERS_VIEW AS SELECT name, age FROM CUSTOMERS; Now you can query CUSTOMERS_VIEW in similar way as you query an actual table. Following is the example: SQL > SELECT * FROM CUSTOMERS_VIEW; This would produce following result: +----------+-----+ | name | age | +----------+-----+ | Ramesh | 32 | | Khilan | 25 | | kaushik | 23 | | Chaitali | 25 | | Hardik | 27 | | Komal | 22 | | Muffy | 24 | +----------+-----+ The WITH CHECK OPTION: The WITH CHECK OPTION is a CREATE VIEW statement option. The purpose of the WITH CHECK OPTION is to ensure that all UPDATE and INSERTs satisfy the condition(s) in the view definition. If they do not satisfy the condition(s), the UPDATE or INSERT returns an error. The following is an example of creating same view CUSTOMERS_VIEW with the WITH CHECK OPTION:

CREATE VIEW CUSTOMERS_VIEW AS SELECT name, age FROM CUSTOMERS WHERE age IS NOT NULL WITH CHECK OPTION; The WITH CHECK OPTION in this case should deny the entry of any NULL values in the view's AGE column, because the view is defined by data that does not have a NULL value in the AGE column. Updating a View : A view can be updated under certain conditions: The SELECT clause may not contain the keyword DISTINCT. The SELECT clause may not contain summary functions. The SELECT clause may not contain set functions. The SELECT clause may not contain set operators. The SELECT clause may not contain an ORDER BY clause. The FROM clause may not contain multiple tables. The WHERE clause may not contain subqueries. The query may not contain GROUP BY or HAVING. Calculated columns may not be updated. All NOT NULL columns from the base table must be included in the view in order for the INSERT query to function. So if a view satisties all the above mentioned rules then you can update a view. Following is an example to update the age of Ramesh: SQL > UPDATE CUSTOMERS_VIEW SET AGE = 35

WHERE name='Ramesh'; This would ultimately update the base table CUSTOMERS and same would reflect in the view itself. Now try to query base table, and SELECT statement would produce following result: +----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 35 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 | | 7 | Muffy | 24 | Indore | 10000.00 | +----+----------+-----+-----------+----------+

Another way to update a view is : CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table WHERE predicates;

Inserting Rows into a View: Rows of data can be inserted into a view. The same rules that apply to the UPDATE command also apply to the INSERT command. Here we can not insert rows in CUSTOMERS_VIEW because we have not included all the NOT NULL columns in this view, otherwise you can insert rows in a view in similar way as you insert them in a table. Deleting Rows into a View: Rows of data can be deleted from a view. The same rules that apply to the UPDATE and INSERT commands apply to the DELETE command. Following is an example to delete a record having AGE= 22.

SQL > DELETE FROM CUSTOMERS_VIEW WHERE age = 22; This would ultimately delete a row from the base table CUSTOMERS and same would reflect in the view itself. Now try to query base table, and SELECT statement would produce following result: +----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 35 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 7 | Muffy | 24 | Indore | 10000.00 |

Dropping Views: Obviously, where you have a view, you need a way to drop the view if it is no longer needed. The syntax is very simple as given below: DROP VIEW view_name; Following is an example to drop CUSTOMERS_VIEW from CUSTOMERS table: DROP VIEW CUSTOMERS_VIEW; Order By : used to retrieve data in a specific order. Ascending order is the default. In order to get the data in descending order we use desc keyword and to display in ascending we can use asc mysql> SELECT cust_id, cust_type_cd, city, state, fed_id FROM customer ORDER BY RIGHT(fed_id, 3);

+---------+--------------+------------+------+-------------+ | cust_id | cust_type_cd | city | state | fed_id | +---------+--------------+------------+------+-------------+ | 1 | I | Lynnfield | MA | 111-11-1111 | | 10 | B | Salem | NH | 04-1111111 | | 2 | I | Woburn | MA | 222-22-2222 | | 11 | B | Wilmington | MA | 04-2222222 | | 3 | I | Quincy | MA | 333-33-3333 | | 12 | B | Salem | NH | 04-3333333 | | 13 | B | Quincy | MA | 04-4444444 | | 4 | I | Waltham | MA | 444-44-4444 | | 5 | I | Salem | NH | 555-55-5555 | | 6 | I | Waltham | MA | 666-66-6666 | | 7 | I | Wilmington | MA | 777-77-7777 | | 8 | I | Salem | NH | 888-88-8888 | | 9 | I | Newton | MA | 999-99-9999 | +---------+--------------+------------+------+-------------+ 13 rows in set (0.24 sec) This query uses the built-in function right() to extract the last three characters of the fed_id column and then sorts the rows based on this value. Sorting with column place : If you are sorting using the columns in your select clause, you can opt to reference the columns by their position in the select clause rather than by name. For example, if you want to sort using the second and fifth columns returned by a query, you could do the following: mysql> SELECT emp_id, title, start_date, fname, lname FROM employee ORDER BY 2, 5;
| emp_id | title | start_date | fname | lname | +--------+--------------------+------------+----------+-----------+ | 13 | Head Teller | 2004-05-11 | John | Blake | | 6 | Head Teller | 2008-03-17 | Helen | Fleming | | 16 | Head Teller | 2005-03-15 | Theresa | Markham | | 10 | Head Teller | 2006-07-27 | Paula | Roberts | | 5 | Loan Manager | 2007-11-14 | John | Gooding | | 4 | Operations Manager | 2006-04-24 | Susan | Hawthorne |

| 1 | President | 2005-06-22 | Michael | Smith | | 17 | Teller | 2006-06-29 | Beth | Fowler | | 9 | Teller | 2006-05-03 | Jane | Grossman |

Usage Of NOT Operator : WHERE end_date IS NULL AND NOT (title = 'Teller' OR start_date < '2007-01-01')

OR
WHERE end_date IS NULL AND title != 'Teller' AND start_date >= '2007-01-01'

S-ar putea să vă placă și