Microsoft Study Bible

November 3, 2009

SQLAzureMW: Migrate SQL 2005/ 2008 to SQL Azure

SQL Azure Migration Wizard (SQLAzureMW) is a project on the CodePlex, which helps you migrate to your local SQL Server 2005 / 2008 databases into SQL Azure.

 The SQL Azure Migration Wizard (SQLAzureMW) will let you identify a SQL Server 2005 / 2008 database that you want to migrate to SQL Azure or select an existing SQL file that has the commands you want to execute against SQL Azure. After you choose SQL Server 2005/2008 database, SQLAzureMW walks you through the selection of your SQL objects, creates SQL scripts suitable for SQL Azure, and allows you to edit / deploy to SQL Azure.

If your source is a SQL Server database, SQLAzureMW will walk you through the different object types (i.e. Tables, Stored Procedures, Views, etc.) and let you decide which ones you want analyzed / scripted. You will be given three options:

 Script to window - Choose this option to display the SQL script to a wizard window where you can modify it before telling the wizard to script to Azure. 

  Script to file - Choose this option if you want to save your SQL script to a file. You can edit this file in SQL Server Management Studio and run it from there or save it and use the wizard to load and run your file.

Scrip to Azure—Choose this option if you have database compatible with SQL Azure. It will prompt you to input Azure account and then run the generated script.

SQLAzureMW can handle the incompatibility between SQL 2005/2008 and SQL Azure. For example, it will l automatically try to make changes to your SQL Azure tables / stored procs / view (for example, text columns will become varchar (max) columns), and unbind XML schema collections, which SQL Azure don’t support .These conversions and changes of script are stored in a XML configuration file named NotSupportedByAzureFile.config.

  The current version of SQLAzureMW in Alpha v0.2 is based on Microsoft Public License Ms-PL)。SQLAzureMW is a project in VS 2008, which must run on .NET 3.5.

           

 

September 21, 2009

How to Check IDENTITY column in SQL Server 2005/2000?

In SQL Server database, we often used  IDENTITY property to define the columns of self-growth when creating the table .However, how can we effectively and quickly check the column out properly configured and the use of its percentage? After reading a lot of materials or information, I find this following sentences most convenient.

EXEC dbo.CheckIdentities
GO

/* The SQL Server 2005 version of the stored procedure. It uses new catalog views */
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(SCHEMA_NAME(t.schema_id)) + ‘.’ +  QUOTENAME(t.name) AS TableName,
c.name AS ColumnName,
CASE c.system_type_id
WHEN 127 THEN ‘bigint’
WHEN 56 THEN ‘int’
WHEN 52 THEN ’smallint’
WHEN 48 THEN ‘tinyint’
END AS ‘DataType’,
IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) AS CurrentIdentityValue,
CASE c.system_type_id
WHEN 127 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 9223372036854775807
WHEN 56 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 2147483647
WHEN 52 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 32767
WHEN 48 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 255
END AS ‘PercentageUsed’
FROM sys.columns AS c
INNER JOIN
sys.tables AS t
ON t.[object_id] = c.[object_id]
WHERE c.is_identity = 1
ORDER BY PercentageUsed DESC
END

If this stored procedure was called in SQL Server 2000 ,the following errors will appear:

Server: Msg 195, Level 15, State 10, Procedure a, Line 4
‘SCHEMA_NAME’ is not a recognized function name.

So ,in SQL Server 2000 ,those procedure should be changed:

/* The SQL Server 2000 version of the stored procedure. Uses system tables. This should work in SQL Server 7.0 too */
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(USER_NAME(t.uid))+ ‘.’ +  QUOTENAME(t.name) AS TableName,
c.name AS ColumnName,
CASE c.xtype
WHEN 127 THEN ‘bigint’
WHEN 56 THEN ‘int’
WHEN 52 THEN ’smallint’
WHEN 48 THEN ‘tinyint’
END AS ‘DataType’,
IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) AS CurrentIdentityValue,
CASE c.xtype
WHEN 127 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 9223372036854775807
WHEN 56 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 2147483647
WHEN 52 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 32767
WHEN 48 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 255
END AS ‘PercentageUsed’
FROM syscolumns AS c
INNER JOIN
sysobjects AS t
ON t.id = c.id
WHERE COLUMNPROPERTY(t.id, c.name, ‘isIdentity’) = 1
AND OBJECTPROPERTY(t.id, ‘isTable’) = 1
ORDER BY PercentageUsed DESC
END
/* The SQL Server 2000 version of the stored procedure. Uses INFORMATION_SCHEMA views. */
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(t.TABLE_SCHEMA) + ‘.’ + QUOTENAME(t.TABLE_NAME)  AS TableName,
c.COLUMN_NAME AS ColumnName,
c.DATA_TYPE AS ‘DataType’,
IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) AS CurrentIdentityValue,
CASE c.DATA_TYPE
WHEN ‘bigint’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 9223372036854775807
WHEN ‘int’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 2147483647
WHEN ’smallint’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 32767
WHEN ‘tinyint’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 255
END AS ‘PercentageUsed’
FROM INFORMATION_SCHEMA.COLUMNS AS c
INNER JOIN
INFORMATION_SCHEMA.TABLES AS t
ON c.TABLE_SCHEMA = t.TABLE_SCHEMA AND c.TABLE_NAME = t.TABLE_NAME
WHERE COLUMNPROPERTY(OBJECT_ID(t.TABLE_SCHEMA + ‘.’ + t.TABLE_NAME), c.COLUMN_NAME, ‘isIdentity’) = 1
AND c.DATA_TYPE IN (’bigint’, ‘int’, ’smallint’, ‘tinyint’)
AND t.TABLE_TYPE = ‘BASE TABLE’
ORDER BY PercentageUsed DESC
END

 

 

 

Powered by WordPress

Close
E-mail It