0% found this document useful (0 votes)
116 views111 pages

Microsoft SQL Server

This document provides an overview of Microsoft SQL Server and database concepts. It discusses what a database and DBMS are, and covers database architectures including two-tier and three-tier client/server models. It also summarizes database schemas, instances, models, and the three schema architecture. Additional sections cover SQL, components of SQL like DDL and DML, and an introduction to working with Microsoft SQL Server and SQL Server Management Studio.

Uploaded by

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

Microsoft SQL Server

This document provides an overview of Microsoft SQL Server and database concepts. It discusses what a database and DBMS are, and covers database architectures including two-tier and three-tier client/server models. It also summarizes database schemas, instances, models, and the three schema architecture. Additional sections cover SQL, components of SQL like DDL and DML, and an introduction to working with Microsoft SQL Server and SQL Server Management Studio.

Uploaded by

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

Microsoft SQL Server

DBMS Concepts
Database System Concepts and Architecture

• A database is an organized collection of information.


• A DBMS is a program that stores, retrieves, and modifies data in the
database on request.
Database Architecture
• Database architecture is logically divided into two types.
• Logical two-tier Client / Server architecture
• Logical three-tier Client / Server architecture
Two-tier Client / Server architecture
• Two-tier Client / Server architecture is used for User Interface
program and Application Programs that runs on client side.
• An interface called ODBC(Open Database Connectivity) provides
an API that allow client side program to call the DBMS.
• Most DBMS vendors provide ODBC drivers.
• A client program may connect to several DBMS's.
Three-tier Client / Server database architecture

• Three-tier Client / Server database architecture is


commonly used architecture for web applications.
• Intermediate layer called Application server or Web
Server stores the web connectivity software and the
business logic(constraints) part of application used to
access the right amount of data from the database server.
• This layer acts like medium for sending partially
processed data between the database server and the
client.
Relational Database Life cycle

• From concept to production, you can develop a database


by using the system development life cycle, which
contains multiple stages of development.

• This top-down, systematic approach to database


development transforms business information
requirements into an operational database.
Database Schemas and Instances

• Database Schema: The description of a database.

• It includes descriptions of the database structure and the constraints that should
hold on the database.

• Entity - an object in the real world that is distinguishable from other objects.

• Attribute - a property or description of an entity.

• Domain - a set of possible values for an attribute.

• Relationship - an association among two or more entities.


Database Schemas and Instances

• Schema Diagram: A diagrammatic display of (some aspects of)


a database schema.
• Schema Construct: A component of the schema or an object
within the schema, e.g., STUDENT, COURSE.
• Database Instance: The actual data stored in a database at a
particular moment in time.
Database Models
• Conceptual (high-level, semantic) data models: Provide
concepts that are close to the way many users perceive data.
(Also called entity-based or object-based data models.)

• Physical (low-level, internal) data models: Provide concepts


that describe details of how data is stored in the computer.

• Implementation (representational) data models: Provide


concepts that fall between the above two, balancing user views
with some computer storage details.
Three Schema Architecture
1.The internal level has an internal schema, which describes the physical
storage structure of the database.
The internal schema uses a physical data model and describes the
complete details of data storage and access paths for the database.
2. The conceptual level has a conceptual schema, which describes the
structure of the whole database for a community of users.
• The conceptual schema hides the details of physical storage structures
and concentrates on describing entities, data types, relationships, user
operations, and constraints.
• This implementation conceptual schema is often based on a conceptual
schema design in a high-level data model.
3. The external or view level includes a number of external schemas or user
views.
• Each external schema describes the part of the database that a particular
user group is interested in and hides the rest of the database from that
user group.
• Mappings among schema levels are needed to
transform requests and data.
• Programs refer to an external schema, and are
mapped by the DBMS to the internal schema for
execution.
Data Independence
• Logical Data Independence: The capacity to change the
conceptual schema without having to change the external
schemas and their application programs.
• Physical Data Independence: The capacity to change the
internal schema without having to change the conceptual
schema.
Step IV Data Distribution
Data fragmentation:
• It is a technique used to break up objects. 
• In designing a distributed database, you must decide which portion of the database is
to be stored where. 
• One technique used to break up the database into logical units called fragments.

