SlideShare a Scribd company logo
Never stop improving quality




Microsoft SQL Server

      LARION_TDT@Internship_03




                           www.elarion.com
Contents
Introduction
●   Relational Database
●   Database management system
●   Microsoft SQL server
●   Structures of Microsoft SQL server
●   How to create index for each record
●   Backup, Restore Database
●   Stored Procedure, Trigger, Function
●   View
●   Supporting tools for MS SQL server
●   Demo
                                                     2
Relational Database (1 of 4)
                                           Definition
●   Relational Database is database that all data are
    established many tables to have relationship each
    other.
●   Each table consists of many columns and many rows
    that each column is usually called a register,each row
    is described an attribute.




                                                             3
Relational Database (2 of 4)
                                     The main components
●       The main components :
       Table: each table stores information of an object
        outside real life.
       Primary key: a collection of one column or many
        columns inside tables that it is not permit null data and
        is only one.
       Foreign key: a collection of one column or many
        columns inside tables that they are a primary of other
        tables and their data can be permitted null




                                                                    4
Relational Database (3 of 4)
                Example 1:




                               5
Relational Database (4 of 4)
                Example 2:




                               6
Database Management System(1 of 3)

●   Popular Database Management Systems
       MS SQL server
       MySQL
       Oracle
       PostgreSql
       DB2
       …


                                                  7
Database Management System(2 of 3)
                                  Definition
●   Database management system is a
    software to permit users to create,
    control and access into database.
●   Database management system has
    maintained consistency of database
    during its cycle life.



                                            8
Database Management System (3 of 3)
                                           Function
●   The main functions of database management system
       Database definition
       Database construction
       Database manipulation: add , delete...
       Database administrator: security...
       Database protection: backup, restore




                                                       9
Mircosoft SQL server(1 of 3)
●   MS SQL Server is a database management
    system that it is established and developed by
    Microsoft based on Transact-SQL method in
    order to exchange data between Client and MS
    SQL Server.




                                                     10
Mircosoft SQL server(2 of 3)
                               Adaptation
●   MS SQL Server is optimized in order to run Very
    Large Database Environment (VLDE) even
    though Tera-Byte, especially for serving user
    thousands
●    MS SQL Server can collaborate with other
    servers such as Microsoft Internet Information
    Server (IIS), Oracle...




                                                      11
Mircosoft SQL server (3 of 3)
                                  Versions
●   Versions of MS SQL Server
       Enterprise Edition
       Developer Edition
       Standard Edition
       Workgroup Edition
       SQL Server Express Edition



                                           12
Mircosoft SQL server(1 of 3)
                                  Structure
●   One of the most usual structures MS SQL Server
       Client / Server Architecture
       N-tier Architecture




                                                 13
Structure of MS SQL server(2 of 3)

●   Client / Server Architecture




                                              14
Structure of MS SQL server (3 of 3)

●   N-tier Architecture




                                               15
How to create index for each record(1 of 2)

●   Index is used to supporting and improving
    for accessing more quick to data flows base
    on value of one or many columns.
●   Two forms:
        Clustered index
        Non-clustered index




                                                    16
How to create index for each record(2 of 2)

●   Syntax:
CREATE [CLUSTERED | NONCLUSTERED] INDEX index_name
    ON table_name(column_name [, column_name]...)

●   For example for creating non-clustered index on
    MADV of NHANVIEN columns:
CREATE NONCLUSTERED INDEX idx_nhanvien_madv
     ON nhanvien(madv)




                                                       17
Backup, Restore Database(1 of 7)
                                       Backup
What is Backup Database?
●   That is the activity of copying files or
    databases from SQL server to another
    storage device.
●   Having two backup database forms:
       By backup database commands
       By direct action in your SQL Server




                                               18
Backup, Restore Database(2 of 7)
                                         Backup
