{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/1348","repository_url":"https://api.github.com/repos/tgriesser/knex","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/1348/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/1348/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/1348/events","html_url":"https://github.com/tgriesser/knex/issues/1348","id":148713914,"number":1348,"title":"Adding multiple columns in SQL Server migrations fails","user":{"login":"nickwhiteley","id":10241991,"avatar_url":"https://avatars.githubusercontent.com/u/10241991?v=3","gravatar_id":"","url":"https://api.github.com/users/nickwhiteley","html_url":"https://github.com/nickwhiteley","followers_url":"https://api.github.com/users/nickwhiteley/followers","following_url":"https://api.github.com/users/nickwhiteley/following{/other_user}","gists_url":"https://api.github.com/users/nickwhiteley/gists{/gist_id}","starred_url":"https://api.github.com/users/nickwhiteley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickwhiteley/subscriptions","organizations_url":"https://api.github.com/users/nickwhiteley/orgs","repos_url":"https://api.github.com/users/nickwhiteley/repos","events_url":"https://api.github.com/users/nickwhiteley/events{/privacy}","received_events_url":"https://api.github.com/users/nickwhiteley/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tgriesser/knex/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/tgriesser/knex/labels/MSSQL","name":"MSSQL","color":"207de5"},{"url":"https://api.github.com/repos/tgriesser/knex/labels/PR%20please","name":"PR please","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-15T16:59:08Z","updated_at":"2016-05-08T23:45:16Z","closed_at":null,"body":"The syntax generated for mssql, when adding a column to an existing table in a migration file, prefixes every column with ADD.  Only the first column added should have the ADD clause, others are column separated.\r\n\r\n```js\r\nknex.schema.table('users', function (table) {\r\n  table.string('first_name');\r\n  table.string('last_name');\r\n})\r\n```\r\n\r\nGenerates:\r\n```sql\r\nALTER TABLE [users] ADD  [first_name] nvarchar(255), ADD [last_name] nvarchar(255)\r\n```\r\nBut it should generate:\r\n\r\n```sql\r\nALTER TABLE [users] ADD  [first_name] nvarchar(255), [last_name] nvarchar(255)\r\n```\r\nor:\r\n```sql\r\nALTER TABLE [users] ADD  [first_name] nvarchar(255)\r\nALTER TABLE [users] ADD  [last_name] nvarchar(255)\r\n```\r\nAdding the following to the assign in dialects\\mssql\\schema\\tablecompiler.js fixed it for me.\r\n```js\r\n  // Add columns to the table\r\n  addColumns : function (columns) {\r\n    var addClause = ' ';\r\n    for (var i = 0, l = columns.sql.length; i < l; i++) {\r\n      this.pushQuery({\r\n        sql: 'ALTER TABLE ' + this.tableName() + ' ADD ' + columns.sql[i],\r\n        bindings: columns.bindings[i]\r\n      })\r\n    };\r\n  },\r\n\r\n```\r\nPutting it in a single ALTER statement breaks the rollback (the way I did it, can't see why) hence opting for multiple ALTER statements."},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/217753314","html_url":"https://github.com/tgriesser/knex/issues/1348#issuecomment-217753314","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/1348","id":217753314,"user":{"login":"rhys-vdw","id":822105,"avatar_url":"https://avatars.githubusercontent.com/u/822105?v=3","gravatar_id":"","url":"https://api.github.com/users/rhys-vdw","html_url":"https://github.com/rhys-vdw","followers_url":"https://api.github.com/users/rhys-vdw/followers","following_url":"https://api.github.com/users/rhys-vdw/following{/other_user}","gists_url":"https://api.github.com/users/rhys-vdw/gists{/gist_id}","starred_url":"https://api.github.com/users/rhys-vdw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhys-vdw/subscriptions","organizations_url":"https://api.github.com/users/rhys-vdw/orgs","repos_url":"https://api.github.com/users/rhys-vdw/repos","events_url":"https://api.github.com/users/rhys-vdw/events{/privacy}","received_events_url":"https://api.github.com/users/rhys-vdw/received_events","type":"User","site_admin":false},"created_at":"2016-05-08T23:45:16Z","updated_at":"2016-05-08T23:45:16Z","body":"@nickwhiteley Thanks for the report. Could you provide a PR for this change please?"}}