SQL Server Version installation
VerifiedAdded on 2022/08/13
|47
|2567
|16
AI Summary
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/7fe611e6-32c3-47ca-b277-6fa070416a92-page-1.webp)
Running head: MS SQL SERVER
MS SQL Server
Name of the Student:
Name of the University:
Author Note
MS SQL Server
Name of the Student:
Name of the University:
Author Note
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/d6b980d2-2e32-40f7-b070-0a17210bd606-page-2.webp)
1
MS SQL SERVER
Week 1 - Getting started
SQL Server dev Version installation
The screenshots for the step by step installation of the SQL Server dev version has been
described below:
MS SQL SERVER
Week 1 - Getting started
SQL Server dev Version installation
The screenshots for the step by step installation of the SQL Server dev version has been
described below:
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/7a6de84d-af1e-4907-b1fb-cf4f4382440e-page-3.webp)
2
MS SQL SERVER
MS SQL SERVER
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/c903a582-5b04-4707-9dac-d3288efe8aec-page-4.webp)
3
MS SQL SERVER
MS SQL SERVER
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/6a97ce6b-5101-42d3-bc36-52f6275bcd5c-page-5.webp)
4
MS SQL SERVER
MS SQL SERVER
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/91386298-7018-431d-a577-c769bc33032c-page-6.webp)
5
MS SQL SERVER
MS SQL SERVER
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/b0d2cf5f-7da0-46a4-b3bd-122b3279147e-page-7.webp)
6
MS SQL SERVER
Introduction to Server configuration manager
The tools associated with the SQL Severs are being managed with the help of the SQL
Server configurations manager. The network protocols associated with the server and the server
itself is configured with the help of this tool.
MS SQL SERVER
Introduction to Server configuration manager
The tools associated with the SQL Severs are being managed with the help of the SQL
Server configurations manager. The network protocols associated with the server and the server
itself is configured with the help of this tool.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/e1912949-b8af-4716-bd03-45132dc22185-page-8.webp)
7
MS SQL SERVER
All the instances of the servers are available for the users to view and manage with the
help of this tool.
Architecture of SQL Server versus Access
The MS access database utilizes the file servers design where the details of the database
can be adjusted within a single file. On the other hand, the SQL Server provides the option of a
client server architecture, which provide the option of a centralized database.
MS SQL SERVER
All the instances of the servers are available for the users to view and manage with the
help of this tool.
Architecture of SQL Server versus Access
The MS access database utilizes the file servers design where the details of the database
can be adjusted within a single file. On the other hand, the SQL Server provides the option of a
client server architecture, which provide the option of a centralized database.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/ac1d623b-c85d-4e1a-8a0a-821bc7890634-page-9.webp)
8
MS SQL SERVER
Kware Script explanation
The Kware Script runs without any errors and the Kware database is created. However, it
is seen that Kware database only has 4 table. The customer, Products, SalesOrder,
SalesOrderProduct tables are the ones which has been created.
MS SQL SERVER
Kware Script explanation
The Kware Script runs without any errors and the Kware database is created. However, it
is seen that Kware database only has 4 table. The customer, Products, SalesOrder,
SalesOrderProduct tables are the ones which has been created.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/259b90cf-0d55-47da-a308-fc7a5159304f-page-10.webp)
9
MS SQL SERVER
Create table statements, Data types
Supplier Table is created
USE [Kware]
GO
/****** Object: Table [dbo].[Supplier] Script Date: 2/15/2020 1:07:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Supplier](
[SID] [int] NOT NULL,
[Code] [nvarchar](50) NULL,
[Name] [nvarchar](50) NULL,
CONSTRAINT [PK_Supplier] PRIMARY KEY CLUSTERED
(
MS SQL SERVER
Create table statements, Data types
Supplier Table is created
USE [Kware]
GO
/****** Object: Table [dbo].[Supplier] Script Date: 2/15/2020 1:07:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Supplier](
[SID] [int] NOT NULL,
[Code] [nvarchar](50) NULL,
[Name] [nvarchar](50) NULL,
CONSTRAINT [PK_Supplier] PRIMARY KEY CLUSTERED
(
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/6b3f44a3-8b63-40a5-9f48-ecad7c552c1b-page-11.webp)
10
MS SQL SERVER
[SID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
Purchase Order table is created
USE [Kware]
GO
/****** Object: Table [dbo].[PurchaseOrder] Script Date: 2/15/2020 1:08:35 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PurchaseOrder](
[POID] [int] NOT NULL,
MS SQL SERVER
[SID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
Purchase Order table is created
USE [Kware]
GO
/****** Object: Table [dbo].[PurchaseOrder] Script Date: 2/15/2020 1:08:35 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PurchaseOrder](
[POID] [int] NOT NULL,
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/a5a9b4b3-cb9f-4815-916c-e42341226544-page-12.webp)
11
MS SQL SERVER
[SID] [int] NOT NULL,
[Numbr] [numeric](18, 0) NOT NULL,
[Date] [datetime] NOT NULL,
[FullPrice] [money] NOT NULL,
[Status] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_ProductOrder] PRIMARY KEY CLUSTERED
(
[POID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PurchaseOrder] WITH CHECK ADD CONSTRAINT
[FK_ProductOrder_Supplier] FOREIGN KEY([SID])
REFERENCES [dbo].[Supplier] ([SID])
GO
MS SQL SERVER
[SID] [int] NOT NULL,
[Numbr] [numeric](18, 0) NOT NULL,
[Date] [datetime] NOT NULL,
[FullPrice] [money] NOT NULL,
[Status] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_ProductOrder] PRIMARY KEY CLUSTERED
(
[POID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PurchaseOrder] WITH CHECK ADD CONSTRAINT
[FK_ProductOrder_Supplier] FOREIGN KEY([SID])
REFERENCES [dbo].[Supplier] ([SID])
GO
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/1e004722-9509-4de8-bf89-fcbcc0496481-page-13.webp)
12
MS SQL SERVER
ALTER TABLE [dbo].[PurchaseOrder] CHECK CONSTRAINT [FK_ProductOrder_Supplier]
GO
USE [Kware]
GO
/****** Object: Table [dbo].[PurchaseOrderProduct] Script Date: 2/15/2020 1:09:11 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PurchaseOrderProduct](
[POPID] [int] NOT NULL,
[POID] [int] NOT NULL,
[PID] [int] NOT NULL,
[ItemPrice] [money] NOT NULL,
[NbrItemsRequested] [numeric](18, 0) NOT NULL,
MS SQL SERVER
ALTER TABLE [dbo].[PurchaseOrder] CHECK CONSTRAINT [FK_ProductOrder_Supplier]
GO
USE [Kware]
GO
/****** Object: Table [dbo].[PurchaseOrderProduct] Script Date: 2/15/2020 1:09:11 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PurchaseOrderProduct](
[POPID] [int] NOT NULL,
[POID] [int] NOT NULL,
[PID] [int] NOT NULL,
[ItemPrice] [money] NOT NULL,
[NbrItemsRequested] [numeric](18, 0) NOT NULL,
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/76b0f9d2-049e-4767-9cad-0b5527ab994e-page-14.webp)
13
MS SQL SERVER
[ExtendedPrice] [money] NOT NULL,
[NbrItemsReceived] [numeric](18, 0) NOT NULL,
CONSTRAINT [PK_PurchaseOrderProduct] PRIMARY KEY CLUSTERED
(
[POPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PurchaseOrderProduct] WITH CHECK ADD CONSTRAINT
[FK_PurchaseOrderProduct_Product] FOREIGN KEY([PID])
REFERENCES [dbo].[Product] ([PID])
GO
ALTER TABLE [dbo].[PurchaseOrderProduct] CHECK CONSTRAINT
[FK_PurchaseOrderProduct_Product]
GO
MS SQL SERVER
[ExtendedPrice] [money] NOT NULL,
[NbrItemsReceived] [numeric](18, 0) NOT NULL,
CONSTRAINT [PK_PurchaseOrderProduct] PRIMARY KEY CLUSTERED
(
[POPID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON,
OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PurchaseOrderProduct] WITH CHECK ADD CONSTRAINT
[FK_PurchaseOrderProduct_Product] FOREIGN KEY([PID])
REFERENCES [dbo].[Product] ([PID])
GO
ALTER TABLE [dbo].[PurchaseOrderProduct] CHECK CONSTRAINT
[FK_PurchaseOrderProduct_Product]
GO
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/1728daef-c9c4-47f2-bc96-213a159f503b-page-15.webp)
14
MS SQL SERVER
ALTER TABLE [dbo].[PurchaseOrderProduct] WITH CHECK ADD CONSTRAINT
[FK_PurchaseOrderProduct_PurchaseOrder] FOREIGN KEY([POID])
REFERENCES [dbo].[PurchaseOrder] ([POID])
GO
ALTER TABLE [dbo].[PurchaseOrderProduct] CHECK CONSTRAINT
[FK_PurchaseOrderProduct_PurchaseOrder]
GO
Primary/foreign/check constraints
Supplier
MS SQL SERVER
ALTER TABLE [dbo].[PurchaseOrderProduct] WITH CHECK ADD CONSTRAINT
[FK_PurchaseOrderProduct_PurchaseOrder] FOREIGN KEY([POID])
REFERENCES [dbo].[PurchaseOrder] ([POID])
GO
ALTER TABLE [dbo].[PurchaseOrderProduct] CHECK CONSTRAINT
[FK_PurchaseOrderProduct_PurchaseOrder]
GO
Primary/foreign/check constraints
Supplier
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/11e97cca-586d-4aa2-8cea-f84bf3a6ac88-page-16.webp)
15
MS SQL SERVER
Purchase Order
MS SQL SERVER
Purchase Order
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/ffac9344-4bb5-485e-946f-b44a401a1a0c-page-17.webp)
16
MS SQL SERVER
Purchase Order Product
MS SQL SERVER
Purchase Order Product
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/547bf577-bcfc-4b14-8159-f165c5e3d650-page-18.webp)
17
MS SQL SERVER
Homework
Customer
Product
MS SQL SERVER
Homework
Customer
Product
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/41659775-7eee-4cbe-afd1-f3ab78e7bb33-page-19.webp)
18
MS SQL SERVER
Purchase Order
Purchase Order Product
Sales Order
Sales Order Product
MS SQL SERVER
Purchase Order
Purchase Order Product
Sales Order
Sales Order Product
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/ddfd5d04-bf1e-4820-9ffd-8a8c3ea675a3-page-20.webp)
19
MS SQL SERVER
Suppliers
Week 2 - Creating db structure
Introduce alter table statements
ALTER TABLE Customer
ADD DOB datetime;
UPDATE Customer
SET Customer.DOB = 2010-01-01
Where Customer.CID = 2 OR Customer.CID = 4 OR Customer.CID = 6;
UPDATE Customer
SET Customer.DOB = 2009-01-01
MS SQL SERVER
Suppliers
Week 2 - Creating db structure
Introduce alter table statements
ALTER TABLE Customer
ADD DOB datetime;
UPDATE Customer
SET Customer.DOB = 2010-01-01
Where Customer.CID = 2 OR Customer.CID = 4 OR Customer.CID = 6;
UPDATE Customer
SET Customer.DOB = 2009-01-01
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/d1e67fc5-b3dd-47e2-b77a-318b00a4a177-page-21.webp)
20
MS SQL SERVER
Where Customer.CID = 1 OR Customer.CID = 3 OR Customer.CID = 5;
UPDATE Customer
SET Email = 'sanbinder.malhi@cqumail.com'
;
Homework
Select * from Customers;
The single table SQL has been obtained here. It is not possible to back up a single table
from a database, however, the table can be copied into a new database created.
Week 3 - Introducing TSQL and advanced SQL
Print Statements
The Print statement returns a user-defined message to the client.
SELECT Statements
This command is used for retrieving an number of rows from a database and in addition
to this, provides the options of selecting a number of tables from the other columns.
String Concatenations
The concatenation function is used for adding up of two strings in the single data form.
MS SQL SERVER
Where Customer.CID = 1 OR Customer.CID = 3 OR Customer.CID = 5;
UPDATE Customer
SET Email = 'sanbinder.malhi@cqumail.com'
;
Homework
Select * from Customers;
The single table SQL has been obtained here. It is not possible to back up a single table
from a database, however, the table can be copied into a new database created.
Week 3 - Introducing TSQL and advanced SQL
Print Statements
The Print statement returns a user-defined message to the client.
SELECT Statements
This command is used for retrieving an number of rows from a database and in addition
to this, provides the options of selecting a number of tables from the other columns.
String Concatenations
The concatenation function is used for adding up of two strings in the single data form.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/7c79b7d1-862b-4c73-8b79-d7b4ecf6d97d-page-22.webp)
21
MS SQL SERVER
Date Calculations
The date calculations are helping for fetching data such as the current date and the
difference in between two dates.
Advanced SQL
The advanced sql commands involves the complex groups involving the where command
and additionally including the explicit and implicit joins.
Homework
1
a.
Select Customer.Name, SalesOrder.* From Customer Inner Join SalesOrder On Customer.CID =
SalesOrder.CID;
b.
Select Customer.Name, SalesOrder.* From Customer, SalesOrder
Where Customer.CID = SalesOrder.CID;
MS SQL SERVER
Date Calculations
The date calculations are helping for fetching data such as the current date and the
difference in between two dates.
Advanced SQL
The advanced sql commands involves the complex groups involving the where command
and additionally including the explicit and implicit joins.
Homework
1
a.
Select Customer.Name, SalesOrder.* From Customer Inner Join SalesOrder On Customer.CID =
SalesOrder.CID;
b.
Select Customer.Name, SalesOrder.* From Customer, SalesOrder
Where Customer.CID = SalesOrder.CID;
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/2aa1f659-f1ee-45d0-a773-6d24bff6c062-page-23.webp)
22
MS SQL SERVER
c.
CREATE OR ALTER FUNCTION new_func (@name nvarchar(50), @id int)
RETURNS TABLE As
RETURN (Select Customer.Name, SalesOrder.* From Customer Inner Join SalesOrder
On Customer.CID = SalesOrder.CID
Where Customer.Name = @name)
2
Select * From
Product
Where Description LIKE '%saucepan%' AND Price > 70.00 OR Description LIKE '%goblet%'
AND Price > 70.00;
3
a.
MS SQL SERVER
c.
CREATE OR ALTER FUNCTION new_func (@name nvarchar(50), @id int)
RETURNS TABLE As
RETURN (Select Customer.Name, SalesOrder.* From Customer Inner Join SalesOrder
On Customer.CID = SalesOrder.CID
Where Customer.Name = @name)
2
Select * From
Product
Where Description LIKE '%saucepan%' AND Price > 70.00 OR Description LIKE '%goblet%'
AND Price > 70.00;
3
a.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/2e668f94-2693-4a69-8f4a-ce6459ea1dbf-page-24.webp)
23
MS SQL SERVER
Select * From Customer, SalesOrder, Product, SalesOrderProduct
Where Customer.CID = SalesOrder.CID and SalesOrder.SOID = SalesOrderProduct.SOID and
SalesOrderProduct.PID = Product.PID and Product.Description LIKE '%saucepan%';
b.
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
Inner Join Product On SalesOrderProduct.PID = Product.PID
Where Product.Description LIKE '%saucepan%';
c.
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
MS SQL SERVER
Select * From Customer, SalesOrder, Product, SalesOrderProduct
Where Customer.CID = SalesOrder.CID and SalesOrder.SOID = SalesOrderProduct.SOID and
SalesOrderProduct.PID = Product.PID and Product.Description LIKE '%saucepan%';
b.
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
Inner Join Product On SalesOrderProduct.PID = Product.PID
Where Product.Description LIKE '%saucepan%';
c.
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/b85e80cb-8938-4dd2-9f52-86f8379d24be-page-25.webp)
24
MS SQL SERVER
Where SalesOrderProduct.PID IN (Select PID From Product Where Description LIKE
'%saucepan%');
d.
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
AND EXISTS (Select PID From Product Where Description LIKE '%saucepan%');
4
The preceding question is difficult to answer over time as the results would provide a
huge set of data and hence, it can be recommended that explicit join can be used for obtaining
the result.
5
a.
MS SQL SERVER
Where SalesOrderProduct.PID IN (Select PID From Product Where Description LIKE
'%saucepan%');
d.
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
AND EXISTS (Select PID From Product Where Description LIKE '%saucepan%');
4
The preceding question is difficult to answer over time as the results would provide a
huge set of data and hence, it can be recommended that explicit join can be used for obtaining
the result.
5
a.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/34623728-e8e5-4093-a03c-b6e2bf0226c8-page-26.webp)
25
MS SQL SERVER
Select Customer.Name, COUNT(SalesOrder.SOID) From Customer Inner Join SalesOrder On
Customer.CID = SalesOrder.CID
Group By Customer.Name;
b.
CREATE OR ALTER FUNCTION new_count(@names nvarchar(50))
RETURNS TABLE As
RETURN (Select Customer.Name, COUNT(SalesOrder.SOID) As Count From
Customer Inner Join SalesOrder On Customer.CID = SalesOrder.CID
Where Customer.Name = @names
Group By Customer.Name)
6
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
Inner Join Product On SalesOrderProduct.PID = Product.PID
Where SalesOrderProduct.NbrItemsRequested > SalesOrderProduct.NbrItemsDispatched AND
Product.NbrItemsInStock > 0;
MS SQL SERVER
Select Customer.Name, COUNT(SalesOrder.SOID) From Customer Inner Join SalesOrder On
Customer.CID = SalesOrder.CID
Group By Customer.Name;
b.
CREATE OR ALTER FUNCTION new_count(@names nvarchar(50))
RETURNS TABLE As
RETURN (Select Customer.Name, COUNT(SalesOrder.SOID) As Count From
Customer Inner Join SalesOrder On Customer.CID = SalesOrder.CID
Where Customer.Name = @names
Group By Customer.Name)
6
Select * From Customer
Inner Join SalesOrder On Customer.CID = SalesOrder.CID Inner join SalesOrderProduct On
SalesOrder.SOID = SalesOrderProduct.SOID
Inner Join Product On SalesOrderProduct.PID = Product.PID
Where SalesOrderProduct.NbrItemsRequested > SalesOrderProduct.NbrItemsDispatched AND
Product.NbrItemsInStock > 0;
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/6fc4d713-c7b5-45ca-89fc-fcd9f855dce1-page-27.webp)
26
MS SQL SERVER
7 It is difficult to answer this question 100% accurately, because is the calendar is not uniform
throughout the database system. Hence, the exact answer to clients who are over 18 can not be
found.
Week 4 - database mail, cursors, stored procedures
Mail Profiles
MS SQL SERVER
7 It is difficult to answer this question 100% accurately, because is the calendar is not uniform
throughout the database system. Hence, the exact answer to clients who are over 18 can not be
found.
Week 4 - database mail, cursors, stored procedures
Mail Profiles
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/d25df46c-6928-453f-a428-14120b110c4d-page-28.webp)
27
MS SQL SERVER
MS SQL SERVER
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/aeb5da5d-b1f7-4d9a-b1ea-9e02066ca028-page-29.webp)
28
MS SQL SERVER
MS SQL SERVER
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/f3a2fdde-85f5-463c-8e16-84eceba1dcd8-page-30.webp)
29
MS SQL SERVER
db_send_mail statement
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
N'<H1>Customer Report</H1>' +
N'<table border="1">' +
N'<tr><th>CID</th><th>Name</th>' +
MS SQL SERVER
db_send_mail statement
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
N'<H1>Customer Report</H1>' +
N'<table border="1">' +
N'<tr><th>CID</th><th>Name</th>' +
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/4e9c8abb-14c0-4525-8f99-90025a4f605d-page-31.webp)
30
MS SQL SERVER
N'<th>Street</th><th>Suburb</th><th>State</th>' +
N'<th>Postcode</th></tr>' +
CAST ( ( SELECT td = CID, '',
td = Name, '',
td = Street, '',
td = Suburb, '',
td = State, '',
td = Postcode
FROM Customer
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'student',
@recipients='sanbinder.malhi@cqumail.com',
@subject = 'Work Order List',
@body = @tableHTML,
MS SQL SERVER
N'<th>Street</th><th>Suburb</th><th>State</th>' +
N'<th>Postcode</th></tr>' +
CAST ( ( SELECT td = CID, '',
td = Name, '',
td = Street, '',
td = Suburb, '',
td = State, '',
td = Postcode
FROM Customer
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'student',
@recipients='sanbinder.malhi@cqumail.com',
@subject = 'Work Order List',
@body = @tableHTML,
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/101f08df-0082-4238-a831-fd42e8ab7893-page-32.webp)
31
MS SQL SERVER
@body_format = 'HTML' ;
Cursors
For the execution of the SQL statements the database engines a work area is used and the
cursors allows the users for naming the area of work and accesses the information which are
stored in it. It is used in database for the retrieving the data, which is single row at a single time.
Create procedure statement
The stored procedures are used for creating an automated function which would be
triggered when the conditions arise.
USE [Kware]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROCEDURE usp_SendEmail
MS SQL SERVER
@body_format = 'HTML' ;
Cursors
For the execution of the SQL statements the database engines a work area is used and the
cursors allows the users for naming the area of work and accesses the information which are
stored in it. It is used in database for the retrieving the data, which is single row at a single time.
Create procedure statement
The stored procedures are used for creating an automated function which would be
triggered when the conditions arise.
USE [Kware]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROCEDURE usp_SendEmail
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/60b6a7e6-9dfd-4b84-950c-c566d077c773-page-33.webp)
32
MS SQL SERVER
AS
Declare @email nvarchar(128)
Declare @name nvarchar(128)
Declare @Date date
SELECT GETDATE(), Month(GetDate()), Day(GetDate()), Year(GetDate())
DECLARE rcpt_cursor CURSOR FOR
select
Name,
Email
from dbo.Customer a
where Month(DOB) = Month(GetDate())
and Day(DOB) = Day(GetDate())
MS SQL SERVER
AS
Declare @email nvarchar(128)
Declare @name nvarchar(128)
Declare @Date date
SELECT GETDATE(), Month(GetDate()), Day(GetDate()), Year(GetDate())
DECLARE rcpt_cursor CURSOR FOR
select
Name,
from dbo.Customer a
where Month(DOB) = Month(GetDate())
and Day(DOB) = Day(GetDate())
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/9fd3069a-5a8e-45ad-8f9b-82f8c5b5d929-page-34.webp)
33
MS SQL SERVER
OPEN rcpt_cursor
FETCH NEXT FROM rcpt_cursor
INTO @name,@email
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @email
Declare @subject nvarchar(255)
Declare @Bodytext nvarchar(512)
Set @BodyText = @Name + '' + ' has a birthday today.'
Set @Subject = 'Happy Birthday'
exec msdb.dbo.sp_send_dbmail
MS SQL SERVER
OPEN rcpt_cursor
FETCH NEXT FROM rcpt_cursor
INTO @name,@email
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @email
Declare @subject nvarchar(255)
Declare @Bodytext nvarchar(512)
Set @BodyText = @Name + '' + ' has a birthday today.'
Set @Subject = 'Happy Birthday'
exec msdb.dbo.sp_send_dbmail
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/d7f27a07-8c9b-416a-b9a6-43c8b70b273d-page-35.webp)
34
MS SQL SERVER
@Profile_Name = 'HappyBirthday',
@Recipients = @email,
@Body = @BodyText,
@Subject = @Subject
FETCH NEXT FROM rcpt_cursor
INTO @name,@email
END
CLOSE rcpt_cursor
DEALLOCATE rcpt_cursor
Go
Exec usp_SendEmail
MS SQL SERVER
@Profile_Name = 'HappyBirthday',
@Recipients = @email,
@Body = @BodyText,
@Subject = @Subject
FETCH NEXT FROM rcpt_cursor
INTO @name,@email
END
CLOSE rcpt_cursor
DEALLOCATE rcpt_cursor
Go
Exec usp_SendEmail
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/4c13f7ac-4b84-4b46-a8d2-41e8ca93ca81-page-36.webp)
35
MS SQL SERVER
SQL jobs
In a SQL Server Agent job the integration service packages are schedules and the type of
integrations are required to be stored for the jobs.
Homework
Week 5 – triggers
Triggers
use kware
go
drop table if exists [Audit]
go
MS SQL SERVER
SQL jobs
In a SQL Server Agent job the integration service packages are schedules and the type of
integrations are required to be stored for the jobs.
Homework
Week 5 – triggers
Triggers
use kware
go
drop table if exists [Audit]
go
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/8ce81067-7812-46b6-a645-e130827d77ed-page-37.webp)
36
MS SQL SERVER
create table [Audit]
(
Action varchar(10)
, [User] varchar(50)
, Timestamp datetime
, [Table] varchar(50)
, NameBefore nvarchar(255)
, NameAfter nvarchar(255)
)
-- exec resetsampledata
drop trigger if exists tr_Customer_audit_insert
go
create trigger tr_Customer_audit_insert
on customer
after insert
MS SQL SERVER
create table [Audit]
(
Action varchar(10)
, [User] varchar(50)
, Timestamp datetime
, [Table] varchar(50)
, NameBefore nvarchar(255)
, NameAfter nvarchar(255)
)
-- exec resetsampledata
drop trigger if exists tr_Customer_audit_insert
go
create trigger tr_Customer_audit_insert
on customer
after insert
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/177a954b-7e40-4a35-aa3f-98c445240f68-page-38.webp)
37
MS SQL SERVER
as
begin
declare @Name as varchar(255)
select @Name = Name from inserted
insert into [Audit] (Action, [user], Timestamp, [Table], NameAfter)
values ( 'Insert', SYSTEM_USER, getdate(), 'Customer', @Name)
end
GO
DROP TRIGGER IF exists tr_Customer_audit_delete
go
CREATE TRIGGER tr_Customer_audit_delete
ON Customer
MS SQL SERVER
as
begin
declare @Name as varchar(255)
select @Name = Name from inserted
insert into [Audit] (Action, [user], Timestamp, [Table], NameAfter)
values ( 'Insert', SYSTEM_USER, getdate(), 'Customer', @Name)
end
GO
DROP TRIGGER IF exists tr_Customer_audit_delete
go
CREATE TRIGGER tr_Customer_audit_delete
ON Customer
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/849bb034-2277-41ae-a305-771913b56e6c-page-39.webp)
38
MS SQL SERVER
AFTER DELETE
AS
BEGIN
DECLARE @Name AS varchar(255)
SELECT @Name = Name FROM deleted
INSERT INTO [Audit] (Action, [User], Timestamp, [Table], NameAfter)
VALUES ('Delete', SYSTEM_USER, GETDATE(), 'Customer', @Name)
END
MS SQL SERVER
AFTER DELETE
AS
BEGIN
DECLARE @Name AS varchar(255)
SELECT @Name = Name FROM deleted
INSERT INTO [Audit] (Action, [User], Timestamp, [Table], NameAfter)
VALUES ('Delete', SYSTEM_USER, GETDATE(), 'Customer', @Name)
END
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/ad570773-6b58-492a-b5db-af27e3f382de-page-40.webp)
39
MS SQL SERVER
On update of Product, if discount changed, then recalculate FinalPrice
CREATE TRIGGER pro_dis
ON SalesOrder
AFTER INSERT, UPDATE
AS
UPDATE SalesOrder SET FinalPrice = FullPrice - Discount
GO
Homework
CREATE TRIGGER pro_price
ON SalesOrderProduct
AFTER INSERT, UPDATE
AS
UPDATE SalesOrderProduct SET ExtendedPrice = ItemPrice*NbrItemsRequested
GO
Week 6 - design choice
The designing of the database has been done as per the normal forms. Hence, the tables
contain atomic value. Therefor the second address cannot be added. Hence, as a solution an
additional column is required to added into the system.
The updated Supplier table is described below:
MS SQL SERVER
On update of Product, if discount changed, then recalculate FinalPrice
CREATE TRIGGER pro_dis
ON SalesOrder
AFTER INSERT, UPDATE
AS
UPDATE SalesOrder SET FinalPrice = FullPrice - Discount
GO
Homework
CREATE TRIGGER pro_price
ON SalesOrderProduct
AFTER INSERT, UPDATE
AS
UPDATE SalesOrderProduct SET ExtendedPrice = ItemPrice*NbrItemsRequested
GO
Week 6 - design choice
The designing of the database has been done as per the normal forms. Hence, the tables
contain atomic value. Therefor the second address cannot be added. Hence, as a solution an
additional column is required to added into the system.
The updated Supplier table is described below:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/1aecf18e-7968-431e-b4b8-e49f61773ba4-page-41.webp)
40
MS SQL SERVER
The updated product table is providing below:
The following error was received.
Homework
The ER Model has been described below:
MS SQL SERVER
The updated product table is providing below:
The following error was received.
Homework
The ER Model has been described below:
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/aa6aa82b-3055-4c16-9dfb-1b85667c9bf3-page-42.webp)
41
MS SQL SERVER
Week 7 - Why subtypes are a bad idea
A single table is a better option to have than that subtypes as one-to-one data as there
might be thousand number of rows and columns therefore it is very difficult to reduce the data
which are duplicate.
Week 8 - Transactions and try/catch
Try catch helps in handling the errors in an effective way. Transaction is used to maintain
the data integrity.
MS SQL SERVER
Week 7 - Why subtypes are a bad idea
A single table is a better option to have than that subtypes as one-to-one data as there
might be thousand number of rows and columns therefore it is very difficult to reduce the data
which are duplicate.
Week 8 - Transactions and try/catch
Try catch helps in handling the errors in an effective way. Transaction is used to maintain
the data integrity.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/a4eeb9f1-b7dc-4243-a4ae-4d210e589b34-page-43.webp)
42
MS SQL SERVER
Week 9 - Users, logons and security
Logons are used for the purpose of giving better security. this ensures that authentication
is being performed properly at every instance level
Week 10 - Application front end stuff
MS SQL SERVER
Week 9 - Users, logons and security
Logons are used for the purpose of giving better security. this ensures that authentication
is being performed properly at every instance level
Week 10 - Application front end stuff
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/93454a7b-4c6f-412a-9d1e-7f691f78e862-page-44.webp)
43
MS SQL SERVER
MS SQL SERVER
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/a74ca52f-8a4a-400e-865e-4c1b968d6781-page-45.webp)
44
MS SQL SERVER
MS SQL SERVER
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/90ce8f02-5193-4785-88e1-8026327064bc-page-46.webp)
45
MS SQL SERVER
MS SQL SERVER
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
![Document Page](https://desklib.com/media/document/docfile/pages/ms-sql-server-20-20-ms-sql-server/2024/09/13/8b66473a-96b7-4504-a5f3-a0b2b7945062-page-47.webp)
46
MS SQL SERVER
Week 11 - Backup and recovery SQL-server style
A set of one or more than one backup media is consisting of a single media set. An ordered
collection of backup media is known as a collection of the backup media. A number of such
media is known as the backup media family.
MS SQL SERVER
Week 11 - Backup and recovery SQL-server style
A set of one or more than one backup media is consisting of a single media set. An ordered
collection of backup media is known as a collection of the backup media. A number of such
media is known as the backup media family.
1 out of 47
Related Documents
![[object Object]](/_next/image/?url=%2F_next%2Fstatic%2Fmedia%2Flogo.6d15ce61.png&w=640&q=75)
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.