Syntax of Backup Database Commands
    BACKUP DATABASE { database_name | @database_name_var }
      TO < backup_device > [ ,...n ]
      [ WITH
         [ BLOCKSIZE = { blocksize | @blocksize_variable } ]
         [ [ , ] DESCRIPTION = { 'text'| @text_variable } ]
         [ [ , ] DIFFERENTIAL ]
         [ [ , ] EXPIREDATE = { date | @date_var }
             | RETAINDAYS = { days | @days_var } ]
         [ [ , ] FORMAT | NOFORMAT ]
         [ [ , ] { INIT | NOINIT } ]
         [ [ , ] MEDIADESCRIPTION = { 'text'| @text_variable } ]
         [ [ , ] MEDIANAME = { media_name | @media_name_variable } ]
         [ [ , ] NAME = { backup_set_name | @backup_set_name_var } ]
         [ [ , ] { NOSKIP | SKIP } ]
         [ [ , ] { NOUNLOAD | UNLOAD } ]
         [ [ , ] RESTART ]
         [ [ , ] STATS [ =percentage ] ]
      ]

                                                                       19
Backup, Restore Database(3 of 7)
                                     Backup
Description
 °   BLOCKSIZE: automatic parameter
 °   DIFFERENTIAL: differential backup is only
     necessary change datas
 °   EXPIREDATE: expiration of backup day
 °   FORMAT/NOFORMAT: destroying existing datas
     or not
 °   INIT/NOINIT: replace datas or not
 °   DESCRIPTION: details of description
 °   STATS: appearance of programbar
                                                  20
Backup, Restore Database(4 of 7)
                                  Backup
For example backup database
     BACKUP DATABASE QLNGK
     TO DISK= ‘F: ngk.bak’
     WITH
     DESCRIPTION = ‘BACK UP’,
     STATS
     GO




                                          21
Backup, Restore Database(5 of 7)
                                Backup
Result




                                        22
Backup, Restore Database(6 of 7)
                                            Restore
Syntax
      RESTORE DATABASE { database_name | @database_name_var }
  [ FROM <backup_device> [ ,...n ] ]
  [ WITH {
  [ RECOVERY | NORECOVERY | STANDBY =
        {standby_file_name | @standby_file_name_var } ]
  | , <general_WITH_options> [ ,...n ] | , <replication_WITH_option>
  | , <change_data_capture_WITH_option> | , <service_broker_WITH options>
  | , <point_in_time_WITH_options—RESTORE_DATABASE>
  } [ ,...n ]
  ]
        [;]
                                                                            23
Backup, Restore Database(end)
                                 Restore
For example:
     RESTORE DATABASE users
     FROM DISK='C:backupusers.BAK'
     WITH RECOVERY




                                           24
Stored Procedure, Trigger (1 of 9)
                              Stored Procedure
What is Stored Procedure ?
●   SP (Stored Procedure) is the name given to a
    group of SQL statement is created and stored in
    the server database.
●   SP allows transmission parameters, and may be
    called by many clients over the network with
    different parameters. When SP is changed, all
    clients will automatically receive the new
    version, because the SP is stored at the Server,
    not Client.

                                                       25
Stored Procedure, Trigger (2 of 9)
                              Stored Procedure
Creating procedure
 CREATE PROCEDURE procedure_name [;number]
   [([parameter1] [,parameter2]...[parameter255])]
  AS sql_statements




                                                     26
Stored Procedure, Trigger (3 of 9)
                                                  Stored Procedure
For example
  CREATE PROCEDURE sp_users_insert

      (@firstname varchar(50),

      @lastname varchar(50),

      @birthday date,

      @groupid int)

 AS

  BEGIN

        if exists(select groupid from groups where groupid = @groupid)

      BEGIN

      insert into users(firstname, lastname, birthday, groupid)
 values(@firstname,@lastname,@birthday,@groupid)

      END

  END
                                                                         27
Stored Procedure, Trigger (4 of 9)
                                               Trigger
●   Trigger is a data type that is specific saved.
    Otherwise, trigger to help ensure data integrity.
