I tried to execute scripts from [1] in model database and user-defined databases but they give definitions/scripts of only user-defined (non-system) views, i.e. those that I anyway can easily get from GUI.
How can I see/script the definition/script of a system view in SQL Server 2008 R2?
[1]
Answers to question "System Views text in SQL Server 2005"
System Views text in SQL Server 2005
select object_definition(object_id('[sys].[server_permissions]'))
AS [processing-instruction(x)] FOR XML PATH('')
(The XML bit is just to prevent long definitions getting truncated when viewed in SSMS)
You can also stop the SQL Server instance. Copy the mssqlsystemresource file (on my system this is at C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Binn\mssqlsystemresource.mdf and then re-attatch the copy under a new name).
In the reattached version it is easier to poke around and see the various definitions using normal SSMS functionality.
Related
As the title says, I need to restore a SQL Server 2012 database (express) to a SQL Server 2008 R2 production database.
I cannot find a way to do so.
The scripting seems to fail due to the size of one of the tables having about 300.000 records.
Any way to "downgrade" the 2012 database?
Thanks
Michael
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server (2012) down to an older version (2008 R2) - the internal file structures are just too different to support backwards compatibility. There's no way, no trick, no hack, no magic to make this happen. Period.
You can either get around this problem by
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.
I have a requirement that am facing difficulty i.e. restoring a data from MS SQL 2012 to MS SQL 2008 using .bak file. when am trying to restore , am getting an error. is this possibility to restore this to downgrade.
can any one help me how to restore ?
Unfortunately SQL Server will not go backwards. The only way you can do this is Using SSIS to transfer the data or you can use the import/export utility.
On your 2012 Server Right click on the DB you want to export data from and scroll down to tasks and then choose export data it will have you then insert all of the information for both the source and destination servers then on the summary page click mappings and make sure they are correct for what you need and the DB it is going to is correct. Then follow the screens until you can click finish. YOu may have too play with it for a little bit to get it to behave nicely but this should work for you.
If all you have is a BAK file you may have to resotre it to a dummy DB on the 2012 server first.
I know the basic syntax of queries but otherwise I'm a beginner with SQL.
I have an SQL file (.sql) and I downloaded a couple programs (pgadmin and sql workbench).
I have no idea how to get from where I am now to actually writing queries and finding information. How do I set up so I can actually import my SQL file and start writing queries?
pgAdmin is the default GUI for PostgreSQL.
SQL Workbench is a free, DBMS-independent, cross-platform SQL query tool.
Either way, you need to connect to a database to actually run queries. The DBMS can either run on your local machine or you can connect to a remote server - where you need access privileges of course.
When scripting a SQL Server 2000 database, on an SQL Server 2000 version of SQL Server, with SQL Server Management Studio 2008 R2 (10.50.1617.0) i get the error:
Creating a user without an associated login is not supported in SQL Server 2008 R2.
With the full stack trace:
Microsoft.SqlServer.Management.Smo.SmoException: Creating a user without an associated login is not supported in SQL Server 2008 R2.;
at Microsoft.SqlServer.Management.SqlScriptPublish.GeneratePublishPage.worker_DoWork(Object sender, DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
What is a good way to resolve this issue.
i've considered:
creating a login (and incur the wrath high atop the thing)
deleting the user (and incur the wrath from high atop the place)
select some rather than all objects to script, and don't script the user that offends SQL Server 2008 R2
But i'll let people on SO post answers, get answers upvoted, and accept an answer that best solves the problem.
As instructed. Just don't script the database users that have no associated login. You can do this in the Tasks > Generate Scripts wizard (pointing 2008 or later SSMS at your 2000 instance) by choosing to select specific database objects and unchecking any troublesome users:
I suspect that your SQL Server 2000 database has user aliases: these were required in SQL Server 6.5 in some circumstances because it was, er, crap,
Note what MSDN says:
sp_addalias is provided for backward compatibility. Microsoft® SQL Server™ version 7.0 provides roles and the ability to grant permissions to roles as an alternative to using aliases.
Run sp_helpuser on the SQL Server 2000 box and review the output and remove them
I'd like to make a daily automatic creation of the creation script for a database in SQL Server 2008, meaning having a (bat, exe, ... whatever) that creates a text file with the very same output obtained by right-clicking on the database in SQL Management Studio and do Script database as... --> Create to... --> New Query window.
Any hint?
Thanks in advance,
Mauro
EDIT 1: We already used SMO but a couple of things are annoying
Needs compatibility pack in SQL Server 2008 (confirm?)
Some things were not created in script (some indexes and keys and in table creation schema is lost)
Best choice for me would something with a powershell script but any other idea is welcome!
You can use SMO. For example: http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated (see the Scripting Objects section).
More info on SMO: http://msdn.microsoft.com/en-us/library/ms162169.aspx