Data replication
• It is the storage of data copies at multiple sites on the network. Fragment copies can
be stored at several site, thus enhancing data availability and response time.
• Replicated data is subject to a mutual consistency rule.
• This rule requires that all copies of the data fragments must be identical and to ensure
data consistency among all of the replications. 

Data allocation
• It is a process of deciding where to store the data.
• It also involves a decision as to which data is stored at what location. 
Working with Microsoft SQL Server
Introduction to SQL

• SQL (Structured Query Language) is a database computer


language designed for managing data in relational database
management systems (RDBMS).
• SQL, is a standardized computer language that was originally
developed by IBM for querying, altering and defining relational
databases, using declarative statements.
• SQL is pronounced /ˌɛs kjuː ˈɛl/ (letter by letter) or /ˈsiːkwəl/ (as a
word).
Introduction to SQL
• Even if SQL is a standard, many of the database systems that exist
today implement their own version of the SQL language.
• In this course, we will use the Microsoft SQL Server as an
example.
• There are lots of different database systems, or DBMS – Database
Management Systems, such as:
• Microsoft SQL Server
o Enterprise, Developer versions, etc.
o Express version is free of charge
• Oracle
• MySQL (Oracle, previously Sun Microsystems) - MySQL can be
used free of charge (open source license), Web sites that use MySQL:
YouTube, Wikipedia, Facebook
• Microsoft Access, IBM DB2, Sybase etc.
Components of SQL

• Data Definition Language (DDL)


• Data Manipulation Language (DML)
Data Definition Language (DDL)
• The Data Definition Language (DDL) manages table and index
structure.
• The most basic items of DDL are the CREATE, ALTER, RENAME and
DROP statements:
• CREATE creates an object (a table, for example) in the database.
• DROP deletes an object in the database, usually irretrievably.
• ALTER modifies the structure an existing object in various ways—
for example, adding a column to an existing table.
Data Manipulation Language (DML)

• The Data Manipulation Language (DML) is the subset of SQL used to add, update
and delete data.
• The acronym CRUD refers to all of the major functions that need to be
implemented in a relational database application to consider it complete.
• Each letter in the acronym can be mapped to a standard SQL statement:

Operation SQL Description


Create INSERT INTO inserts new data into a
database

Read (Retrieve) SELECT extracts data from a


database
Update UPDATE updates data in a
database
Delete (Destroy) DELETE deletes data from a
database
Introduction to SQL Server

• Microsoft is the vendor of SQL Server.


• There are different editions of SQL Server, where SQL Server
Express is free to download and use.
• SQL Server uses T-SQL (Transact-SQL).
• T-SQL is Microsoft's proprietary extension to SQL.
• TSQL is very similar to standard SQL, but in addition it supports
some extra functionality, builtin functions, etc.
• T-SQL expands on the SQL standard to include procedural
programming, local variables, various support functions for string
processing, date processing, mathematics, etc.
Introduction to SQL Server
• SQL Server consists of a Database Engine and a Management Studio.
Introduction to SQL Server

• The Database engine has no graphical interface - it is just a


service running in the background of your computer
(preferable on the server).
• The Management Studio is graphical tool for configuring and
viewing the information in the database.
• It can be installed on the server or on the client (or both).
SQL Server Installation
How to work with SQL Server
SQL Server Management Studio (SSMS)

• SQL Server Management Studio is a GUI tool included with SQL Server for configuring,
managing, and administering all components within Microsoft SQL Server.
• The tool includes both script editors and graphical tools that work with objects and
features of the server.
• A central feature of SQL Server Management Studio is the Object Explorer, which allows
the user to browse, select, and act upon any of the objects within the server.
• It can be used to visually observe and analyze query plans and optimize the database
performance, among others.
• SQL Server Management Studio can also be used to create a new database, alter any
existing database schema by adding or modifying tables and indexes, or analyze
performance.
• It includes the query windows which provide a GUI based interface to write and execute
queries.
SQL Server Management Studio (SSMS)
SQL Server Management Studio (SSMS)

• When creating SQL commands and queries, the “Query Editor”


(select “New Query” from the Toolbar) is used.

• With SQL and the “Query Editor” we can do almost everything


