Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views83 pages

Basic Database

Uploaded by

sahluaddisu92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views83 pages

Basic Database

Uploaded by

sahluaddisu92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 83

BOLE MANUFACTURING COLLAGE

BASIC DATABASE training

Operate Database Application


Content that covers
• Introduction to database
• Data types in database
• Create e_r diagram
• Create database/blank database
• Create query from database
• Create form from database
• Create report from database
• Introduction to SQL/when we have atime.
Introduction to Database

• A database can best be described as a way of


storing large amounts of information.
• The data can be retrieved and we can even ask
questions of the data and get answers.
– For example:You may want to know how
many Students enrolled in every occupational
level.
• MS Access (MS Office Access 2007) is a
database management tool that enables one to
store relevant data.
• Other database software's include sql,oracle
etc….
Introduction to Database
• Database also has the capabilities to
retrieve, sort, summarize report and result
immediately and effectively.
• Microsoft Access (MS Access) enables to
manage all important information from a
single database file.

• Data is raw fact,figure,stastics.


• Record is a collection of related data.
The design process
 Determine the purpose of your database. This helps
prepare you for the remaining steps.
 Find and organize the information required. Gather all of
the types of information you might want to record in the
database, such as product name and order number.
 Divide the information into tables. Divide your
information items into major entities or subjects, such as
Products or Orders. Each subject then becomes a table.
 Turn information items into columns . Decide what
information you want to store in each table.
 Specify primary keys. Choose each table’s primary key.
The primary key is a column that is used to uniquely
identify each row. An example might be Product ID or
Order ID.
The design process
 Set up the table relationships. Look at each table and
decide how the data in one table is related to the data in
other tables. Add fields to tables or create new tables to
clarify the relationships, as necessary.
 Refine your design. Analyze your design for errors.
Create the tables and add a few records of sample data.
See if you can get the results you want from your tables.
Make adjustments to the design, as needed.
 Apply the normalization rules. Apply the data
normalization rules to see if your tables are structured
correctly. Make adjustments to the tables, as needed.
Database OBJECTS
What does Database Object mean?
• A database object in a relational database is a
data structure used to either store or reference
data. The most common object that people
interact with is the table. Other objects are
indexes, stored procedures, sequences, views
and many more.
The different type of Database objects

• Tables: - Recently, we define it as a file but technically, it


