Microsoft SQL Server
Microsoft SQL Server
DBMS Concepts
Database System Concepts and Architecture
• 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.
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
• 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:
• 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)
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
• Tables: Use upper case and singular form in table names – not plural, e.g.,
“STUDENT” (not students)
• 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:
• 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
• 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
• 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.