with code, but sometimes it is also a good idea to use the
different Designer tools in SQL to help us do the work without
coding (so much).
Create a new Database

You may also use the SQL language to create a new database, but sometimes it is easier to
just use the built-in features in the Management Studio.
Queries
• In order to make a new SQL query, select the “New Query” button from the Toolbar.
CREATE TABLE

• The CREATE TABLE statement is used to create a table in a database.


Data types

• Numbers: int, float


• Text/Stings: varchar(X) – where X is the length of the string
• Dates: date, datetime
Example – Create Table
Create a table called “CUSTOMER” which has the following columns and data types:
Example – Create Table
Create Tables using the Designer Tools
Create Tables using the Designer Tools
Guidelines

When creating tables you should consider following these guidelines:

• Tables: Use upper case and singular form in table names – not plural, e.g.,
“STUDENT” (not students)

• Columns: Use Pascal notation, e.g., “StudentId”

• Primary Key:
 If the table name is “COURSE”, name the Primary Key column “CourseId”, etc.
 “Always” use Integer and Identity(1,1) for Primary Keys.

• Specify Required Columns (NOT NULL) – i.e., which columns that need to have data
or not
• Standardize Data Types: int, float, varchar(x).
• Use English for table and column names
INSERT INTO
• The INSERT INTO statement is used to insert a new row in a
table.
• It is possible to write the INSERT INTO statement in two
forms.
• The first form doesn't specify the column names where the
data will be inserted, only their values:
• The second form specifies both the column names and the
values to be inserted:

Example:
INSERT INTO CUSTOMER (CustomerNumber, LastName,
FirstName, AreaCode,Address, Phone)
VALUES ('1000', 'Smith', 'John', 12, 'California', '11111111')
Insert Data Only in Specified Columns:

• It is also possible to only add data in specific columns.


Insert Data in the Designer Tools:
• When you have created the tables you can easily insert data into
them using the designer tools.
• Step 1: Right-click on the specific table and select “Edit Top 200
Rows”:
Insert Data in the Designer Tools:
• Step2: Enter data in a table format, similar to, e.g., MS Excel:
SELECT
• The SELECT statement is probably the most used SQL command.
• The SELECT statement is used for retrieving rows from the
database and enables the selection of one or many rows or
columns from one or many tables in the database.
• We will use the CUSTOMER table as an example. The CUSTOMER
table has the following columns:
SELECT
• The CUSTOMER table contains the following data:
Select Data in the Designer Tools:
UPDATE
• The UPDATE statement is used to update existing records in a
table.
• Syntax:
UPDATE
UPDATE
Update Data in the Designer Tools:
• The same way you insert data you can also update the data.
• Step1: Right-click on the specific table and select “Edit Top 200 Rows”:
Update Data in the Designer Tools:

• Step2: Then you can change your data:


DELETE
• The DELETE statement is used to delete rows in a table.
• Syntax:
DELETE
Delete All Rows:

• It is possible to delete all rows in a table without deleting the


table.
• This means that the table structure, attributes, and indexes
will be intact:
Delete Data in the Designer Tools

• You delete data in the designer by right-click on the row and select
“Delete”:
The ORDER BY Keyword
• If you want the data to appear in a specific order you need to use
the “order by” keyword.
The ORDER BY Keyword

• You may also sort by several columns

• If you use the “order by” keyword, the default order is ascending
(“asc”). If you want the
• order to be opposite, i.e., descending, then you need to use the
“desc” keyword.
SELECT DISTINCT
• In a table, some of the columns may contain duplicate values. This
is not a problem, however, sometimes you will want to list only the
different (distinct) values in a table.
• The DISTINCT keyword can be used to return only distinct
(different) values.
• Syntax :
ALTER TABLE Statement

• ALTER TABLE statement in SQL Server (Transact-SQL) is used to


add a column, modify a column, drop a column, rename a
column or rename a table.
Add column in table
Add multiple columns in table
Modify column in table
Drop column in table
Rename column in table

• You can not use the ALTER TABLE statement in SQL Server to
rename a column in a table.
Rename table

• You can not use the ALTER TABLE statement in SQL Server to rename
a table.

You might also like