●   A table has maximum 3 trigger types:
          Update trigger
          Insert trigger
          Delete trigger
●   For example: employer salary is not permitted
    higher than his top-banana

                                                        28
Stored Procedure, Trigger (5 of 9)
                                                Trigger
Syntax:
  CREATE TRIGGER trigger_name
   ON table_name | view_name
      [WITH ENCRYPTION]
   {FOR | AFTER | INSTEAD OF}{ [INSERT] [,] [UPDATE ] [,]
 [DELETE] }
   AS sql_statements




                                                            29
Stored Procedure, Trigger (6 of 9)
                                                 Trigger

CREATE TRIGGER groups_users_delete
on groups
for delete
as
 BEGIN
   DECLARE @groupid int;
   Set @groupid=(Select groupid from DELETED);
   delete from users where groupid = @groupid
 END



                                                       30
Stored Procedure, Trigger (7 of 9)
                                       Function
Function is database object similar procedures .
However,the difference between procedures and
function that function returns to a value via its
function name while procedures do not.




                                                    31
Stored Procedure, Trigger (8 of 9)
                                              Trigger
Syntax
   CREATE FUNCTION [ schema_name. ] function_name
    ( [ { @parameter_name [ AS ]
      [ type_schema_name. ] parameter_data_type
      [ = default ] [ READONLY ] }
      [ ,...n ]S
      ]
    )
  RETURNS return_data_type
   [ WITH <function_option> [ ,...n ] ]
   [ AS ]
   BEGIN
        function_body
        RETURN scalar_expression
   END
  [;]                                               32
Stored Procedure, Trigger (end)
                                             Trigger
For example
 CREATE FUNCTION f_users_tong()
 RETURNS @bangthongke TABLE
 (groupid int,groupname varchar(50),tonguser INT)
 AS
  BEGIN
   INSERT INTO @bangthongke
   SELECT groups.groupid,groups.groupname,COUNT(userid)
   FROM (groups INNER JOIN users
   ON groups.groupid = users.groupid)
   GROUP BY groups.groupid,groups.groupname
   RETURN
 END

                                                      33
View(1 of 4)

Definition
●   View is a method that we can watch at data into
    one or many tables of database.
●   View is a virtual screen that it is created as a union
    of rows and columns by one or many different
    tables.
●   Decreasing more complex in database



                                                             34
View(2 of 4)

Syntax:
CREATE VIEW COMMAND used to create view:

   CREATE VIEW <virtual_name_table>
   AS
   <select_statement>



                                           35
View(3 of 4)

For example:
CREATE VIEW DSSV
AS
     SELECT masv, hodem, ten,
     DATEDIFF (YY, ngaysinh,GETDATE())
     AS tuoi, tenlop
     FROM sinhvien, lop



                                         36
View(end)
Result




                     37
Supportting tools for MS SQL Server

   One of the most popular supporting tools for MS
   SQL sever is SQL Assistant .You can download
   from link

http://www.softpedia.com/progDownload/SoftTree-SQL-Assistant-Download-92428.html




                                                                                   38
Demo
●   How to use Diagram
●   Decentralized
●   Backup
●   Restore
●   Function
●   Store Procedure
●   Trigger



                                39
Reference
●   Document of LARION_TDT@internship_02 Courses
●   Website: www.msdn.microsoft.com




                                                   40
Question and Answer




?
                      41
Thank you!



             42

More Related Content

What's hot (20)

PDF
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
eVideoTuition
 
PPTX
Data Definition and Data Manipulation Language-DDL & DML
Md. Selim Hossain
 
PPTX
Getting Started with MySQL II
Sankhya_Analytics
 
PPSX
IM02: Database Language
Kelvin Chan
 
PPT
MySQL lecture
webhostingguy
 
PPTX
Postgresql
NexThoughts Technologies
 
PPTX
Difference Between Sql - MySql and Oracle
Steve Johnson
 
