Link to home
Start Free TrialLog in
Avatar of Ederwainer
EderwainerFlag for Brazil

asked on

SQL Express - Define my database as MODEL and create new databases from it

Hello everybody again,

We have a framwork from which we devise websites for customers and the framework runs on top of a SQL Server Express database.

I'd like to know what would be the quickest way to define my database as a Model database and create duplicates of this database to deploy other websites.

As of now I run a .sql file which populates an empty db and inserts the needed data to it.
Recently we made some upgrades to our framework and the ammount of data to be inserted on the db grew quite a lot, thats why I think theres gotta be an easier and faster way of doing this, considering that I have administrator's access to the database server instance.

Thanks

Eder
ASKER CERTIFIED SOLUTION
Avatar of Aanvik
Aanvik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ederwainer

ASKER

I was successful at creating a .bak file from our model database.
However, when I create a new database it asks me who is the owner, and for each database we create we also need to create a unique owner (user).

How do I create the user prior to creating the database, so I can point to him as the owner when I create the new database?

Thanks!

Eder
Avatar of Aanvik
Aanvik

Its simple. Create a user with a SQL statement in the Target database and while restore you should be able to use that user.
You should be able to restore with SQL statement as well... as long as .bak file is in predefined location.
Ok,

I found where I can create a new user. Ill go trhough the process and see how it goes.

Thank you so far!

Eder
Im having some trouble with it and I could use some further guidance.

I made a .bak file from our oficial database and stored it on the server.
Then I create a new user, create a new database  and go to Tasks -> Restore, choose device as the source and point to the .bak file I created.

Then I come across an error that implies that the .bak file can be restored only the the database from which it was originated. Is that so?

If that is so, this might not be the best method, as what I need to do is to created databases that are duplicate of our official database, however with difeerent names, to be owned by different logins and be used in different websites.

Thanks

Eder
I got over the problem described above. However I came across a new difficulty,

When I generate the .bak file, the default schema is exported along with it. However for security purpose I dont want to use the same schema for all databases and I can accomplish that by populating the db from a .sql query, as it will apply the schema based on the name of the user that owns the newly created database.

How can I have a unique schema for each database if when I restore from .bak it will apply the existing schema instead of using the schema of the database being restored to?

Thanks again.

Eder Wainer