I have been working on a project recently which has required me to implement a WAMP server with MSSQL. The environment that was required was Windows Server 2008, MSSQL 2008 and we had MSSQL Studio. Of course, we installed PHP and Apache. We had to use a prior version of PHP as newer versions required a different syntax for the mssql_query statments.
The porting of a MySQL database to MSSQL was not straightforward either. I used dbconvert, which is free but you can only export the first 50 rows of each table in free mode, after that you pay.
You can download this here:
http://dbconvert.com/convert-mssql-to-mysql-pro.php
Then there was the problem of data types, since MSSQL seems to want varchar’s to be nvarchar and blob’s to be varbinary. A few good tips for this are as follows:
When selecting data from the db, you need to cast nvarchar’s as text first, something like this:
cast(field1 as text) as field1
When updating a varbinary, you first need to cast it as such, like this:
field1=cast(‘$value1′ as varbinary(max))
The next problem was updating the database structure. If you receive an error when doing this in design mode (MSSQL Studio), such as this:
Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.
…then there is a few ways you can work around it. If your database does not record transaction changes, then you can use the global settings in MSSQL Studio to turn the ‘Prevent saving changes that require table re-creation’ tick box off. Otherwise you need to use T-SQL to make your db changes. There is a blog post from MS here, which covers it:
http://support.microsoft.com/kb/956176
Finally, to set a field on a table to autoincrement, you need to use the IDENTITY keyword, for example like this:
CREATE TABLE [dbname].[dbo].tablename
(
id int IDENTITY(1,1)PRIMARY KEY,
field1 varchar(max) NULL,
…
)
The numbers in parentheses after IDENTITY refer to the start value and the increment amount, so in the above example the start value is 1 and the rows increment by 1 each time.