How can I automate the “generate scripts” task in SQL Server Management Studio 2008?

SqlPubwiz has very limited options compared to the script generation in SSMS. By contrast the options available with SMO almost exactly match those in SSMS, suggesting it is probably even the same code. (I would hope MS didn’t write it twice!) There are several examples on MSDN like this one that show scripting tables as … Read more

Sql Server ‘Saving changes is not permitted’ error ► Prevent saving changes that require table re-creation

From Save (Not Permitted) Dialog Box on MSDN : The Save (Not Permitted) dialog box warns you that saving changes is not permitted because the changes you have made require the listed tables to be dropped and re-created. The following actions might require a table to be re-created: Adding a new column to the middle … Read more

SQL Server 2008: how do I grant privileges to a username?

If you want to give your user all read permissions, you could use: EXEC sp_addrolemember N’db_datareader’, N’your-user-name’ That adds the default db_datareader role (read permission on all tables) to that user. There’s also a db_datawriter role – which gives your user all WRITE permissions (INSERT, UPDATE, DELETE) on all tables: EXEC sp_addrolemember N’db_datawriter’, N’your-user-name’ If … Read more

How to see query history in SQL Server Management Studio

[Since this question will likely be closed as a duplicate.] If SQL Server hasn’t been restarted (and the plan hasn’t been evicted, etc.), you may be able to find the query in the plan cache. SELECT t.[text] FROM sys.dm_exec_cached_plans AS p CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t WHERE t.[text] LIKE N’%something unique about your query%’; If … Read more

What is the best way to auto-generate INSERT statements for a SQL Server table?

Microsoft should advertise this functionality of SSMS 2008. The feature you are looking for is built into the Generate Script utility, but the functionality is turned off by default and must be enabled when scripting a table. This is a quick run through to generate the INSERT statements for all of the data in your … Read more