How to copy architecture of an existing database to a new database in SQL Server - sql

I'm using
Microsoft SQL Server 2012 (SP1) - 11.0.3153.0 (X64) Express Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)
and I need to copy the database architecture(Tables and their constraints) to a new database so I can extract the database diagram. The current database won't allow me to(extract a diagram), but any new database I create, will.
I tried creating one with the old ones mdf but it threw an error.
I tried to do an export, which copied all of the tables, but none of the constraints!!!

In SQL Server Management Studio, right click on your database, select Tasks, Generate Scripts. Select the options for generating tables, indexes and constraints. Use the generated script(s) to recreate a new database where you can create the diagrams.

Management studio->Right click on the database
Task->Generate script->Script entire database and all database objects
generate the script to a file/clipboard/new query window
Create new database schema from this script

If you have access to (friendly) developer they may have a copy of MS Visual Studio with SQL Server data tools installed; in it there is a handy feature called SQL Schema Compare that can copy whole or parts of schemas between databases.

Related

SQL Server Schema Compare displays all Tables, Views, Procedures, Functions in database

I have a .NET project. When I do a SQL Server Schema Compare between what is on a local SQL Server 2017 database to Visual Studio in the direction of Database --> Project, the compare lists all tables, views, procedures and functions that are in the database under "Add".
It is unable to see the database objects in the project, so it thinks it needs to add everything to the project. Nothing shows in the Target object definition panel for any of the listed objects
If I do go ahead with the update to add a table to the project, E.G. Exhibit table, then it appears as Exhibit_1.sql in the project alongside the existing Exhibit.sql.
However, some changes were made to procedures in the database that showed up under "Change" so I was able to update them as normal
If I reverse the direction of the compare to Project --> Database, it lists all of the objects under Delete
Local Database is SQL Server 2017 but was upgraded from 2008.
Compatibility level is set to 2017 in the database properties in SQL Server Management Studio
In Visual Studio I have set the Target Platform of the database to SQL Server 2017.
I have ticked "Validate casing on identifiers" and Database collation is SQL_Latin_General_CP1_CI_AS on both
Visual Studio is version v15.7.1 and .NET is 4.7.03056
Is there anything else I need to do for the SQL Server Schema Compare to show the correct comparison? Something in the comparison settings?

Schema compare is not recognizing target source database objects

I recently updated from Visual Studio 2017 Enterprise to 2019 Enterprise. In my solution, I have a database project where I develop my tables, SPs, etc. and use "Schema Compare" to update my database in SQL Server.
When I open schema compare, connect to the target database in SQL server, and hit "Compare," it seems not to recognize objects in the target database because it lists every object in my database project to "Add" them to the target database in SQL Server despite the fact they already exist.
I tried opening my database project in Visual Studio 2017 (where I originally developed the project) and schema compare worked as intended. The connection to the target database in SQL Server was the same.

Possible to restore a backup of SQL Server 2014 on SQL Server 2012?

I know that you can't (at least not easily) restore a SQL Server 2012 backup on SQL Server 2008. But how does it work for SQL Server 2014 to SQL Server 2012 ?
On database level there is the property to adjust the compatibility mode to any other SQL Server version.
How does this helps or work ? Will it only disallow the features from 2014?
To be honest I already tried to restore a backup, but 2012 didn't recognize the datafile, so I couldn't click ok Button to start the restore procedure.
Did I miss some important option ?
You CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility. This is still true in SQL Server 2014 - you cannot restore a 2014 backup on anything other than another 2014 box (or something newer).
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.
The compatibility mode setting just controls what T-SQL features are available to you - which can help to prevent accidentally using new features not available in other servers. But it does NOT change the internal file format for the .mdf files - this is NOT a solution for that particular problem - there is no solution for restoring a backup from a newer version of SQL Server on an older instance.
Sure it's possible... use Export Wizard in source option use SQL SERVER NATIVE CLIENT 11, later your source server ex.192.168.100.65\SQLEXPRESS next step select your new destination server ex.192.168.100.65\SQL2014
Just be sure to be using correct instance and connect each other
Just pay attention in Stored procs must be recompiled

Cant edit schema or data from sql server management studio

I have connected to my SQL azure server using SQL Server 2012 Management Studio and I cannot edit any of my table's schema or the data in it. When I right click on the table the options are missing. Am I doing something wrong?
Not that I am using SSMS 2012, but in 2008 R2 is generally the same. There is no GUI for neither table designer, nor "Edit top 200 records". You have to begin diving into the DDL and DML for SQL Server and give up GUIs. One way you could use GUI to some extend, especially for DDL is to use the portal provided Windows Azure SQL Database manager. You can find a link to it when you go to your database from either the new or the old portal (Manage). Other way is to use some third party tool, which I am not aware of.
Here is the link to that manager from the new portal:
Another option some people may find helpful, if you have and use Visual Studio then you can link to the server in ServerManager, connect to the database, and then design and edit data directly.
My 2008 R2 version of SSMS had the same problem. I downloaded 2016 CTP3 SSMS which has Azure support and everything is normal for the Azure Databases.
https://msdn.microsoft.com/en-us/library/mt238290.aspx
I did lose my connection history information so beware.

Creating new users in SQL Azure

I have been assigned the task of converting an SQL Server Database to an SQL Azure Database. During the process I encountered these problems:
Cannot use the Object Browser in Management Studio 2008 v10. Is there a fix to this?
I cannot create new Users under the Security Section since I cant use the Object Browser.
Basically I want to create an Admin user and NonAdmin user each with their own privileges to UPDATE, DELETE, INSERT commands on different tables in the database.
Basically my web application has a sign up form how can I associate new registered user to the SQL Azure Roles during the sign up process to limit them from perfroming ertain commands on the database tables?
Just answer your questions.
1, No SSMS 2008 doesn't support Azure. You MUST use SSMS 08 R2.
2, If you are using SSMS 08 R2 the object explorer will be appeared. But the features when connecting to SQL Azure will be very limited. The designer and dialog are disabled which means all tasks should be done by using the SQL script.
3, Not pretty sure what you mean, but you can try what you are doing on SQL Server since SQL Azure is very very similar with SQL Server.
Data-tier Application and SQL Azure MW are good tool for migrating your existing database to SQL Azure. But you can still use the build-in feature in SSMS 08 R2 to migrate the database schema as well. Just use the Generate Script menu item from your local database, and make sure you selected SQL Azure in the "Script for the database engine type".
Check out the official page on how to move data etc..'Migrating Databases to SQL Azure'
http://msdn.microsoft.com/en-us/library/windowsazure/ee730904.aspx
Also check out the 'SQL Azure Migration Wizard v3.8.3'
http://sqlazuremw.codeplex.com/
Migrating Databases to SQL Azure by Using Data-tier Application Export and Import is probably your best option, the migration wizard is a great tool, I have used both.
re: 1 you need service packs, I'm not sure 2008 V10 is supported, get the latest version or upgrade to 2008R2 Mgmt Studio (latest)
2: use the tools above
3: not sure here what you are trying to do to correctly answer.
hope that helps...