PDF
Web app development_my_sql_08
Hassen Poreya
 
PPTX
SQL
Rajesh-QA
 
PPT
Updates
Isa Ansharullah
 
PPTX
MySql:Introduction
DataminingTools Inc
 
DOCX
Db2 Important questions to read
Prasanth Dusi
 
DOCX
Postgre sql run book
Vasudeva Rao
 
PDF
BITS: Introduction to MySQL - Introduction and Installation
BITS
 
DOCX
Types of sql commands by naveen kumar veligeti
Naveen Kumar Veligeti
 
PPTX
Group Members
Farhan Shahani
 
DOCX
Performence tuning
Vasudeva Rao
 
PPTX
Getting Started with MySQL I
Sankhya_Analytics
 
PPT
Chapter 7 working with databases and my sql
kausar31
 
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
eVideoTuition
 
Data Definition and Data Manipulation Language-DDL & DML
Md. Selim Hossain
 
Getting Started with MySQL II
Sankhya_Analytics
 
IM02: Database Language
Kelvin Chan
 
MySQL lecture
webhostingguy
 
Difference Between Sql - MySql and Oracle
Steve Johnson
 
Web app development_my_sql_08
Hassen Poreya
 
MySql:Introduction
DataminingTools Inc
 
Db2 Important questions to read
Prasanth Dusi
 
Postgre sql run book
Vasudeva Rao
 
BITS: Introduction to MySQL - Introduction and Installation
BITS
 
Types of sql commands by naveen kumar veligeti
Naveen Kumar Veligeti
 
Group Members
Farhan Shahani
 
Performence tuning
Vasudeva Rao
 
Getting Started with MySQL I
Sankhya_Analytics
 
Chapter 7 working with databases and my sql
kausar31
 

Viewers also liked (11)

PPTX
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
PPTX
MS SQL SERVER: Sql Functions And Procedures
sqlserver content
 
PPTX
MS SQL SERVER: Getting Started With Sql Server 2008
sqlserver content
 
PPT
The Ultimate Date Time Universe solution (Quick Start and Setup MS SQL Server)
Gino Scheppers
 
PPTX
MS SQL SERVER: Retrieving Data From A Database
sqlserver content
 
PPTX
Scenarios
Netresult Ltd
 
PPTX
MS Sql Server: Joining Databases
DataminingTools Inc
 
PPTX
Data type[s] on MS SQL Server
Chandan Banerjee
 
PPTX
MS Sql Server: Introduction To Database Concepts
DataminingTools Inc
 
PDF
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
PDF
Data that persuades: Annotated - from SES SF 2012
Ian Lurie
 
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
MS SQL SERVER: Sql Functions And Procedures
sqlserver content
 
MS SQL SERVER: Getting Started With Sql Server 2008
sqlserver content
 
The Ultimate Date Time Universe solution (Quick Start and Setup MS SQL Server)
Gino Scheppers
 
MS SQL SERVER: Retrieving Data From A Database
sqlserver content
 
Scenarios
Netresult Ltd
 
MS Sql Server: Joining Databases
DataminingTools Inc
 
Data type[s] on MS SQL Server
Chandan Banerjee
 
MS Sql Server: Introduction To Database Concepts
DataminingTools Inc
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Data that persuades: Annotated - from SES SF 2012
Ian Lurie
 
Ad

Similar to Introducing ms sql_server (20)

PPTX
Introducing ms sql_server_updated
leetinhf
 
PDF
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
PPT
Ms sql server architecture
Ajeet Singh
 
PPT
DB2UDB_the_Basics Day2
Pranav Prakash
 
PPTX
Ms sql server
yajit1
 
PPT
Module02
Sridhar P
 
PPS
05 qmds2005 session07
Niit Care
 
PPTX
7. SQL.pptx
chaitanya149090
 
PPT
Database concepts and Archeticture Ch2 with in class Activities
Zainab Almugbel
 
PPTX
Obevo Javasig.pptx
LadduAnanu
 
