This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
GO | |
/****** Object: Database [Store] Script Date: 03.02.2025 23:21:19 ******/ | |
CREATE DATABASE [Store] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N'Store', FILENAME = N'C:\datab\Store.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB ) | |
LOG ON | |
( NAME = N'Store_log', FILENAME = N'C:\datab\Store_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) | |
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Store; | |
SELECT * | |
FROM Product | |
ORDER BY date_of_delivery | |
-- 1. Посчитать возможную выручку за Phones и Tablet (с учётом скидок на эти товары) | |
SELECT | |
category, | |
SUM(ROUND(price - (price * discount/ 100), 2) * quantity ) AS [total price] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
GO | |
/****** Object: Database [Storik] Script Date: 11.02.2025 23:49:06 ******/ | |
CREATE DATABASE [Storik] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N'Storik', FILENAME = N'C:\datab\Storik.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB ) | |
LOG ON | |
( NAME = N'Storik_log', FILENAME = N'C:\datab\Storik_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) | |
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Storik | |
-- INNER JOINS: | |
-- 1. Показать названия и категории товаров, поставщиками которых являются ООО "Паньки" или ООО «Какие люди» | |
SELECT | |
p.name AS product_name, | |
c.name AS category_name, | |
pr.name AS producer_name | |
FROM Product p | |
JOIN Category c ON p.id_category = c.id | |
JOIN Producer pr ON pr.id = p.id_producer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Storik | |
-- 1. Показать товары, средняя цена продажи которых была больше 500 | |
SELECT p.name, p.price, c.name AS category_name, AVG(s.price) AS [avg sale price] | |
FROM Product p | |
JOIN Sale s ON p.id = s.id_product | |
JOIN Category c ON p.id_category = c.id | |
GROUP BY p.name, p.price, c.name | |
HAVING AVG(s.price) > 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Storik | |
-- 1. Показать самый популярный товар магазина (больше всего раз продавался) | |
SELECT TOP 1 | |
p.name AS product_name, | |
s.quantity AS sale_quantity | |
FROM Product p | |
JOIN Sale s ON p.id = s.id_product | |
ORDER BY s.quantity DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1. Показать среднее арифметическое трёх вещественных чисел, хранящихся в переменных | |
DECLARE @x float = 10.5, @y float = 8.7, @z float = 1.1 | |
DECLARE @avg float = (@x + @y + @z) / 3 | |
PRINT @avg | |
-- 2. Показать горизонтальную линию из звёздочек длиной @L | |
DECLARE @L int = 10; | |
DECLARE @symb char = '-' | |
DECLARE @start int = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Storik | |
-- 1. Написать хранимую процедуру, которая показывает общее количество проданных товаров в каждой из категорий и от каждого производителя. | |
CREATE PROCEDURE PROC_01 AS | |
SELECT | |
p.name AS product_name, | |
c.name AS category_name, | |
SUM(s.quantity) AS total_sales, | |
pr.name AS producer_name | |
FROM Product p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1. Написать функцию, которая покажет список всех пользовательских баз данных SQL Server, и их общие размеры в байтах | |
CREATE FUNCTION GetUserDBSize() | |
RETURNS TABLE | |
AS RETURN ( | |
SELECT | |
name AS DatabaseName, | |
SUM(size * 8 * 1024) AS TotalSizeBytes | |
FROM sys.master_files | |
WHERE type IN (0) | |
AND database_id > 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.Принцип единственной ответственности (Single Responsibility Principle, SRP) | |
В проекте реализован принцип SRP при использовании класса DataBase. | |
Этот класс отвечает только за работу с подключением к базе данных и не содержит логики, связанной с другими аспектами приложения. | |
Он инкапсулирует операции открытия и закрытия соединения, предоставляя методы OpenConnection() и CloseConnection(), | |
которые используются в других частях приложения. Это способствует разделению ответственности и облегчает сопровождение кода. | |
2. Нарушение принципа SOLID | |
Принцип открытости/закрытости (Open/Closed Principle, OCP) в методе SaveTaskToDatabase() класса AppForm. | |
Этот метод напрямую взаимодействует с базой данных, создавая команду SqlCommand и выполняя запросы. | |
Если в будущем потребуется изменить способ хранения данных (например, использовать другую базу данных), |
OlderNewer