Is it possible to create database from the previous source code of .net core where the database models were created by scaffolding.
I have lost the database but I have my source code available is it possible to regenerate the tables in Microsoft SQL server 2016 from the models I have created.
Please let me know if its possible
Yes. Just create a new Migration if you want to manage the schema in EF or run Database.EnsureCreated() to create the database from the EF model if you intend to manage the database in SQL Server. eg:
using var db = new Db();
db.Database.EnsureCreated();
And in any case backup your databases.
Related
I have 2 SQL Server databases. The reason is because I created an ASP.NET MVC project using "Individual User Accounts" for authentication. This created a default connection with a database that includes the following tables:
AspNetUserClaims, AspNetUserLogins, AspNetUsers, _MigrationHistory
I then went a step further and built out my own custom roles with a RoleController. So I also have a table for AspNetRoles and AspNetUserRoles. Everything with this is working.
I also have another database that I built in Management Studio that is holding all of the data of my application. I am using Entity Framework to communicate with the database.
I currently reference both databases in my web.config connection strings.
But I would like to migrate the database from the default connection (with my AspNetUsers) into the one in Management Studio.
Is it as simple as copying the tables and putting them in my other database in Management Studio or can I copy the whole schema? Just trying to figure out the best approach here.
You can migrate tables from a database to a diferent one. On SSMS, just right click on a database, select Tasks -> Generate Scripts, and use the wizard to create a script with the table definition and data (optional) to be executed on the new database.
I am a newbie to SQL DBA, I wanted to understand the following concepts
What is the difference between a Database migration & Database Refresh in SQL?
Suppose we want to migrate a database from one instance to other instance, can we follow the below method
Create a new DB in the destination instance with the same name as the source instance
Refresh destination DB with Source DB, & copy all the user access
Database migration:
Moving a database from one server to other usually will do for database upgrades.
Database Refresh in SQL:
Overwrite the existing data in the database with other database data using backup files. Usually will refresh production data to UAT or DEV for data/Issue analysis.
Suppose we want to migrate a database from one instance to other instance, can we follow the below method?
Yes you can follow.
If you are using sql server 2012 and above then you can go for contained database options.
I am using SQL Server 2008 R2 with asp.net MVC.
Scenario is, I am having the License generation application. Where as a each while creating the new license has it creates a separate database according to centralized database script. Say DBCentralized is the current central database and after creating 3 licenses DBLicence1, DBLicence2, DBLicence3 are three databases. This architecture may not good but client's architects want to follow this. But say I am having any schema wise changes in DBCentralized database. Say adding new table, stored procedure, or altering table then certainly this will reflects onward license creations. But what about the existing databases. I need to update existing database schema according to new alterations. since this scenario in short is Updating existing licenses.
I am relativley new to MS SQL server. I need to create a test database from exisitng test data base with same schema and get the data from production and fill the newly created empty database. For this I was using generate scripts in SSMS. But now I need to do it on regular basis in a job. Please guide me how I can create empty databases automatically at a point of time.
You will have a very hard time automating the generate scripts wizard. I would suggest using something like Red-Gate's SQL Compare (or any alternative that supports command-line). You can create a new, empty database, then script a compare/deploy using the command line from SQL Server Agent.
Another, more icky alternative, is to deploy your schema and modules to the model database. You can keep this in sync using SQL Compare (or alternatives), or just be diligent about deployment of schema/module changes, then when you create a new database it will automatically inherit the current state of your schema/modules. The problem with this approach (other than depending on you keeping model in sync) is that all new databases will inherit this schema, since there currently is no way to have multiple models.
Have you considered restoring backups?
To add to Aaron's already good answer, I've been using SQLDelta for years - I think it's excellent.
(I have no connection to SqlDelta, other than being a very satisfied customer)
When I create any new database It automatically create some tables in new database.
Details:
I created a new database "TestDatabase" using below command
Create database TestDatabase
When I expand the Tables folder, I found that there are already some tables created automatically.
These are those tables which I was using in some other database.
Table names:
1. Employee
2. Admin
etc
How can I create new fresh database to make sure that no tables created in it?
Presumably at some point you accidentally created these tables in the model database.
This is used as the template for creating new databases. Simply delete them from model to stop them appearing in every freshly created database.
SQL Server uses the model database as the basis for new databases. Check and see if these tables exist in model - and if they do, delete them.
You should probably check for other objects in modeltoo (stored procedures, views etc).