This is not a direct way to T-SQL. Although it creates a pure T-SQL solution that you can apply to your database.
Your results may vary depending on your database ... For example, low referential integrity can make this a bit more complicated.
In addition, this is due to a disclaimer for your own risk :-)
- Get the database that you want to transfer to the SSDT project
http://msdn.microsoft.com/en-us/library/azure/jj156163.aspx http://blogs.msdn.com/b/ssdt/archive/2012/04/19/migrating-a-database-to -sql-azure-using-ssdt.aspx
This is a good way to port any schema to Azure independently ... This is better than just creating a bacpac file .. fix ... export ... fix .. etc. Therefore, I would recommend doing this anytime you want to transfer your database to Azure
For FILLFACTOR fixes, I simply used find and replace to remove all FILLFACTORS from the generated schema files ... Fortunately, I used DB so that they were all set to 90, so it was pretty easy to find a solution and replace (CTRL-SHIFT-F ) ... If your values โโvary, you can probably use the RegEx Visual Studio search functions to find all the placeholders and simply remove them from the indexes.
I'm not so good at RegEx, but I think it works
WITH \((.)*FILLFACTOR(.)*\)
At this point, you will have to fix any additional exceptions related to Azure compliance. The links provided describe how to do this.
- Now that you are at the point where you have an SSDT project that meets the requirements of AZURE SQL.
Here comes ACTION AT YOUR OWN RISK
I used these scripts to remove all FK, PK, and Unique Constraints from the database.
while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY', 'UNIQUE'))) begin declare @sql nvarchar(2000) SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']') FROM information_schema.table_constraints WHERE CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY', 'UNIQUE') exec (@sql) end declare @qry nvarchar(max); select @qry = (SELECT 'DROP INDEX [' + ix.name + '] ON [' + OBJECT_NAME(ID) + ']; ' FROM sysindexes ix WHERE ix.Name IS NOT null and ix.OrigFillFactor <> 0 for xml path('')); exec sp_executesql @qry
I do this because AFAIK the only way to completely remove the fill parameter is to reset and recreate the index. This is due to a cascading set of problems: - / PK with fill factors it is necessary that FK fall, etc. There is probably a smarter way to do this so that you do not remove ALL FK and PK and you look at the dependency trees ...
Now go back to the Azure-compatible SSDT project and make a SCHEME for COMPARISON of this project with your DB ... This will create a script that recreates all your FK, PK and unique restrictions (without Fill Factor) .... At this point, you can just click "Update", or you can click the button to the right of the update that will generate a script that you can use ... So now armed
- script above to remove FK, Pks and Unique.
- script created by SSDT
- Simple testing and viewing of the specified scenarios to ensure that nothing was missed.
You should be able to upgrade your current database to Azure compatible SCHEMA
Additional thoughts:
In my case, fill factors in the production database did nothing useful. They were created by default only. In your case, filling factors can be important, so do not just delete them all in your box without azure production, not knowing the consequences.
There are additional things to consider when performing this task in a production system ... For example, this can lead to mirror delays, and this can cause your log files to grow in a way that you don't expect. Which is important only if you turn directly to production ...
It would be nice if they all worked with FILL FACTOR 100: - /
There are third-party tools there (as I heard) that you can use to upgrade to Azure ...
Another option is to use https://sqlazuremw.codeplex.com/
Use this to create an Azure compatible SCHEMA, and then it uses BCP to copy all the data.
BUT, if you want to make your current SCHEMA Azure compatible so that you can create a bacpac file for upload to Azure, this worked for me when I had to do this.
EDIT: Azure V12 supports fill ratios