PPT
Database Foundation Training
Franky Lao
 
PPTX
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
PPT
Sql server basics
Dilfaroz Khan
 
PPTX
SQL_SERVER_BASIC_1_Training.pptx
KashifManzoorMeo
 
PPTX
Sql server basics
VishalJharwade
 
PPTX
SQL_SERVER_BASIC_1_Training.pptx
QuyVo27
 
PDF
Introduction to Apache Tajo: Data Warehouse for Big Data
Gruter
 
PDF
Data administration
Prof. Erwin Globio
 
PDF
The dr overnight dba
gdabate
 
PDF
Introduction to the Structured Query Language SQL
Harmony Kwawu
 
Introducing ms sql_server_updated
leetinhf
 
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
Ms sql server architecture
Ajeet Singh
 
DB2UDB_the_Basics Day2
Pranav Prakash
 
Ms sql server
yajit1
 
Module02
Sridhar P
 
05 qmds2005 session07
Niit Care
 
7. SQL.pptx
chaitanya149090
 
Database concepts and Archeticture Ch2 with in class Activities
Zainab Almugbel
 
Obevo Javasig.pptx
LadduAnanu
 
Database Foundation Training
Franky Lao
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
Sql server basics
Dilfaroz Khan
 
SQL_SERVER_BASIC_1_Training.pptx
KashifManzoorMeo
 
Sql server basics
VishalJharwade
 
SQL_SERVER_BASIC_1_Training.pptx
QuyVo27
 
Introduction to Apache Tajo: Data Warehouse for Big Data
Gruter
 
Data administration
Prof. Erwin Globio
 
The dr overnight dba
gdabate
 
Introduction to the Structured Query Language SQL
Harmony Kwawu
 
Ad

Recently uploaded (20)

PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 

