Download presentation
Presentation is loading. Please wait.
1
A Change of Topic Chapter 1 Chapter 2
2
Basic concepts Attributes and Domains
Student Roll_No Name Per Rank 1 Shreyas 72 4 2 Prathamesh 85 17 Jaya 65 7 19 Anirudha 78 3 56 Durva 95
3
Definition of table Any relation is subset of all possible rows.
D1xD2xD3xD4x……….xDn-1 x Dn. A relation is a set of n tuples(a1,a2,……an ) Where each ai€Di
4
Consider customer relation
Cust_Name={Ashish,Akshay,Priyanka,Jay} Cust_Street={Main,Camp,Park} Cust_City={Nasik,Pune,Mumbai} Then relation r={(Ashish,Main,Nasik), (Akshay,Camp,Mumbai), (Priyanka,Park,Mumbai), (Jay,Park,Pune)}
5
Database schema & instances
Schema Definition Student_Schema={rollno,name,per,rank} We can denote student relation on student schema such as, Let D1,D2,…Dn are attri. Let A1,A2…..An are the records R=(D1,D2,….Dn) is a relation schema Where An€Dn
6
Student Schema Student Columns/Attributes Roll No Name Percentage 1 2
3 4 5 Rahul Priya Spruha Tejas Ram 69 61 46 88 75 Rows /Tuples Instances
7
Codds Rules: Information Rule:
All information in a relational database including table names, column names is represented in the form of tables. This simple view of data speeds up design and learning process. 2. Guaranteed Access Rule : Whole data should be available or accessible to the user without any ambiguity. Ambiguity can be avoided only through perfect combination of table name,primary key, and column. 3.Systematic treatment of null values. Absence of values should be treated properly.
8
4.Dynamic on-Line catalog based on the relational model(Database Description Rule ).
The description of a database is stored and maintained in the form of tables . This implies that a data dictionary should be present within the RDBMS. 5.Comprehensive Data Sub-language Rule Database needs to support minimum one clearly defined language This language should be capable of handling DML,DDL,DCL,data integrity, Eg.SQL 6.View Updating Rule changes made in the view are transmitted to the base table and vice-versa.
9
7.High Level Insert, Update and Delete
The RDBMS supports insertion, updating and deletion at a table level. 8. Physical Data Independence 9. Logical Data Independence 10.Integrity Independence 11. Non subversion Rule: There should not exist a way to modify or change the database structure except database languages. 12. Distribution Independence RDBMS package must makes it possible for the database to be distributed across multiple computers even though they are having heterogeneous platforms both for h/w and operating system. Database systems built on the relational framework are well suited for today's Client/Server database design.
10
BasicConcepts Attributes and Domains
A Change of Topic BasicConcepts Attributes and Domains Key Concepts
11
Key Concepts The word key is referred to the attribute of the relation. Kay is used to avoid duplication in the relations.
12
Super key Is any combination of column(s) for which that combination of values will be unique across all rows in a table. Ex. The table has columns called Manager{ManagerID, Name, Title, and DepartmentID}. Every manager has his/her own ManagerID, so that value is always unique in each and every row. This means that if we combine the ManagerID column value for any given row with any other column value, then we will have a unique set of values.
13
Possible combinations are
(ManagerID, Name), (ManagerID, Title), (ManagerID, DepartmentID), (ManagerID, Name, DepartmentID) If you add any other column/attribute to a Primary Key then it become a super key.
14
Candidate Key Candidate keys are actually minimal super keys – so both candidate keys and minimal super keys mean exactly the same thing.
15
Primary Key It’s a unique attribute of a database files which allows storing only unique values. Primary key values are never null. Ex. Consider the following Relation Manager Manager{ManagerID, Name, Title, and DepartmentID}.
16
Foreign Key Foreign key is a primary key of another table. Ex.
Customer{Cust_id,loan_id,name,street} Loan{loan_id,branch_name,amount}
17
A Change of Topic Key Concepts Normalization
18
Normalization Process of decomposition of database tables to avoid redundancy. It’s a database design technique by which relational database tables are structured so that to make user friendly. Its remove inconsistencies and anomalies from database. Tables can be normalized to varying degrees: 1st ,2nd ,3rd ,BCNF forms.
19
Purpose of normalization
Remove repetition. Remove inconsistency. Is adding and deleting new activity possible? Updating Roll NO Name Div Activity Code Activity Fees 1 Yogesh A A1 Drawing 200 2 Prathamesh A2 Swimming 350 3 Durva B 4 Atharva 5 Prachi C A3 Craft 100
20
Anomalies INSERT ANOMALY: This refers to the situation when it is impossible to insert certain types of data into the database. DELETE ANOMALY: The deletion of data leads to unintended loss of additional data, data that we had wished to preserve. UPDATE ANOMALY: This refers to the situation where updating the value of a column leads to database inconsistencies (i.e., different rows on the table have different values).
21
Normalization is the process of splitting table into different parts so that we can avoid redundancy and anomalies. Roll No Name Division 1 Yogesh A 2 Prathamesh 3 Durva B 4 Atharva 5 Prachi C Activity Code Activity Fees A1 Drawing 200 A2 Swimming 350 A3 Craft 100 Roll No Activity Code 1 A1 2 A2 3 4 5 A3
22
Functional dependencies
Can be defined as column Y of the relation R are said to be functionally dependent upon column X of relation R if and only if each value of X in R is associated with exactly one value of Y at any given time. Short hand: R.x - > R.y
23
Defination The attributes of a table is said to be dependent on each other when an attribute of a table uniquely identifies another attribute of the same table. Student(rollno,name,per) Rollno->name in words we can say Name is functionally dependent on rollno.
24
First Normal Form A database is in first normal form if it satisfies the following conditions: Contains only atomic values There are no repeating groups An atomic value is a value that cannot be divided. A repeating group means that a table contains two or more columns that are closely related.
25
1st Normal Form Example This table is not in first normal form because the [Color] column can contain multiple values. For example, the first row includes values "red" and "green." To bring this table to first normal form, we split the table into two tables and now we have the resulting tables:
26
Result Now first normal form is satisfied, as the columns on each table all hold just one value.
27
2nd Normal Form Definition
A database is in second normal form if it satisfies the following conditions: It is in first normal form All non-key attributes are fully functional dependent on the primary key In a table, if attribute B is functionally dependent on A, but is not functionally dependent on a proper subset of A, then B is considered fully functional dependent on A. Hence, in a 2NF table, all non-key attributes cannot be dependent on a subset of the primary key.
28
Example A table that is in 1st normal form and contains only a single key as the primary key is automatically in 2nd normal form. This table has a composite primary key [Customer ID, Store ID]. The non-key attribute is [Purchase Location]. In this case, [Purchase Location] only depends on [Store ID], which is only part of the primary key. Therefore, this table does not satisfy second normal form.
29
To bring this table to second normal form, we break the table into two tables, and now we have the following: What we have done is to remove the partial functional dependency that we initially had. Now, in the table [TABLE_STORE], the column [Purchase Location] is fully dependent on the primary key of that table, which is [Store ID].
30
3rd Normal Form Definition
A database is in third normal form if it satisfies the following conditions: It is in second normal form There is no transitive functional dependency By transitive functional dependency, we mean we have the following relationships in the table: A is functionally dependent on B, and B is functionally dependent on C. In this case, C is transitively dependent on A via B.
31
3rd Normal Form Example In the table, [Book ID] determines [Genre ID], and [Genre ID] determines [Genre Type]. Therefore, [Book ID] determines [Genre Type] via [Genre ID] and we have transitive functional dependency, and this structure does not satisfy third normal form.
32
To bring this table to third normal form, we split the table into two as follows:
Now all non-key attributes are fully functional dependent only on the primary key. In [TABLE_BOOK], both [Genre ID] and [Price] are only dependent on [Book ID]. In [TABLE_GENRE], [Genre Type] is only dependent on [Genre ID].
33
Boyce and Codd Normal Form (BCNF)
For a table to be in BCNF, following conditions must be satisfied: R must be in 3rd Normal Form and, for each functional dependency ( X -> Y ), X should be a super Key.
34
Example: Suppose there is a company wherein employees work in more than one department. They store the data like this: emp_id emp_nationality emp_dept dept_type dept_no_of_emp 1001 Austrian Production and planning D001 200 stores 250 1002 American design and technical support D134 100 Purchasing department 600 Functional dependencies in the table above: emp_id -> emp_nationality emp_dept -> {dept_type, dept_no_of_emp} Candidate key: {emp_id, emp_dept}
35
To make the table comply with BCNF we can break the table in three tables like this:
emp_nationality table: emp_dept_mapping table: emp_id emp_nationality 1001 Austrian 1002 American emp_id emp_dept 1001 Production and planning stores 1002 design and technical support Purchasing department emp_dept table: emp_dept dept_type dept_no_of_emp Production and planning D001 200 stores 250 design and technical support D134 100 Purchasing department 600 Functional dependencies: emp_id -> emp_nationality emp_dept -> {dept_type, dept_no_of_emp} Candidate keys: For first table: emp_id For second table: emp_dept For third table: {emp_id, emp_dept}
36
A Change of Topic Normalization Intro to SQL
37
Database Languages. 1) data definition Languages.(DDL)
2) data manipulation Language.(DML) 3) data control language.(DCL)
38
Data definition Language.
It is used to define the basic structure of database. With this user can define the integrity constraints. Commands of DDL : 1)Create. 2)Alter 3)Drop 4)Truncate. 5)DESC 6)Rename. 7)Creating user. 8) Use of integrity constraints.
39
Create The SQL CREATE TABLE statement is used to create a new table.
Syntax: CREATE TABLE table_name ( column1 datatype (size) , column2 datatype (size), column3 datatype (size), ..... columnN datatype (size), PRIMARY KEY( one or more columns ) );
40
Example SQL> CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
41
ALTER The SQL ALTER TABLE command is used to add, delete or modify columns in an existing table. You should also use the ALTER TABLE command to add and drop various constraints on an existing table.
42
Syntax to add new column using alter
ALTER TABLE table_name ADD column_name datatype; Ex: ALTER TABLE student ADD grade varchar2(10);
43
Syntax to drop column using alter
ALTER TABLE table_name DROP COLUMN column_name; Example: ALTER TABLE student DROP COLUMN grade;
44
Syntax to change datatype of column using alter
ALTER TABLE table_name MODIFY COLUMN column_name datatype; Example: ALTER TABLE student MODIFY COLUMN per number(10,2);
45
Drop table The SQL DROP TABLE statement is used to remove a table definition and all the data, indexes, triggers, constraints and permission specifications for that table. Syntax: DROP TABLE table_name; Example: DROP TABLE student;
46
truncate The SQL TRUNCATE TABLE statement is used to remove all records from a table. It performs the same function as a DELETE statement without a WHERE clause. Warning: If you truncate a table, the TRUNCATE TABLE statement can not be rolled back in some databases. Syntax: TRUNCATE TABLE table_name; TRUNCATE TABLE student;
47
Desc Desc command is used to describe the structure of existing table.
Synatx: desc <table name>; desc student;
48
Rename SQL RENAME TABLE syntax is used to change the name of a table. Sometimes, we choose non-meaningful name for the table. So it is required to be changed. Syntax: RENAME old_table _name To new_table_name; Example: RENAME student To student1;
49
Creating user Create user command is used to create new user in database Syntax: CREATE USER username IDENTIFIED BY password Where, username is new user name password is user password CREATE USER compuser IDENTIFIED BY comp1234
50
Data manipulation Languages.
Data manipulation language is used to manipulate data i.e. do operation on data. 1) Insert: 2)Update: 3)Delete. 4) call.
51
insert The SQL INSERT INTO Statement is used to add new rows of data to a table in the database. Syntax: INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN); Example: INSERT INTO CUSTOMERS (ID,NAME,AGE, ADDRESS,SALARY) VALUES (1, 'Ramesh', 32, 'Ahmedabad', );
52
update The SQL UPDATE Query is used to modify the existing records in a table. You can use the WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows would be affected. Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ...., columnN = valueN WHERE [condition]; You can combine N number of conditions using the AND or the OR operators.
53
delete The SQL DELETE Query is used to delete the existing records from a table. You can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted. Synatx: DELETE FROM table_name WHERE [condition];
54
call Use the CALL statement to execute a routine (a standalone procedure or function, or a procedure or function defined within a type or package) from within SQL. Syntax: {call procedure_name( )}
55
A Change of Topic Intro to SQL Data Types In SQL
56
Data Types in SQL Characters: Numbers: Times and dates:
CHAR(20) -- fixed length VARCHAR(40) -- variable length Numbers: BIGINT, INT, SMALLINT, TINYINT REAL, FLOAT -- differ in precision MONEY Times and dates: DATE DATETIME -- SQL Server Others... All are simple
57
Data-type Syntax Explanation Integer INTEGER The integer data type is used to specify an integer value. Smallint SMALLINT The smallint data type is used to specify small integer value. Numeric NUMERIC(P,S) It specifies a numeric value. Here 'p' is precision value and 's' is scale value. Real REAL The real integer is used to specify a single precision floating point number. Decimal DECIMAL(P,S) It specifies a decimal value. Here 'p' is precision value and 's' is scale value. Double precision DOUBLE PRECISION It specifies double precision floating point number. Float FLOAT(P) It specifies floating-point value e.g. 12.3, 4.5 etc. Here, 'p' is precision value. Character CHAR(X) Here, 'x' is the character's number to store.
58
Character varying VARCHAR2(X) Here, 'x' is the character's number to store Bit BIT(X) Here, 'x' is the number of bits to store Bit varying BIT VARYING(X) Here, 'x' is the number of bits to store (length can vary up to x). Date DATE It stores year, month and days values. Time TIME It stores hour, minute and second values Timestamp TIMESTAMP The timestamp data type is used to store year, month, day, hour, minute and second values. Time with time zone TIME WITH TIME ZONE It is exactly same as time but also store an offset from UTC of the time specified. Timestamp with time zone TIMESTAMP with TIME ZONE It is same as timestamp but also stores an offset from UTC of the time specified.
59
A Change of Topic Data Types In SQL Data Integrity Constraints
60
Integrity Constraints
Completeness or correctness of data. RDBMS. Modification of data-Insert ,Update ,Delete. Why integrity breaks- Invalid data entered in database. Changes made in DB get lost due to any failure. Existing data may get modified to the wrong value. If transaction aborted then DB will partially updated. Parent Records may deleted through its child exists.
61
Integrity Constraints…
Constraints are nothing but restrictions. Types- I/O constraints: Primary key constraints Referential key integrity constraints Unique key constraints Business rule constraints: Null Not Null Check constraints
62
Primary key integrity constraints
The entity integrity rule is designed to assure that every relation have a primary key. Primary key should non repeating and not null Ex: Fax no is optional
63
Create Primary Key At the time of table creation: Here is the syntax to define the ID attribute as a primary key in a CUSTOMERS table. CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
64
ADD CONSTRAINT PK_CUSTID PRIMARY KEY (ID);
To create a PRIMARY KEY constraint on the "ID" column when the CUSTOMERS table already exists, use the following SQL syntax − ALTER TABLE CUSTOMER ADD PRIMARY KEY (ID); OR ALTER TABLE CUSTOMERS ADD CONSTRAINT PK_CUSTID PRIMARY KEY (ID);
65
Referential Integrity constraint and on delete cascade
Foreign key Referenced table-Parent table Table with foreign key-child table. On delete cascade- When record present in parent table is deleted, then corresponding record in the child table will be automatically deleted.
66
Example create table emp_details( empno numeric(4) primary key, deptno numeric(2)constraint dept_fk references dept(deptno), cellno numeric(10) constraint cell_unq unique, grosspay numeric(10) constraint check_pay check(grosspay>12000));
67
Check Integrity constraint
These constraints are created using CREATE ASSERTION statement. CREATE ASSERTION name CHECK (conditional expression) Ex: CREATE ASSERTION ICSAL CHECK(SELECT MIN(SALARY) FROM EMPLOYEE<50000)
68
Domain Integrity Constraint
Used to define the characteristics of column. To allow only valid values in the table ,the domain integrity constraints are used. Ex. I want to create a table “bank_account” with “account_type” field having value either “checking” or “saving”:
69
create domain account_type char(12) constraint acc_type_test
check(value in ("Checking", "Saving")); create table bank_account ( account_nbr int PRIMARY KEY, account_holder_name varchar(30), account_type account_type );
70
UNIQUE Constraint The UNIQUE Constraint prevents two records from having identical values in a column. In the CUSTOMERS table, for example, you might want to prevent two or more people from having an identical age.
71
During table creation CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL UNIQUE, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
72
If table is already exist
ALTER TABLE CUSTOMERS MODIFY AGE INT NOT NULL UNIQUE; OR ALTER TABLE CUSTOMERS ADD CONSTRAINT myUniqueConstraint UNIQUE(AGE, SALARY);
73
Business rule constraints-Not Null
By default, a column can hold NULL values. If you do not want a column to have a NULL value, then you need to define such a constraint on this column specifying that NULL is now not allowed for that column. A NULL is not the same as no data, rather, it represents unknown data.
74
Syntax-At the time of table creation
CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
75
If table has already been created
ALTER TABLE CUSTOMERS MODIFY SALARY DECIMAL (18, 2) NOT NULL;
76
Check constraint The CHECK Constraint enables a condition to check the value being entered into a record. If the condition evaluates to false, the record violates the constraint and isn't entered the table.
77
At the time of table creation
CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL CHECK (AGE >= 18), ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
78
After table creation ALTER TABLE CUSTOMERS MODIFY AGE
INT NOT NULL CHECK (AGE>=18); OR ADD CONSTRAINT AgeCheck CHECK(AGE >= 18);
79
Data manipulation Languages.
Data manipulation language is used to manipulate data i.e. do operation on data. 1) Insert: 2)Update: 3)Delete. 4) call.
80
A Change of Topic DML DCL
81
Data Control Language(DCL)
DCL are used to facilitate users to use privilege commands. Creators or owners of database objects have a complete authority over them. Database objects may be table, views etc. DCL commands 1) Grant 2) Revoke. 3) commit 4) Savepoint 5) Rollback.
82
Data authorization Authorization is the process of allowing the different privileges to the users to access ,add ,modify or delete the data. -Access or read the data Insert new data Update data Delete data Sql standard previllages-select ,insert ,update ,delet and all.
83
Grant command To grant the privileges Syntax:
Grant<privillege_list> on <relation_name> To <user/role_list> Ex: Grant select on employee to user1,user2… grant update(amount) on loan to user1 grant insert on loan to public
84
Revoke command To cancel the granted privileges. Syntax:
Revoke<privillage_list> on <relation_name> From<user/role_list> Ex: Revoke select on employee from user1,user2..
85
Commit COMMIT command is used to permanently save any transaction into the database. When we use any DML command like INSERT, UPDATE or DELETE, the changes made by these commands are not permanent, until the current session is closed, the changes made by these commands can be rolled back. To avoid that, we use the COMMIT command to mark the changes as permanent. Syntax: COMMIT;
86
SAVEPOINT command SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever required. Syntax: SAVEPOINT savepoint_name; In short, using this command we can name the different states of our data in any table and then rollback to that state using the ROLLBACK command whenever required.
87
ROLLBACK command This command restores the database to last commited state. It is also used with SAVEPOINT command to jump to a savepoint in an ongoing transaction. If we have used the UPDATE command to make some changes into the database, and realise that those changes were not required, then we can use the ROLLBACK command to rollback those changes, if they were not commited using the COMMIT command.
88
Syntax: Rollback ROLLBACK TO savepoint_name;
89
DQL Commands The commands of SQL that are used to retrieve data from the database are collectively called as DQL. So all Select statements comes under DQL.
90
Syntax: Select command
SELECT column_name1, column_name2, column_name3, ... , column_nameN FROM table_name; Or Select * from table_name
91
A Change of Topic DCL and DQL SQL Operators
92
SQL operators To operate values or numbers then operators are used.
Types: Arithmetic Operators Comparison Operators Logical operators Set operators Range searching operators: Between Pattern matching operators -like
93
Arithmetic Operators Ex: Select ename,salary + comm from employee;
SrNo. Operator Meaning 1 + Addition 2 - Subtraction 3 * Multiplication 4 / Division Ex: Select ename,salary + comm from employee;
94
Comparison Operators Mainly used to compare two values. Sr.No Operator
Meaning 1 = Is equal to 2 != Not equal to 3 < Less than 4 > Greater than 5 <> 6 <= Less than or equal to 7 >= Greater than or equal to 8 Between Between two values 9 In In the list 10 Like Simillar to value 11 Null Is null
95
Example Select empno,ename,deptno From employee where deptno!=2;
96
Logical Operators Mainly used to evaluate an expression that depends upon specific condition. Ex: select * fro employee Where salary>1500 AND comm>5000; Sr.No. Operator Meaning 1 AND Logical AND 2 OR Logical OR 3 NOT Logical NOT
97
Set operators These are the special operators which combines the result of two quries. Union Union all Intersect Minus
98
Union operator Returns all distinct rows selected by both quries. Ex;
SELECT * FROM First UNION SELECT * FROM Second;
99
Examples SELECT * FROM First UNION SELECT * FROM Second;
The First table, ID Name 1 abhi 2 adam SELECT * FROM First UNION SELECT * FROM Second; The Second table, ID Name 2 adam 3 Chester The resultset table will look like, ID NAME 1 abhi 2 adam 3 Chester
100
Union all It combines all records from both the quries.
It does not avoid the duplications. Ex; Select deptno from employee union all Select deptno from department;
101
Example SELECT * FROM First UNION ALL SELECT * FROM Second;
The First table, SELECT * FROM First UNION ALL SELECT * FROM Second; ID NAME 1 abhi 2 adam The resultset table will look like, The Second table, ID NAME 1 abhi 2 adam 3 Chester ID NAME 2 adam 3 Chester
102
INTERSECT Intersect operation is used to combine two SELECT statements, but it only retuns the records which are common from both SELECT statements. In case of Intersect the number of columns and datatype must be same.
103
Example SELECT * FROM First INTERSECT SELECT * FROM Second;
The First table, SELECT * FROM First INTERSECT SELECT * FROM Second; ID NAME 1 abhi 2 adam The Second table, he resultset table will look like ID NAME 2 adam 3 Chester ID NAME 2 adam
104
Minus The Minus operation combines results of two SELECT statements and return only those in the final result, which belongs to the first set of the result.
105
Example SELECT * FROM First MINUS SELECT * FROM Second;
The First table, SELECT * FROM First MINUS SELECT * FROM Second; ID NAME 1 abhi 2 adam The Second table, The resultset table will look like, ID NAME 2 adam 3 Chester ID NAME 1 abhi
106
A Change of Topic Set operators Range searching operators
107
IN Operator The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions. Syntax: SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);
108
Examples SELECT * FROM Customers WHERE Country IN ('Germany', 'France', 'UK'); Country NOT IN ('Germany', 'France', 'UK');
109
Between The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included. Syntax: SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
110
Example SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;
111
A Change of Topic Range searching operators Pattern Matching operators
112
LIKE Operator The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards used in conjunction with the LIKE operator: % - The percent sign represents zero, one, or multiple characters _ - The underscore represents a single character Note: MS Access uses a question mark (?) instead of the underscore (_). The percent sign and the underscore can also be used in combinations!
113
Like syntax: SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern; Example: SELECT * FROM Customers WHERE CustomerName LIKE 'a%';
114
SELECT * FROM Customers WHERE CustomerName LIKE '%a';
SELECT * FROM Customers WHERE CustomerName LIKE '%or%'; SELECT * FROM Customers WHERE CustomerName LIKE '_r%';
115
SELECT * FROM Customers WHERE CustomerName LIKE 'a_%_%';
SELECT * FROM Customers WHERE ContactName LIKE 'a%o'; SELECT * FROM Customers WHERE CustomerName NOT LIKE 'a%';
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.