Case Study 3
Case Study 3
Case Study 3
[Continent]
select * from [dbo].[Customers]
select * from [dbo].[Transactions]
1 Display the count of customer in each region who has done the transaction in year
2020
3 Display customer id, region name and transaction amountwhere transaction type is
deposit and transaction amount > 500
5 Display the detail of customer id, region name, transaction type and transaction
amount for the minimum transaction amount in deposit
10 Create a udf to find total of transaction amount for given transaction type
BEGIN TRY
SELECT region_id + region_name from Continent
END TRY
BEGIN CATCH
SELECT ERROR_STATE() AS ErrorState , ERROR_MESSAGE()
ErrorMsg ;
END CATCH;
GO
BEGIN TRY
INSERT INTO Continent values(null,'India')
END TRY
BEGIN CATCH
PRINT 'Error: Insert failed.'
END CATCH
--14 Create a trigger to prevent deleting of a table in a database
CREATE TRIGGER tr_prevent_table_drop
ON DATABASE
FOR DROP_TABLE
AS
BEGIN
RAISERROR ('Table drop is not allowed.', 16, 1)
ROLLBACK;
END;
drop table Continent
SELECT * FROM (
SELECT *,
DENSE_RANK () OVER (
PARTITION BY txn_type
ORDER BY txn_amount DESC
) amount_rank
FROM [dbo].[Transactions]
)t
WHERE amount_rank < 5;
18 Create a pivot table to display the total purchase, withdrawal and deposit for all the
customers.