Introducing ms sql_server

  • 1. Never stop improving quality Microsoft SQL Server LARION_TDT@Internship_03 www.elarion.com
  • 2. Contents Introduction ● Relational Database ● Database management system ● Microsoft SQL server ● Structures of Microsoft SQL server ● How to create index for each record ● Backup, Restore Database ● Stored Procedure, Trigger, Function ● View ● Supporting tools for MS SQL server ● Demo 2
  • 3. Relational Database (1 of 4) Definition ● Relational Database is database that all data are established many tables to have relationship each other. ● Each table consists of many columns and many rows that each column is usually called a register,each row is described an attribute. 3
  • 4. Relational Database (2 of 4) The main components ● The main components :  Table: each table stores information of an object outside real life.  Primary key: a collection of one column or many columns inside tables that it is not permit null data and is only one.  Foreign key: a collection of one column or many columns inside tables that they are a primary of other tables and their data can be permitted null 4
  • 5. Relational Database (3 of 4) Example 1: 5
  • 6. Relational Database (4 of 4) Example 2: 6
  • 7. Database Management System(1 of 3) ● Popular Database Management Systems  MS SQL server  MySQL  Oracle  PostgreSql  DB2  … 7
  • 8. Database Management System(2 of 3) Definition ● Database management system is a software to permit users to create, control and access into database. ● Database management system has maintained consistency of database during its cycle life. 8
  • 9. Database Management System (3 of 3) Function ● The main functions of database management system  Database definition  Database construction  Database manipulation: add , delete...  Database administrator: security...  Database protection: backup, restore 9
  • 10. Mircosoft SQL server(1 of 3) ● MS SQL Server is a database management system that it is established and developed by Microsoft based on Transact-SQL method in order to exchange data between Client and MS SQL Server. 10
  • 11. Mircosoft SQL server(2 of 3) Adaptation ● MS SQL Server is optimized in order to run Very Large Database Environment (VLDE) even though Tera-Byte, especially for serving user thousands ● MS SQL Server can collaborate with other servers such as Microsoft Internet Information Server (IIS), Oracle... 11
  • 12. Mircosoft SQL server (3 of 3) Versions ● Versions of MS SQL Server  Enterprise Edition  Developer Edition  Standard Edition  Workgroup Edition  SQL Server Express Edition 12
  • 13. Mircosoft SQL server(1 of 3) Structure ● One of the most usual structures MS SQL Server  Client / Server Architecture  N-tier Architecture 13
  • 14. Structure of MS SQL server(2 of 3) ● Client / Server Architecture 14
  • 15. Structure of MS SQL server (3 of 3) ● N-tier Architecture 15
  • 16. How to create index for each record(1 of 2) ● Index is used to supporting and improving for accessing more quick to data flows base on value of one or many columns. ● Two forms:  Clustered index  Non-clustered index 16
  • 17. How to create index for each record(2 of 2) ● Syntax: CREATE [CLUSTERED | NONCLUSTERED] INDEX index_name ON table_name(column_name [, column_name]...) ● For example for creating non-clustered index on MADV of NHANVIEN columns: CREATE NONCLUSTERED INDEX idx_nhanvien_madv ON nhanvien(madv) 17
  • 18. Backup, Restore Database(1 of 7) Backup What is Backup Database? ● That is the activity of copying files or databases from SQL server to another storage device. ● Having two backup database forms:  By backup database commands  By direct action in your SQL Server 18
  • 19. Backup, Restore Database(2 of 7) Backup Syntax of Backup Database Commands BACKUP DATABASE { database_name | @database_name_var } TO < backup_device > [ ,...n ] [ WITH [ BLOCKSIZE = { blocksize | @blocksize_variable } ] [ [ , ] DESCRIPTION = { 'text'| @text_variable } ] [ [ , ] DIFFERENTIAL ] [ [ , ] EXPIREDATE = { date | @date_var } | RETAINDAYS = { days | @days_var } ] [ [ , ] FORMAT | NOFORMAT ] [ [ , ] { INIT | NOINIT } ] [ [ , ] MEDIADESCRIPTION = { 'text'| @text_variable } ] [ [ , ] MEDIANAME = { media_name | @media_name_variable } ] [ [ , ] NAME = { backup_set_name | @backup_set_name_var } ] [ [ , ] { NOSKIP | SKIP } ] [ [ , ] { NOUNLOAD | UNLOAD } ] [ [ , ] RESTART ] [ [ , ] STATS [ =percentage ] ] ] 19
  • 20. Backup, Restore Database(3 of 7) Backup Description ° BLOCKSIZE: automatic parameter ° DIFFERENTIAL: differential backup is only necessary change datas ° EXPIREDATE: expiration of backup day ° FORMAT/NOFORMAT: destroying existing datas or not ° INIT/NOINIT: replace datas or not ° DESCRIPTION: details of description ° STATS: appearance of programbar 20
  • 21. Backup, Restore Database(4 of 7) Backup For example backup database BACKUP DATABASE QLNGK TO DISK= ‘F: ngk.bak’ WITH DESCRIPTION = ‘BACK UP’, STATS GO 21
  • 22. Backup, Restore Database(5 of 7) Backup Result 22
  • 23. Backup, Restore Database(6 of 7) Restore Syntax RESTORE DATABASE { database_name | @database_name_var } [ FROM <backup_device> [ ,...n ] ] [ WITH { [ RECOVERY | NORECOVERY | STANDBY = {standby_file_name | @standby_file_name_var } ] | , <general_WITH_options> [ ,...n ] | , <replication_WITH_option> | , <change_data_capture_WITH_option> | , <service_broker_WITH options> | , <point_in_time_WITH_options—RESTORE_DATABASE> } [ ,...n ] ] [;] 23
  • 24. Backup, Restore Database(end) Restore For example: RESTORE DATABASE users FROM DISK='C:backupusers.BAK' WITH RECOVERY 24
  • 25. Stored Procedure, Trigger (1 of 9) Stored Procedure What is Stored Procedure ? ● SP (Stored Procedure) is the name given to a group of SQL statement is created and stored in the server database. ● SP allows transmission parameters, and may be called by many clients over the network with different parameters. When SP is changed, all clients will automatically receive the new version, because the SP is stored at the Server, not Client. 25
  • 26. Stored Procedure, Trigger (2 of 9) Stored Procedure Creating procedure CREATE PROCEDURE procedure_name [;number] [([parameter1] [,parameter2]...[parameter255])] AS sql_statements 26
  • 27. Stored Procedure, Trigger (3 of 9) Stored Procedure For example CREATE PROCEDURE sp_users_insert (@firstname varchar(50), @lastname varchar(50), @birthday date, @groupid int) AS BEGIN if exists(select groupid from groups where groupid = @groupid) BEGIN insert into users(firstname, lastname, birthday, groupid) values(@firstname,@lastname,@birthday,@groupid) END END 27
  • 28. Stored Procedure, Trigger (4 of 9) Trigger ● Trigger is a data type that is specific saved. Otherwise, trigger to help ensure data integrity. ● A table has maximum 3 trigger types:  Update trigger  Insert trigger  Delete trigger ● For example: employer salary is not permitted higher than his top-banana 28
  • 29. Stored Procedure, Trigger (5 of 9) Trigger Syntax: CREATE TRIGGER trigger_name ON table_name | view_name [WITH ENCRYPTION] {FOR | AFTER | INSTEAD OF}{ [INSERT] [,] [UPDATE ] [,] [DELETE] } AS sql_statements 29
  • 30. Stored Procedure, Trigger (6 of 9) Trigger CREATE TRIGGER groups_users_delete on groups for delete as BEGIN DECLARE @groupid int; Set @groupid=(Select groupid from DELETED); delete from users where groupid = @groupid END 30
  • 31. Stored Procedure, Trigger (7 of 9) Function Function is database object similar procedures . However,the difference between procedures and function that function returns to a value via its function name while procedures do not. 31
  • 32. Stored Procedure, Trigger (8 of 9) Trigger Syntax CREATE FUNCTION [ schema_name. ] function_name ( [ { @parameter_name [ AS ] [ type_schema_name. ] parameter_data_type [ = default ] [ READONLY ] } [ ,...n ]S ] ) RETURNS return_data_type [ WITH <function_option> [ ,...n ] ] [ AS ] BEGIN function_body RETURN scalar_expression END [;] 32
  • 33. Stored Procedure, Trigger (end) Trigger For example CREATE FUNCTION f_users_tong() RETURNS @bangthongke TABLE (groupid int,groupname varchar(50),tonguser INT) AS BEGIN INSERT INTO @bangthongke SELECT groups.groupid,groups.groupname,COUNT(userid) FROM (groups INNER JOIN users ON groups.groupid = users.groupid) GROUP BY groups.groupid,groups.groupname RETURN END 33
  • 34. View(1 of 4) Definition ● View is a method that we can watch at data into one or many tables of database. ● View is a virtual screen that it is created as a union of rows and columns by one or many different tables. ● Decreasing more complex in database 34
  • 35. View(2 of 4) Syntax: CREATE VIEW COMMAND used to create view: CREATE VIEW <virtual_name_table> AS <select_statement> 35
  • 36. View(3 of 4) For example: CREATE VIEW DSSV AS SELECT masv, hodem, ten, DATEDIFF (YY, ngaysinh,GETDATE()) AS tuoi, tenlop FROM sinhvien, lop 36
  • 38. Supportting tools for MS SQL Server One of the most popular supporting tools for MS SQL sever is SQL Assistant .You can download from link http://www.softpedia.com/progDownload/SoftTree-SQL-Assistant-Download-92428.html 38
  • 39. Demo ● How to use Diagram ● Decentralized ● Backup ● Restore ● Function ● Store Procedure ● Trigger 39
  • 40. Reference ● Document of LARION_TDT@internship_02 Courses ● Website: www.msdn.microsoft.com 40