
--
ALTER SERVER ROLE [##MS_ServerStateReader##] ADD MEMBER fabric_login;


--NOTE. CONTROL is a high-level permission in SQL Server that grants comprehensive access to a specific securable. A securable can be a database, schema, table, view, stored procedure, etc.
--Assigning CONTROL to a user for a specific table allows them to manage that table without granting broader permissions across the entire database.
GRANT CONTROL TO fabric_user;

--FROM FABRIC SETTINGS > MANAGE CONNECTION AND GETWAYS 
--CREATE A NEW CONNECTION TO THIS DATABAE USING THE LOGIN/USER CREATED  
--MINIMUM DATABASE PRICING TIER IS STANDARD 100 DTUS 

--CHECK THE TOP HIGHEST WITHDRAWLS SUBCATEGORIES  
SELECT [SubcategoryId],SUM([Withdrawals]) SumWithdrawals
FROM  [fact].[Withdrawals]
GROUP BY [SubcategoryId]
ORDER BY SumWithdrawals DESC 

--LET'S REMOVE ALL RECORDS FROM SUBCATEGORY 1  
DELETE A
FROM  [fact].[Withdrawals] A
WHERE [SubcategoryId] = 1 

--LET'S REMOVE A COLUMN FROM AN EXISTING TABLE 
ALTER TABLE [fact].[Withdrawals] DROP COLUMN [Locked]; 
ALTER TABLE [fact].[Withdrawals] ADD NewColumn INT NULL; 

--LET'S CLONE ONE OF THE TABLES 
select * 
into [fact].[Withdrawals_Number2]
from [fact].[Withdrawals]

--WORHT CONSIDER THAT, ONLY TABLES WITH PRIMARY KEY CAN BE MIRRORED 
ALTER TABLE [fact].[Withdrawals_Number2]
   ADD CONSTRAINT PK_Withdrawals_Number2 PRIMARY KEY CLUSTERED ([SurrogateKey]);
