I'm really unsure about when to use "GO". Note that each of the statements I have gets processed one at a time, so there should not be a need for semicolons. Also, I assume it's no big deal that I'm putting everything on to one long line instead of doing some elaborte indenting. For starters, let's get these 5 MySQL statements translated to MSSQL correctly:
ADD TABLE:
mysql wrote:CREATE TABLE phpbb_mytable (
FirstName varchar(40) NOT NULL DEFAULT '',
LastName varchar(40) NOT NULL DEFAULT '',
DateOfBirth int(11) NOT NULL DEFAULT '0',
SSN int(11) UNSIGNED NOT NULL DEFAULT '' auto_increment,
KEY DateOfBirth (DateOfBirth),
PRIMARY KEY (SSN)) ;
MSsql guess wrote:CREATE TABLE [phpbb_mytable] ( [FirstName] [varchar] (40) NOT NULL, [LastName] [varchar] (40) NOT NULL, [DateOfBirth] [int] NOT NULL, [SSN] [int] UNSIGNED IDENTITY (1, 1) NOT NULL) ON [PRIMARY] GO
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [DF_phpbb_mytable_FirstName] DEFAULT ('') FOR [FirstName]
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [DF_phpbb_mytable_LastName] DEFAULT ('') FOR [LastName]
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [DF_phpbb_mytable_DateOfBirth] DEFAULT ('0') FOR [DateOfBirth]
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [DF_phpbb_mytable_SSN] DEFAULT ('') FOR [SSN]
CREATE INDEX [DateOfBirth_phpbb_mytable_index] ON [phpbb_mytable] ([DateOfBirth]) ON [PRIMARY] GO
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [PK_phpbb_mytable] PRIMARY KEY CLUSTERED ( [SSN] ) ON [PRIMARY] GO
ADD COLUMN
mysql wrote:ALTER TABLE phpbb_mytable ADD
nut_test int(8) NULL DEFAULT '0' ;
MSsql guess wrote:ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD [nut_test] [int] NULL
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [DF_phpbb_mytable_nut_test] DEFAULT ('0') FOR [nut_test]
MODIFY COLUMN
mysql wrote:ALTER TABLE phpbb_mytable MODIFY
nut_test varchar(10) NULL DEFAULT '' auto_increment ;
...I probably need to drop any existing constraints, but I'm not sure how to automate this without screwing up the table.MSsql guess wrote:ALTER TABLE [phpbb_mytable] ALTER COLUMN [nut_test] [varchar] (10) IDENTITY (1, 1) NULL
ALTER TABLE [phpbb_mytable] WITH NOCHECK ADD CONSTRAINT [DF_phpbb_mytable_nut_test] DEFAULT ('') FOR [nut_test]
DROP COLUMN
mysql wrote:ALTER TABLE phpbb_mytable DROP
COLUMN nut_test ;
...will related constraints also be dropped automatically?MSsql guess wrote:ALTER TABLE phpbb_mytable DROP COLUMN nut_test
DROP TABLE
mysql wrote:DROP TABLE phpbb_mytable ;
Let me know what I've got wrong and what's missing. I will try to add more info here in the future, such as datatype conversions.MSsql guess wrote:DROP TABLE phpbb_mytable ;
Thanks!
-Nuttzy