This file contains 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
SELECT | |
DB_NAME(database_id) AS DatabaseName, | |
SUM(size) * 8 AS SizeInBytes | |
FROM | |
sys.master_files | |
WHERE | |
database_id > 4 | |
GROUP BY | |
database_id | |
ORDER BY |
This file contains 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) | |
SELECT user_id, nick, age, education.name, drinking.name, smoking.name | |
FROM users | |
JOIN education ON users.id_education = education.id | |
JOIN drinking ON users.my_drink = drinking.id | |
JOIN smoking ON users.my_smoke = smoking.id | |
WHERE education.name = 'высшее' AND drinking.name = 'не пью вообще' AND smoking.name = 'не курю' | |
2) | |
SELECT user_id, nick, age, eyescolor.name, haircolor.name, gender.name |
This file contains 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 [Library]; | |
DECLARE @table TABLE ( | |
id INT, | |
first_name VARCHAR(50), | |
last_name VARCHAR(50), | |
role VARCHAR(20), | |
department VARCHAR(20), | |
birthday DATE | |
); |
This file contains 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
DECLARE @string NVARCHAR(1000) | |
DECLARE @word NVARCHAR(50) | |
DECLARE @space INT | |
DECLARE @words TABLE ( | |
word NVARCHAR(50), | |
amount INT | |
) | |
DECLARE cur CURSOR FOR SELECT mess FROM messages | |
OPEN cur | |
FETCH NEXT FROM cur INTO @string |
This file contains 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 @string nvarchar(50) = 'нажал кабан на баклажан' | |
SET @string = REPLACE(@string, ' ', '') | |
IF @string = REVERSE(@string) | |
PRINT 'Строка является палиндромом' | |
ELSE | |
PRINT 'Строка не является палиндромом' | |
2. | |
DECLARE @string nvarchar(100) = 'Алекстандр так любит есть шаурму, что готов есть шаурму каждый день.' |
This file contains 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 @start int = 0 | |
DECLARE @finish int = 5 | |
DECLARE @current int = @start | |
DECLARE @result nvarchar(500) = '' | |
WHILE @current < @finish | |
BEGIN | |
SET @result += '*' | |
SET @current += 1 | |
END |
This file contains 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
2. | |
SELECT c.name, SUM(price * quantity) AS TotalSales | |
FROM Category c | |
JOIN Product p ON c.id = p.id_category | |
WHERE c.name IN ('Мясные', 'Хлебо-булочные') | |
GROUP BY c.name | |
3. |
This file contains 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. | |
SELECT Product.name, Delivery.date_of_delivery, Supplier.name | |
FROM Product | |
JOIN Delivery ON Delivery.id = Product.id_producer | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
2. | |
SELECT Region.name |
This file contains 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. | |
SELECT Product.name, Category.name, Supplier.name | |
FROM Product | |
JOIN Delivery ON Delivery.id = Product.id_producer | |
JOIN Supplier ON Supplier.id = Delivery.id_supplier | |
JOIN Category ON Category.id = Product.id_category | |
WHERE Supplier.name LIKE 'Супер закупка' OR Supplier.name LIKE 'Юж поставка' | |
2. |
This file contains 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: 25.05.2023 21:40:15 ******/ | |
CREATE DATABASE [Store] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N'Store', FILENAME = N'C:\1\Store.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) | |
LOG ON | |
( NAME = N'Store_log', FILENAME = N'C:\1\Store_log.ldf' , SIZE = 1280KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) | |
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF |
NewerOlder