was defined as a container or a worksheet-like
container where the collection of data has been stored.
• Tables - A table is a collection of data about a specific
topic, such as products or suppliers
• Basic Component of a Table:
– Meta Data – Database Structure
– Field – Column – Data
– Fieldname
– Record - Row - Information
• Metadata – is a “data about data” or synonymously
called table structure that defines what type of data your
data is? The description of the data stored.
• Queries –Queries used to view, change, and analyze
data in different ways. You can also use them as a source
of records for forms, reports.
• Database Query. A database query is a way of requesting
information from the database. ...
• Forms - A form is a type of a database object that is
primarily used to enter or display data in a database. You
can also use a form as a switchboard that opens other
forms and reports in the database, or as a custom dialog
box that accepts user input and carries out an action
based on the input.
• Reports - A report is an effective way to present your
data in a printed format. Because you have control over
the size and appearance of everything on a report,
Creating Data base Objects
• Before we proceed to creating your first
table, we need to know first the basic
components of a table:
– Meta Data – Database Structure
– Field – Column – Data
– Fieldname
– Record - Row - Information
Data types in Microsoft Access
• The different kinds of MsAccess2007 data types are:
• Text: allows for the storage of any kind of data,
characters, digits and special characters.
• Memo: is used for texts of more than 255 characters
such as comments or explanations.
• Number: for numerical data used in mathematical
calculations.
• Date/Time: for the introduction of date and time from the
year 100 to 9999.
• Currency: For monetary/economic values and numerical
data used in mathematical calculations in which the data
involved contains between one and four decimals.
• Auto number: a unique sequential number (increasing
one by one), or a number that Access assigns every time
it adds a new record to a table.
Data types in Microsoft Access
• Yes/No:- Yes and No values, and fields that contain one of two
values (Yes/No, True/False or Activated/Deactivated).
• OLE Object: an object such as a Microsoft Excel spreadsheet, a
Microsoft Word document, graphics, images, sounds, or other
binaries.
– Used to embed or link to documents from other programs like
Excel and Word.
• Hyperlink: text or a combination of text and numbers stored as text
and used as a hyperlink address.
• Attachment: Used to store files in an Access database.
– The attachment data type lets you store one or more files per
record.
• Lookup wizard…: A lookup wizard field lets the user choose from a
predefined set of options, like a "male" or "female" selection or a
"country" selection.
Designing a table involves:-
• Entering unique names of the columns of the table in the
“field name” column of the design view.
• Names of fields and objects in Microsoft Access can be
up to 64characters long.
• They can include any combination of letters, numbers,
spaces, and special characters except a period (.), an
exclamation point (!), an accent grave (`), and brackets ([
]). They also can't begin with leading spaces.
Normalization
• Normalization is the process of efficiently
organizing data in a database.
• There are two goals of the normalization
process:
• Eliminating redundant data (for example, storing
the same data in more than one table) and
• Ensuring data dependencies make sense (only
storing related data in a table).
• Both of these are valuable goals as they reduce
the amount of space a database consumes and
ensure that data is logically stored.
• Modifying Database Object
If possible, you should avoid deleting a field
from a database that was generated from
one of the supplied templates but
• Before you can delete a field, you must
ensure that it doesn't participate in any
table relationships. If you try to delete a
field for which relationships exist, Access
warns you that you must first delete the
relationships.
Table Relationship
• Relationships allow you to describe the
connections between different database tables
in powerful ways.
• Once you’ve described the relationships
between your tables, you can later leverage that
information to perform powerful cross-table
queries, known as joins.
• A relationship is a logical connection between
two tables.
• Keys are fields that are part of a table
relationship. There are two kinds of keys:-
• Primary key
• A table can have only one primary key.
• A primary key is used to identify each record
that you store in the table.
• It will not allow a duplication of the Primary Key
thus make it unique.
• Primary Key is the unique identification of one
record. There is a uniquely identification
number, such as
• ID number
• A serial number
• A code that serves as a primary key
• Foreign key
• A table can also have one or more foreign
key.
• A foreign key contains values that
correspondent to values in the primary key
of another table
• You use table relationship to combine data
from related table
Types of Database Relationships
• One-to-one relationships: occur when each entry in the
first table has one, and only one, counterpart in the
second table. Example one department has I manager
Employee parking space
• One-to-many relationships: Is the most common type
of database relationship. . One teacher teaches many
student, organization employee
• Many-to-many relationships: occur when each record
in the first table corresponds to one or more records in
the second table and each record in the second table
corresponds to one or more records in the first table.
• Many student can learn many courses
ER Diagrams (Entity Relationship Diagrams)

• An Entity Relationship Diagram (ERD) is a visual


representation of different data using conventions that
describe how these data are related to each other.
• Is a graphical representation of the data independence
of the actual database implementation.
• ER Diagrams Usage
• ER diagrams are most often associated with complex
databases that are used in software engineering and IT
networks.
• In particular, ER diagrams are frequently used during the
design stage of a development process in order to
identify different system elements and their relationships
with each other.
• Elements in ER diagrams
• There are three basic elements in an ER
Diagram:

. Entity
.Attribute
. Relationship
ER Diagram Symbols and Notations
Entity
• An entity can be a person, place, event, or
object that is relevant to a given system.
• For example, a school system may include
students, teachers, major courses,
subjects, fees, and other items.
• Entities are represented in ER diagrams by
a rectangle and named using singular
nouns
• Weak Entity
• A weak entity is an entity that depends on the existence
of another entity.
• In more technical terms it can defined as an entity that
cannot be identified by its own attributes.
• It uses a foreign key combined with its attributed to form
the primary key.
• Example parent/child relationship, parent strong entity
and child is weak entity.
• An entity like order item is a good example for this. The
order item will be meaningless without an order so it
depends on the existence of order.
• Weak Entity Example in ER diagrams
Attribute
• An attribute is a property, trait, or characteristic of an
entity, relationship, or another attribute.
• An entity can have as many attributes as necessary.
• Mean while, attributes can also have their own specific
attributes.
• For example, the attribute “customer address” can have
the attributes number, street, city, and state. These are
called composite attributes.
• Note that some top level ER diagrams do not show
attributes for the sake of simplicity.
• In those that do, however, attributes are represented by
oval shapes.
• Multi value:- has more than one value
• Composite: attributes can also have their
own specific attributes.
• Derived :-changeable values /dependable
E.G age from DOB
• PRIMARY KEYS are underlined.
• Key
Relationship
• A relationship describes how entities interact.
• Associate between entity is called relationship.
• For example, the entity “carpenter” may be related to the
entity “table” by the relationship “builds” or “makes”.

• Relationships are represented by diamond shapes and


are labeled using verbs.
• Using Relationships in Entity Relationship Diagrams
Count……
• The relationship in this case follows a “one
to many” model
Count………
• Example 1:Build an ER Diagram for the following
information:
• A student record management system will have the
following two basic data object categories with their own
features or properties: Students will have an Id, Name,
Dept, Age, GPA and Course will have an Id, Name,
Credit Hours
• student enroll in a course in a specific Academic Year
Count………
• Example 2:Build an ER Diagram for the following
information:
• A Personnel record management system will have the
following two basic data object categories with their own
features or properties: Employee will have an Id, Name,
DoB, Age, Tel and Department will have an Id, Name,
Location
 One employee is assigned in one department
Benefits of ER diagrams
• ER diagrams constitute a very useful framework for creating and
manipulating databases.
• First, ER diagrams are easy to understand and do not require a person to
undergo extensive training to be able to work with it efficiently and
accurately.
• This means that designers can use ER diagrams to easily communicate
with developers, customers, and end users, regardless of their IT
proficiency.
• Second, ER diagrams are readily translatable into relational tables which
can be used to quickly build databases.
• In addition, ER diagrams can directly be used by database developers as
the blueprint for implementing data in specific software applications.
• Lastly, ER diagrams may be applied in other contexts such as describing
the different relationships and operations within an organization.

 Steps to create blank database
 Create a database object or table
 Understand data entry symbols
 Add ,edit or delete records.
 Rename a field in datasheet and design
view
 How to create a relationship
Adding ,Modifying& Deleting Records
• There are several ways to update data in an
Access database. You add a record to your
database when you have a new item to track,
such as a new contact to the Contacts table.
• You also change fields to stay up-to-date, such
as a new address or last name. To maintain data
integrity, the fields in an Access database are
set to accept a specific type of data, such as text
or numbers. If you don't enter the correct data
type, Access displays an error message.
• Finally, you can delete a record when it is no
longer relevant and to save space
Operation sheet 1:- Opening and designing DB application and
principles
• Steps to Create a blank database
• On the Getting Started with Microsoft Office Access page,
under New Blank Database, click Blank Database.

• In the Blank Database pane, type a file name in the File Name box. If you
do not supply a file name extension, Access adds it for you. To change the
location of the file from the default, click Browse for a location to put your
database (next to the File Name box), browse to the new location, and
then click OK.
• Click Create.
• Access creates the database with an empty table named Table1, and then
opens Table1 in Datasheet view. The cursor is placed in the first empty cell
in the Add New Field column.
Steps to create a blank database

• Begin typing to add data, or you can paste


data from another source, as described in
the section Copy data from another source
into an Access table
Steps to Open an existing Access database
• Click the Microsoft Office Button ,
• click Open. In the Open dialog box, browse to the database that
you want to open.
• Double-click the database to open it in the default mode specified in
the Access
• Click Open to open in default mode
• Click the arrow next to the Open button and then click Open Read-
Only to open the database for
• Open:-shared access in a multi-user environment
• read-only access:-access so that you can view but not edit it.
Other users can still read and write to the database.
• Open Exclusive:-anyone else who tries to open the database
receives a "file already in use" message.
• Open exclusive read only:-others can open only in read mode
Operation sheet 2:-Creating Database Objects (Tables )
• Click the Create tab.
• Click Table. ...
• Click the Click to Add field heading. ...
• Select the field type. ...
• Type a name for the field. ...
• Steps to Create a new table by using a table template
• On the Create tab, in the Tables group, click Table Templates and
then select one of the available templates from the list.
Steps To Create a new table by importing or linking to
external data
• Click the Microsoft Office Button , and then
click Open.
• In the Open dialog box, select and open the database in
which you wish to create a new table.
• On the External Data tab, in the Import group, click one
of the available data sources.

• Follow the instructions in the dialog boxes that appear at


each step.
Steps to set or change a table's primary key
• Select the table whose primary key you want to
set or change.
• On the Home tab, in the Views group,
click View, and then click Design View.
• In the table design grid, select the field or fields
that you want to use as the primary key.
• On the Design tab, in the Tools group,
click Primary Key.
• A key indicator appears to the left of the field or
fields that you specify as the primary key.
Steps to Remove the primary key
• Select the table whose primary key you want to
remove.
• On the Home tab, in the Views group,
click View, and then click Design View.
• Click the row selector for the current primary
key. If the primary key consists of multiple fields,
hold down CTRL, and then click the row selector
for each field.
• On the Design tab, in the Tools group,
click Primary Key.
Steps to Set a table's properties
• Select the table whose properties you want to
set.
• On the Home tab, in the Views group,
click View, and then click Design View.
• On the Design tab, in the Show/Hide group,
click Property Sheet. The table property sheet
is shown.
• On the property sheet, click the General tab.
• Click the box to the left of the property that you
want to set, and then enter a setting for the
property.
• To save your changes, press CTRL+S.
• Steps to Open a table in Datasheet view
• In the Navigation Pane, right-click the
table that you want to open.
• On the shortcut menu, click Datasheet
view.
• Steps to Rename a field
• Right-click the heading of the field that you
want to rename (for example, Field1).
• On the shortcut menu, click Rename
Column.
• Enter the new name in the field heading.
• Rename a field in Design view
• In the Navigation Pane, right-click the table in which you want to
rename the field, and then click Design View on the shortcut menu..
• Click the cell in the Field Name column for the field that you want to
rename.
• Edit the text to rename the field.
• To save your changes, click Save on the Quick Access Toolbar.

• Steps to Change a field's data type


• On the Ribbon, click the Datasheet tab .
• In the Data Type list, in the Data Type & Formatting group, select
the data type that you want.
• Rename a table
• In the Navigation Pane, right-click the
table that you want to rename ,and then
click Rename on the shortcut menu.
• Type the new name and then press
ENTER.
• To save your changes, click Save on the
Quick Access Toolbar.
Change the text that appears in a column heading
• In the Navigation Pane, right-click the table in
which you want to change the caption, and then
click Design View on the shortcut menu.
• Click the cell in the Field Name column for the
field whose Caption property you want to set.
• In the bottom section, under Field Properties,
on the General tab, click Caption.
• Type a new caption for the field.
• To save your changes, click Save on the Quick
Access Toolbar
Operation sheet 4:Creating Database
Relationship
• After you have created a table for each
subject in your database, you must
provide Office Access 2007 with the
means by which to bring that information
back together
• You do this by placing common fields in
tables that are related, and by defining
table relationships between your tables.
• You can then create queries, forms, and
reports that display
Steps to Create a table relationship by using the
Relationships document tab
• On the Database Tools tab, in the Show/Hide group,
click Relationships.
• If you have not yet defined any relationships, the Show
Table dialog box automatically appears. If it does not
appear, on the Design tab, in the Relationships group,
click Show Table.

• Select one or more tables or queries and then click Add.


After you have finished adding tables and queries to the
Relationships document tab, click Close.
• Drag a field (typically the primary key) from one table to
the common field (the foreign key) in the other table. To
drag multiple fields, press the CTRL key, click each field,
and then drag them.
• The Edit Relationships dialog box appears.
• Verify that the field names shown are the
common fields for the relationship. If a field
name is incorrect, click on the field name and
select the appropriate field from the list.
• To enforce referential integrity for this
relationship, select the Enforce Referential
Integrity check box. For more information about
referential integrity, see the section Enforce
Referential Integrity
• Click create
Create relationship
• To create a one-to-one relationship Both of the common fields
(typically the primary key and foreign key fields) must have a unique
index. This means that the Indexed property for these fields should
be set to Yes (No Duplicates). If both fields have a unique index,
Access creates a one-to-one relationship.
• To create a one-to-many relationship The field on the one side
(typically the primary key) of the relationship must have a unique
index. Which is Yes (No Duplicates). The field on the many side
should be set to either No or Yes (Duplicates OK).
• When one field has a unique index, and the other does not, Access
creates a one-to-many relationship.
Create a table relationship by using the Field List
pane
• Steps to Add a field and create a relationship from the Field List pane
• On the Datasheet tab, in the Fields & Columns group,
click Add Existing Fields.

• Under Fields available in other tables, click the plus sign


(+) next to a table name to display the list of fields in that
table.
• Drag the field that you want from the Field List pane to
the table that is open in Datasheet view.
• When the insertion line appears, drop the field into
position.
• The Lookup Wizard starts.
Set the join type
• You should think about the result you will most
often want from a query that joins the tables in
this relationship, and then set the join type
accordingly.
• Set the join type
• In the Edit Relationships dialog box, click Join
Type.
• The Join Properties dialog box appears.
• Click your choice, and then click OK.
Example
The following table (using the Customers and Orders
tables) shows the three choices that are displayed in
the Join Properties dialog box, the type of join they use,
and whether all rows or matching rows are returned for
each table.
To Turn referential integrity on or off
• On the Database Tools tab, in
the Show/Hide group, click Relationships.
• The Relationships document tab appears.
• On the Design tab, in
the Relationships group, click All
Relationships.
• You cannot enter a value in the foreign key field
of a related table if that value doesn't exist in the
primary key field of the primary table
• You cannot delete a record from a primary table if
matching records exist in a related table. For
example, you cannot delete an employee record
from the Employees table if there are orders
assigned to that employee in the Orders table.
You can, however, choose to delete a primary
record and all related records in one operation by
selecting the Cascade Delete Related
Records check box.
• You cannot change a primary key value in the primary
table if doing so would create orphan records.
• You can, however, choose to update a primary
record and all related records in one operation by
selecting the Cascade Update Related Fields check box.
• How?
• Go Edit Relationships dialog box appears.
• Select the Enforce Referential Integrity check box.
• Select either the Cascade Update Related Fields or
the Cascade Delete Related Records check box, or
select both.
• Make any additional changes to the relationship, and
then click OK.
Steps to delete a table relationship
• To remove a table relationship, you must
delete the relationship line in the
Relationships document tab.
• Carefully position the cursor so that it
points to the relationship line, and then click
the line.
• The relationship line appears thicker when it is
selected. With the relationship line selected,
press DELETE. Note that when you remove a
relationship, you also remove referential integrity
support for that relationship, if it is enabled
Operation Sheet 5: Add a record to a table or form
• Open the table in Datasheet View or the form in Form
View.
• On the Home tab, in the Records group, click New, or
click New (blank) record, or press Ctrl+Plus Sign (+).
• Find the record with an asterisk in the record selector,
and enter your new information.
• Click or otherwise place the focus on the first field that
you want to use, and then enter your data.
• To move to the next field in the same row, press TAB,
use the Right or Left arrow keys, or click the cell in the
next field.
• When you view another record or close the table or form,
Access saves the new record that you added. To
explicitly save changes to the current record, press
Shift+Enter.
To Delete a record
• The deletion process is fairly simple, except when
the record is related to other data and resides on
the "one" side of a one-to-many relationship. To
maintain data integrity, by default, Access does
not let you to delete related data.
• Open the table in Datasheet View or form in For
• m View.
• Select the record or records that you want to
delete.
• Press DELETE, select Home> Records >Delete,
or press Ctrl+Minus Sign
To Edit data in a text box or field
• Open the table or query in Datasheet View or
form in Form View.
• Click the field or navigate to the field by using
the TAB or arrow keys, and then press F2.
• Place the cursor where In Form view, you can
click a field's label to select the field. In you want
to enter information
• Enter or update the text that you want to insert.
If you make a typing mistake, press
BACKSPACE.
• If a field has an input mask, enter the data
according to the format.
INTRODUCION TO MY SQL
• SQL (Structured Query Language) is a
programming language designed for managing
data in relational database management systems
(RDBMS).
• It is a standard (main query) language for
relational DBMSs, like Microsoft Access, Microsoft
SQL Server, and Oracle, that used to
communicate with a database.
• SQL is used to perform basic data management tasks,
such as the insertion, modification, and deletion of data
from the tables using the standard SQL commands such
as "Select", "Insert", "Update", "Delete", "Create", and
"Drop".
HOW TO INSTAL SQL SERVER
• The SQL Server Installation Wizard provides a single feature
tree to install all SQL Server components such as:
• Database Engine
• Analysis Services
• Reporting Services
• Integration Services
• Master Data Services
• Data Quality Services
• Management tools
• Connectivity components
• You can install each component individually or select a
combination of the components listed above.
STEPS
• STEP 1: Copy the installation files
• STEP 2: Double click on the setup.exe file. After a few
seconds a dialog box appears:
• STEP 3: Click on the Installation hyperlink on the left hand
side of the screen:

• STEP 4 : Click on the "New Server stand-alone


installation" link on the right side of the screen:

COUNT…..
STEP 5 (optional): If any checks have failed, click on the
Show details button or "View detailed report link" to find out
the cause, correct it, and then click on the Re-run button to
perform the checks again.
• STEP 6: Product key ;If all checks have passed, click on
the OK button. After a few moments, the option to select the
edition and to enter the license key (or “product key”) will
appear.
• STEP 7: License Terms
Enter the product key into the box, or choose the free edition if
you're evaluating SQL Server 2008, and click on the Next
button:
• STEP 9: Setup Support Rules. If all is well, the following
screen appears:
• Click on the Next button again.
COUNT….
• STEP 10: Feature Selection. Select the features you
want to install.
At a minimum, the following are useful (I'd argue essential),
but what you need will depend on your needs:
COUNT…..
• STEP 12: Disk Space Requirements
• Click on Next.
STEP 13: Server Configuration. This step allows you to set up the
service accounts that will be used to run SQL Server. If you have
created Windows NT or Active Directory accounts for use with services,
use these.
COUNT….
• STEP 14: Database Engine Configuration – Account
Provision.This screen allows you to set up database engine
security.
COUNT ……
• STEP 15: Database Engine Configuration – Data
Directories. Click on the Data Directories tab.
COUNT….
If you are installing on a single drive laptop or desktop, then simply specify:
Data root
C:\Program Files\Microsoft SQL Server
directory
User database
C:\Data
directory
User log directory C:\Logs
Temp DB
C:\TempDB
directory
Temp Log
C:\TempDB
directory
Backup directory C:\Backups

Click on Next.
COUNT…
• STEP 16: Error Usage Reporting
• This screen simply asks if you want to send error information to
Microsoft and can safely be skipped if you do not want to share
any information.
.Click on Next again…
• STEP 16: Installation Rules
• This screen simply checks if there are any processes or other
installations running which will stop the installation of SQL
Server 2008.
• STEP 17: Ready to Install
• This screen summarizes what you are about to install and gives
you a last chance to cancel or change anything that’s wrongly
configured:
• STEP 18: Installation Complete. The following screen appears:
Creating and Deleting Databases
• Creating a Database
• When you create a database you need to use the Master database.
• 1. To create a database using New Database wizard:
• Right-click on Databases, and then select New Database.
• In Database name field, enter a “database name”.
• To create the database by accepting all default values, click OK;
otherwise, continue with the following optional steps.
• To change the owner name, click (…) to select another owner.
• 2. To create a database using “create database statement”:
• From the Standard bar, click “New Query”.
• On the sql editor write “create database database_name”
• Select the statement <create database database_name> and execute
it to create.
Deleting a database
• You can delete database by executing the DROP
DATABASE statement.
• Example: DROP DATABASE <database name>
• Exercises: 1. Create a database called library.
• 2. Delete the database that you have already
created.
• Creating, modifying and deleting Tables:
• Creating a table
• When you create a table you need to use the current database.
• SQL Server databases store all of your data in tables.
• Syntax: CREATE TABLE table_name
• (
• <Column_Name 1> <data type> <field size> <constraints>,
• <Column_Name 2> <data type> <field size> <constraints>,
• . . .
• <Column_Name n > <data type> <field size> <constraints>
• );
Modifying a table
• You can modify the table by adding a new column and
deleting a column from the table.
• The type of information that you specify when you add a
column is similar to the activity that you perform when you
create a table.
• Syntax: - ALTER TABLE <table_name> ADD
<column_name> <data type> <field size> <constraint>
• - ALTER TABLE <table_name> DROP
COLUMN <column_name>
• Deleting a Table
• Deleting a table removes that table definition and all data, as
well as the permission specification for that table.
• Before you delete a table, you should remove any
dependencies between the table and other objects.
• Syntax: DROP TABLE table_name
Select statement
• The Select statement is the most commonly used SQL command
that allows you to retrieve records from one or more tables in your
database.
• The basic SELECT statement in sql has 3 clauses: SELECT, FROM
and WHERE
• The SELECT clause specifies the table columns that are retrieved.
• The FROM clause specifies the table or tables from which columns
and rows are returned.
• The WHERE clause specifies the condition restricting the query. You
can restrict the number of rows by using comparison operators,
character strings, and logical operators as search conditions.
• The WHERE clause is optional; if missing, all table rows are
accessed.
Literals and data types
• Literals are letters, numbers, or symbols
that are used as specific values in a result
set (in output).
• Literals mean constants which are the
values we write in a conventional form.
• You can include literals in the select list to
make result sets more readable.
• Syntax: SELECT column_name1 ‘string
literal’, column_name2 ’string_literal’, …
FROM table_name
Count…..
• Data type is a constraint that specifies the type
of data stored in a table field.
• Common examples of data type in MS-Access
are:
• - Auto-number, Text, Number,
Date/Time, Currency, Yes/No, and so on.
• Common examples of data type in MS-SQL
server are:
• Char, varchar, int, float, double, datetime, and so
on.
Expressions
• An Expression is a combination of symbols and operators
that the SQL Server Database Engine evaluates to obtain a
single data value.
• Operands are values or variables, whereas operators are
symbols that represent particular actions.
• Operators can be used to join two or more simple
expressions into a complex expression.
• Every expression consists of at least one operand and can
have one or more operators.
• Example: - In the expression, SELECT ((5+5) * (5+5)), 5 is
an operand, and +, * are operators.
• - In database systems, you use expressions to
specify which information you want to retrieve.
• These types of expressions are called
queries.
Updating tables
• Inserting new rows
• The INSERT command is used to add a single tuple
to a relation.
• We must specify the relation (table) name and a list
of values for the tuple.
• The values should be listed in the same order in
which the corresponding attributes were specified in
the CREATE TABLE command.
• Syntax: Insert
into<TABLE_NAME>values('value1'<for_column 1>,
‘ value2'<for_column 2>,
'value3'<for_column 3>,
• . ,'value n'<for_column n>);
Count…
• Syntax: Insert
into<TABLE_NAME>(column1,column2,column3)
values('value1'<for_column 1>,'value2'<for_column
2>'value 3'<for_column 3);
• Updating values in rows
• The UPDATE statement is used to change existing
records in a table.
• Use a table reference to indicate which table needs to be
updated.
• Syntax: UPDATE table_name
• SET <column1=’value1’>,<column2=’value2’>,...
• [WHERE <search-condition>]
Deleting rows in the table
• The DELETE statement removes rows from a table.
• Syntax: DELETE FROM <Table_Name> [WHERE
<search-condition>];
• Combining tables with union
• The UNION operator is used to combine the result-set of
two or more SELECT statements.
• Each SELECT statement within the UNION must have
the same number of columns and similar data types.
• Syntax: SELECT <column_name_list>
FROM <table_name> UNION SELECT
<column_name_list>
• FROM <table_name>
O U
Y
N K
H A
T

You might also like