We have a number of tables in Azure Synapse database with Round Robin distribution. Due to performance issues that come with the data shuffling, we want to convert some of these tables to HASH distribution.
We have created the steps to do this which involves creating a new table with HASH distribution and then doing a CTAS into this new table and then dropping the old table and renaming the new table to old table. The table name needs to be the same as there many Reporting views that use these tables.
But the challenge here is the CTAS only copies the data and not GRANTS and CONSTRAINTS during this process.
So, we want to extract the GRANTS and CONSTRAINTS of any given table into a .sql file so that once we create the new table. we can simply run this sql script and have the GRANTS and CONSTRAINTS in place just as before.
I can find out what GRANTS are given on a certain table through the below command:
EXEC sp_table_privileges @table_name = '<table_name>';
But there is no way to extract this information in the form of an executable sql script.
Is there a way to achieve this using SSMS? This would really help the database modificatons we're planning. Any ideas on how to accomplish this?