Use EDMX file to generate a database? - entity-framework

I have lost my SQL script to generate tables for my database, good thing its not for a client. I thought I had a backup but I do not.
I do have an EDMX file in my project though, so is there any way that I can create the database schema off of the EDMX?

Right click the EMDX design surface, you will find a generate database option there to give you your sql scripts or directly populate a database.

Related

Difference between copy/migrate/export in SQL developer

I am using Oracle SQL developer, it has the following tools,
DATABASE copy, DATABASE export and Migrate.
I want to move one schema and all the data in it from one server to another.
What is the difference between these options? Does anything serve what I am looking for?
Database Copy is probably what you want.
Supply two database connections, and we'll take objects and data and copy them from one database to another.
However, if your schema is large, this will be inefficient. The Copy routine does inserts, row-by-row across the jdbc connections.
Database Export takes the objects and data and offloads them to flat files. These flat files could then be used later to put in another database.
Migrate is used to take a database from SQL Server, Sybase, Teradata, Redshift, DB2, etc. to Oracle. It has an online (jdbc row-by-row) data copy and an offline (flat files for SQL Loader) data move mode. For SQL Server/Sybase, we can also translate the T-SQL stored procedures to PL/SQL.
Your solution might also lie elsewhere - Data Pump. We have a wizard for that as well, and works great for very large schemas/databases. You'll just need access to the database OS so you can put the DMP files into a Database Directory.

Delete database. Entity Framework

I followed the following MDSN tutorial:
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-model
Then I tried this guide according to my needs and I set up a database GAMES.MDF.
Then, I deleted the database and set it up again, is supposedly work (I can write and read data), but there is no such database in the APP_DATA folder. It seems to exist, but somewhere else on my PC.
 
I even tried a new project and it did not work, works but not in the library, and it even uses the data I created before. I even deleted the DB from SQL Server Management Studio 2008.
How do I delete it permanently, not to remain any trace of it?
Check for the connection string in the web.config - You'll probably see the file location there.
Your connection string should ideally name the database you want to use. I would not recommend specifying the MDF file, unless you know you are using SQL Express. Source: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f21c0728-935d-492a-baaf-ff2704e3683b/attachdbfilename-option-in-connection-string?forum=sqldataaccess0
Instead, this is how it is done on SQL Server:
initial catalog=MyDatabase
To be sure you are accessing the database you think you are, run this SQL query through your app, using your connection string, and look at the physical file location of your MDF file. This query is handy for knowing which DB is tied to which DB files.
select * from [dbo].[database_files]
As far as actually clearing the DB, this article deals with managing database initializers and seeds. You might be experiencing a problem due to that:
How to delete and recreate from scratch an existing EF Code first database
Outside of EF, SQL deletes databases like this:
use master
drop database MyDatabase

How update database schema from EF5.0 model first changes?

I'm using VS2012 and EF 5.0 with a model first approach. I am wondering if there is any good way to generate incremental DDL to update model changes without dropping all the tables and losing the data I have in there already.
I like to use a SQL server data project within Visual Studio to keep my data in sync with the database - it's like a mini SQL server schema store.
Basically what we are doing here is updating the schema of the data project using the model's DDL script, then comparing and pushing those changes out to the database. Just be sure to generate your model's DDL script first.
Create a new SQL Server Database project
Right click data project and import your existing schema from the database server
Right click data project and import your generated DDL script from model first project.
Right click data project and do a schema compare of your project vs. your database server
Update database based on this schema compare (click update)
Every time you want to update your database just generate and import your models' sql script, compare, and update. It takes a couple steps but works perfectly.

Alter database to match model

Originally, I used Data Modelling in MySQL Workbench to design a database consisting of a series of tables (i.e. the columns and relationships).
Then using Database -> Forward Engineer, I created a database, and inserted data into the tables.
Now I've realised that the model I've designed needs some changes, and so I've altered some tables by inserted columns. My question is, how do I get MySQL Workbench to alter the tables?
Using Database -> Synchronize Model, Update Source just generates a bunch of CREATE TABLE IF NOT EXISTS sql statements, and as the tables exist, nothing changes.
What you are looking for is in the model menu Database / Synchronize model.
As I couldn't get get File -> Export -> Forward Engineer SQL ALTER Script to work, so I made a backup of the data, dropped the tables, recreated them, and then imported the data. I'd rather find a way to get MySQL Workbench to generate ALTER commands from the changes in my model
The 2011 answer is no longer up to date. I struggled to find the option in a recent version. Here is the new procedure (works for MySQLWorkbench 6.2 at least):
When you have finished editing your model, open Database -> Synchronize with Any Source
In the step Select Source you have 3 parts
Source : choose Model Schemadata
Destination : choose Live Database Server
Send updates to : choose whether the live database should be updated or if you only want to saves the changes to a .sql file
Proceed in the wizard, you can then review the tables and sql queries that will be executed. You can also ignore the update of some tables.

How to copy everything except data from one database to another?

In T-SQL (Microsoft SQL 2008), how can I make a new database which will have the same schemas, tables, table columns, indexes, constraints, and foreign keys, but will not contain any data from the original database?
Note: making a full copy, then removing all data is not a solution in my case, since the database is quite big, and such full copy will spend too much time.
See here for instructions: How To Script Out The Whole Database In SQL Server 2005 and SQL Server 2008
In SQL Management Studio, right click on the database and select "Script database as"
http://msdn.microsoft.com/en-us/library/ms178078.aspx
You can then use the script to create an empty one.
Edit : OP did say 2008
I use liquibase for this purpose. Just point liquibase to a different server and it will use your changelog to bring the second database up to date, schema wise. It has the added benefit that the changelog file gets stored in source control and so I can have tagged versions of it, allowing me to restore a database to what a specific version of my app is expecting.