What is normalization?
In relational database design, the process of organizing data to minimize redundancy. Normalization usually involves dividing a database into two or
more tables and defining relationships between the tables. The major aim of normalization is that reduce the repeated data from the table.
Data redundancy occurs in database systems which have a field that is repeated in two or more tables. For instance, when customer data is duplicated
and attached with each product bought then redundancy of data is a known source of inconsistency, since customer might appear with different values
for given attribute.
Hosp-id
Primary Key
HCity
HAddress
Hos-Name
Pat-id
Hosp-id
Primary Key
Doc-id
Patient
Pat-id
Primary Key
PName
PAddress
PDiagnosis
Record-id
Hosp-id
Medical Record
Record-id
Primary Key
Problem
Date_of_examination
Pat-id
Doctor
Doc-id
DName
Qualification
Salary
Primary Key
Doc-id
Primary Key
Hosp-id
Simple Attributes
Simple attributes which cannot be divided into subparts.
Example: Salary of Doctor
Composite Attributes
Composite attributes which can be divided into subparts.
Example: Patient Name, Doctor Name
Pat-id
Hosp-id
Hosp_Doctor
Hospid
Doc-id
PatiPPatient_MedicalRecord
Pat-id
Recordid
Microsoft Access
Microsoft Access is a desktop relational database management system (RDBMS) that
comes as part of the Office suite of products. It is often used by small businesses and
corporate departments for building small database applications that serve a specific
purpose.
Access has lower specifications than SQL Server (see below), so there are many things
it can't do that SQL Server can.
It's for this reason that Access has traditionally been used for smaller applications, with a
small number of users accessing it simultaneously.
One reason you might choose to use Access over SQL Server is for
compatibility/sharing. Many corporate environments and small businesses have Office
installed. Not so many have SQL Server. You can often email an Access database file to
someone and they can just double-click to open it.
Access is generally a lot easier to use than SQL Server especially for beginners. It
has a uniform interface that is consistent with the rest of the Office suite which can be
great if you're an Office user.
Access also includes wizards that walk you through the process of doing something
new.
You can also create forms straight from within Access. Not something you can do with
SQL Server you'll need a separate application for that. Plus, generating a report is a
lot easier in Access. In fact, forms and reports can be generated within a single click in
Access.
Another reason you might use Access instead of SQL Server is money. If you already
have Access installed as part of the Microsoft Office suite, purchasing SQL Server is an
extra expense that may not be necessary depending on your situation. SQL Server
can be quite expensive, depending on the license (although there are free options
available).
SQL Server
SQL Server is a more robust database management system than Access. SQL Server
was designed to have many hundreds, or even thousands of users accessing it at any
point in time. Microsoft Access on the other hand, doesn't handle this type of load very
well.
This makes SQL Server well suited for database driven websites. Access is not a
suitable solution for a database driven website unless it has a very small amount of
traffic (like you and a few of your friends). Even then, you may find yourself getting errors
due to multiple users trying to access the database at the same time.
SQL Server is also often the database behind corporate CRMs, business inventories,
and other mission-critical applications. The typical requirements of such applications go
way beyond the capabilities of a desktop system like Access.
SQL Server includes advanced database administration tools that enable organisations
to schedule tasks, receive alerts, optimize databases, configure security accounts/roles,
transfer data between other disparate sources, and much more.
Many features are optional, and can be added during installation. Optional components
include Reporting Services, Analysis Services, Master Data Services, Distributed Replay
Controller, Data Quality Services, R Server, PolyBase Query Service for External Data,
and many more.
Even the main administration console (SQL Server Management Studio) isn't included
with installation it needs to be installed separately. The possible reasoning behind this
is that most SQL Server installations are only accessed remotely via an application (at
least, in a production environment). Administering SQL Server from the same machine is
usually reserved for developers or DBAs in a development environment.
Basically, SQL Server includes a lot of advanced features that many Access users will
never need. But many of these advanced features are considered crucial for any
medium to large scale business.
However, just because it has many (optional) advanced features, doesn't mean that you
have to reserve SQL Server for the big jobs. There are free editions available (Express
and Developer editions) that can be perfect for smaller projects.
Access 2016
524,272 terabytes
Attribute
Access 2016
16 terabytes
Maximum number of
simultaneous users /
concurrent connections
255
32,767
Maximum number of
columns/fields per table
255
Number of characters in a
255
Text field (Access) Bytes
per varchar(max),
varbinary(max), xml, text, or
image column (SQL Server)
2^31-1
Number of characters in a
Long Text field (Access),
or per ntext or
nvarchar(max) column
(SQL Server)
2^30-1
Number of indexes in a
table
Approximately 64,000*
Number of characters in an
SQL statement
Number of objects in a
database
32,768
2,147,483,647
Number of fields/columns
per foreign key
10
16
Number of fields/columns
per primary key
10
16
Attribute
Access 2016
Number of fields/columns
per index
10
16
If the table contains one or more
XML indexes, the clustering key of
the user table is limited to 15
columns because the XML column
is added to the clustering key of the
primary XML index.
In SQL Server, you can include
nonkey columns in a nonclustered
index to avoid the limitation of a
maximum of 16 key columns.
Number of fields/columns
in a recordset/SELECT
statement
255
4,096
Number of nested
subqueries
50*
32
What is SQL?
SQL is a computer language for working with sets of facts and the relationships between them. Relational
database programs, such as Access, use SQL to work with data. Like many computer languages, SQL is
an international standard that is recognized by standards bodies such as ISO and ANSI.
You use SQL to describe sets of data that can help you answer questions. When you use SQL, you must
use the correct syntax. Syntax is the set of rules by which the elements of a language are correctly
combined. SQL syntax is based on English syntax, and uses many of the same elements as Visual Basic
for Applications (VBA) syntax.
For example, a simple SQL statement that retrieves a list of last names for contacts whose first name is
Mary might resemble this:
SELECT Last_Name
FROM Contacts
WHERE First_Name = 'Mary';
NOTE: SQL is not only used for manipulating data, but also for creating and altering the design of
database objects, such as tables. The part of SQL that is used for creating and altering database objects is
called data-definition language (DDL). This topic does not cover DDL. For more information, see the
article Create or modify tables or indexes by using a data-definition query.
SELECT statements
To describe a set of data by using SQL, you write a SELECT statement. A SELECT statement contains a
complete description of a set of data that you want to obtain from a database. This includes the following:
What it does
Required
Yes
Yes
No
No
SQL terms
Each SQL clause is composed of terms comparable to parts of speech. The following table lists types
of SQL terms.
SQL term Comparable part Definition
of speech
Example
identifier
noun
Customers.[Phone
Number]
operator
verb or adverb
constant
noun
expression adjective
AS
42
>= Products.[Unit
Price]
Top of Page
Basic SQL clauses: SELECT, FROM, and WHERE
A SQL statement takes the general form:
SELECT field_1
FROM table_1
WHERE criterion_1
;
NOTES:
Access ignores line breaks in a SQL statement. However, consider using a line for each clause to help
improve the readability of your SQL statements for yourself and others.
Every SELECT statement ends with a semi-colon (;). The semi-colon can appear at the end of the last
clause or on a line by itself at the end of the SQL statement.
An example in Access
The following illustrates what a SQL statement for a simple select query might look like in Access:
1. SELECT clause
2. FROM clause
3. WHERE clause
This example SQL statement reads "Select the data that is stored in the fields named E-mail Address and
Company from the table named Contacts, specifically those records in which the value of the field City is
Seattle."
Let's look at the example, one clause at a time, to see how SQL syntax works.
An ORDER BY clause contains a list of the fields that you want to use for sorting, in the same order that
you want to apply the sort operations.
For example, suppose that you want your results sorted first by the value of the field Company in
descending order, and if there are records with the same value for Company sorted next by the
values in the field E-mail Address in ascending order. Your ORDER BY clause would resemble the
following:
ORDER BY Company DESC, [E-mail Address]
NOTE: By default, Access sorts values in ascending order (A-Z, smallest to largest). Use the DESC
keyword to sort values in descending order instead.
For more information about the ORDER BY clause, see the topic ORDER BY Clause.
Top of Page
Working with summarized data: GROUP BY and HAVING
Sometimes you want to work with summarized data, such as the total sales in a month, or the most
expensive items in an inventory. To do this, you apply an aggregate function to a field in your SELECT
clause. For example, if you want your query to show the count of e-mail addresses listed for each
company, your SELECT clause might resemble the following:
SELECT COUNT([E-mail Address]), Company
The aggregate functions that you can use depend on the type of data that is in the field or expression that
you want to use. For more information about the available aggregate functions, see the article SQL
Aggregate Functions.
Specifying fields that are not used in an aggregate function: The GROUP BY clause
When you use aggregate functions, you usually must also create a GROUP BY clause. A GROUP BY
clause lists all the fields to which you do not apply an aggregate function. If you apply aggregate
functions to all the fields in a query, you do not have to create the GROUP BY clause.
A GROUP BY clause immediately follows the WHERE clause, or the FROM clause if there is no
WHERE clause. A GROUP BY clause lists the fields as they appear in the SELECT clause.
For example, continuing the previous example, if your SELECT clause applies an aggregate function to
[E-mail Address] but not to Company, your GROUP BY clause would resemble the following:
GROUP BY Company
For more information about the GROUP BY clause, see the topic GROUP BY Clause.
FROM table_a
;
For example, suppose that you have a table named Products and another table named Services. Both
tables have fields that contain the name of the product or service, the price, warranty or guarantee
availability, and whether you offer the product or service exclusively. Although the Products table stores
warranty information, and the Services table stores guarantee information, the basic information is the
same (whether a particular product or service includes a promise of quality). You can use a union query,
such as the following, to combine the four fields from the two tables:
SELECT name, price, warranty_available, exclusive_offer
FROM Products
UNION ALL
SELECT name, price, guarantee_available, exclusive_offer
FROM Services
;
For more information about how to combine SELECT statements by using the UNION operator, see the
article Combine the results of several select queries by using a union query.
Top of Page
More about the SELECT clause
In a SELECT statement, the SELECT clause lists the fields that contain data that you want to use.
Use square brackets to enclose identifiers
You can use square brackets to enclose the name of a field in a SELECT clause. If the name does not
contain any spaces or special characters (such as punctuation marks), the square brackets are optional. If
the name does contain spaces or special characters, you must use the brackets.
TIP: A name that contains spaces is easier to read and can save you time when you design forms and
reports, but may end up making you type more when you write SQL statements. You should consider this
fact when you name objects in your database.
If your SQL statement has two or more fields that have the same name, you must add the name of each
field's data source to the field name in the SELECT clause. You use the same name for the data source
that you use in the FROM clause.
Select all fields
When you want to include all the fields from a data source, you can either list all the fields individually in
the SELECT clause, or you can use the asterisk wildcard character (*). When you use the asterisk, Access
determines when the query is run what fields the data source contains, and includes all those fields in the
query. This helps make sure that the query stays up-to-date if new fields are added to the data source.
You can use the asterisk with one or more data sources in a SQL statement. If you use the asterisk and
there are multiple data sources, you must include the data source name together with the asterisk, so that
Access can determine which data source to include all fields from.
For example, suppose you want to select all the fields from the Orders table but only the e-mail address
from the Contacts table. Your SELECT clause might resemble this:
SELECT Orders.*, Contacts.[E-mail Address]
NOTE: Keep track of when you use the asterisk. If new fields are later added to the data source and you
did not plan for them, your query results might not turn out as you want.
Select distinct values
If you know that your statement will select redundant data, and you would rather see only distinct values,
you can use the DISTINCT keyword in your SELECT clause. For example, suppose that your customers
each represent several different interests, some of which use the same telephone number. If you want to
make sure that you only see each telephone number once, your SELECT clause appears as follows:
SELECT DISTINCT [txtCustomerPhone]
Use substitute names for fields or expressions: the AS keyword
You can change the label that is displayed for any field in datasheet view by using the AS keyword and a
field alias in your SELECT clause. A field alias is a name that you assign to a field in a query to make the
results easier to read. For example, if you want to select data from a field named txtCustPhone, and the
field contains customer telephone numbers, you could improve the readability of your results by using a
field alias in your SELECT statement, as follows:
SELECT [txtCustPhone] AS [Customer Phone]
NOTE: You must use a field alias when you use an expression in a SELECT clause.
Select by using an expression
Sometimes, you want to look at calculations based on your data, or retrieve only part of a field's data. For
example, suppose that you want to return the year that customers were born, based on data in the
BirthDate field in your database. Your SELECT clause might resemble the following:
SELECT DatePart("yyyy",[BirthDate]) AS [Birth Year]
This expression consists of the DatePart function and two arguments "yyyy" (a constant), and
[BirthDate] (an identifier).
You can use any valid expression as a field, if the expression outputs a single value when given a single
input value.
Top of Page
Part
compopr
Description
Any relational comparison operator: "=," "<," ">," "<=," ">=," or "<>."
Outer joins
Outer joins are similar to inner joins because they tell a query how to combine information from two
sources. They are different because they also specify whether to include data where no common value
exists. Outer joins are directional: you can specify whether to include all the records from the first data
source specified in the join (called a left join), or to include all the records from the second data source in
the join (called a right join).
An outer join has the following syntax:
FROM table1 [ LEFT | RIGHT ] JOIN table2
ON table1.field1compopr table2.field2
The following table describes the different parts of LEFT JOIN and RIGHT JOIN operations.
Part
Description
table1,table2 The names of the tables from which records are combined.
field1,field2 The names of the fields that are joined. The fields must be of the same data type
and contain the same kind of data, but they do not have to have the same name.
compopr
Any relational comparison operator: "=," "<," ">," "<=," ">=," or "<>."
For more information about joins, see the article Join tables and queries.
Top of Page
More about the WHERE clause
When you want to use data to limit the number of records that are returned in a query, you use query
criteria in the WHERE clause of a SELECT statement. A query criterion is similar to a formula it is a
string that may consist of field references, operators, and constants. Query criteria are a type of
expression.
The following table shows some sample criteria and explains how they work.
Criteria
>25 and <50
Description
This criterion applies to a Number field, such as Price or UnitsInStock.
It includes only those records where the field contains a value greater
than 25 and less than 50.
DateDiff ("yyyy",
This criterion applies to a Date/Time field, such as BirthDate. Only
[BirthDate], Date()) > records where the number of years between a person's birth date and
30
today's date is greater than 30 are included in the query result.
Is Null
This criterion can be applied to any kind of field to show records where
the field value is null.
As the previous table illustrates, criteria can look very different from each other depending on the data
type of the field to which the criteria apply and your specific requirements. Some criteria are simple, and
use basic operators and constants. Others are complex, and use functions and special operators, and
include field references.
IMPORTANT: If a field is used with an aggregate function, you cannot specify criteria for that field in a
WHERE clause. Instead, you use a HAVING clause to specify criteria for aggregated fields. For more
information, see the section Working with summarized data: GROUP BY and HAVING.
WHERE clause syntax
A WHERE clause has the following basic syntax:
WHERE field = criterion
For example, suppose that you want the telephone number of a customer, but you only remember that the
customer's last name is Bagel. Instead of looking at all the telephone numbers in your database, you could
use a WHERE clause to limit the results and make it easier to find the telephone number that you want.
Assuming that last names are stored in a field that is named LastName, your WHERE clause appears as
follows:
WHERE [LastName]='Bagel'
NOTE: You do not have to base the criteria in your WHERE clause on the equivalence of values. You
can use other comparison operators, such as greater than (>) or less than (<). For example, WHERE
[Price]>100.
Use the WHERE clause to combine data sources
Sometimes you may want to combine data sources based on fields that have matching data, but have
different data types. For example, a field in one table may have a Number data type, and you want to
compare that field to a field in another table that has a Text data type.
You cannot create a join between fields that have different data types. To combine data from two data
sources based on values in fields that have different data types, you create a WHERE clause that uses one
field as a criterion for the other field, by using the LIKE keyword.
For example, suppose that you want to use data from table1 and table2, but only when the data in field1 (a
text field in table1) matches the data in field2 (a number field in table2). Your WHERE clause would
resemble the following:
WHERE field1 LIKE field2