difference between .dbo and .mdf database - database

I am really new to database and I am using visual studio 2010. From what I know, there are two ways of creating a database. The first is to right clicked on the project and select Add->New Item and then in the Add New Item dialog I select the Service-based Database which creates a mdf file that lies locally in my project.
Alternatively, I can also create a database in the following way. Right click on the DataConnection in Server Explorer and select Create New SQL Server Database. The created database is shown in server explorer as homepc\sqlexpress.myCreatedDatabase.dbo.
So my question is what is the difference between this two databases (mdf and dbo) and will there be any differences that might occur after I release my project, install and run it on other pcs?

.DBO is the database owner while
.MDF is the manifest data file which is the actual database file.
The primary data file contains the startup information for the database and points to the other files in the database. User data and objects can be stored in this file or in secondary data files. Every database has one primary data file. The recommended file name extension for primary data files is .mdf.(see msdn)
for more info see the forum here DBO or MDF whats the diffrence?

Related

Is the correct way to populate my database in Plesk using their Database tab, SSMS, My Little Admin, or some other way?

I cannot find much in the way of written instructions on how to copy my database to Plesk.
This page simply says, "To create a database and a database user: Go to Databases > Add Database."
And then it shows a screenshot which does not match what I have; specifically, it shows an "Import Dump" button which I do not have:
This is what I see in my session (no Import Dump button):
I zipped a .bak file of my database contents and uploaded it to the File Manager's Files section:
...but how do I move it from there to the Database area, and what do I then do to populate my tables with the contents of the .bak file?
Is this something that should be done using Microsoft SQL Server Management Studio, or from "My Little Admin," or what?
I was able to create the (empty) tables by running a script.sql file I generated from my local database. My Little Admin indicates that the empty tables do exist on the server, for example here is the ACTORS table:
OTOH, SSMS shows that the database exists, but shows no tables:

How to dump SQL Server data into csv

I'm converting web application written in ASP into PHP that will be using MySQL. I have a SQL Server database with two files (.MDF and .LDF) I want to convert into CSV file but I am having trouble finding the right tool to do the job. I found that some people are suggesting SQL Server Express. I tried it but couldn't figure out how to load database from file and use it. I also tried to use opendbcopy but when trying to open a file it doesn't show it in the file pane.
If you install SQL Server Express, you can load the image file using the Attach Database functionality in the SQL Server Management Studio (the management UI).
Then you can view and work with the database directly from Management Studio, where you can export the file to CSV by right-clicking the database name and selecting Tasks->Export Data.
There's an online service called RebaseData that can do the job. You just need to upload your .MDF file and it gets converted to a .ZIP archive. The .ZIP archive will contain several .CSV files, one for each table of the database.
Link to the converter
Disclaimer: I'm working for that service.
connect database to visual studio and write query to display all data from the table you want and then right click and select all and again right click and save it .
Its done !

copy a database within SQL Server Express?

I would like to make a copy of a database I have but keep it on the same server as a test database. However, everything I have found is to use the copy database wizard (I am using MS SQL Server Express).
The instructions always say: In SQL Server Management Studio, in Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Copy Database.
I don't have the Copy Database option. I am running as an admin, so no clue why it is missing for me - is it something I have to install separately? I can't do the Detach/Attach since it is copying to the same server. I tried detaching, copying the MDF/LDF, renaming, attaching but as you can imagine that messed a ton up :) I am not great with SQL to do it all programatically. Is there a tool out there I could use?
In SSMS 2008 you can do this:
Create a backup of the database you want to copy
In SSMS, right-click 'Databases' and select 'Restore Database'
Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section
Enter the name of the new database in the 'To database' field in the 'Destination for Restore' section - this cannot be the name of an existing database.
Click OK
You're done! :)
In SQL Server Express 2012 you can do following steps:
Create a backup of the database you want to copy
right-click "Databases" and select "Restore Files and Filegroups"
Enter the name of the new database in the "To database" field.
Select "From device" and then select the file that you backuped in the first step
click "OK"
this will "clone" the Database with the correct table settings such as the "default value" and "auto increase" etc.
SQL Express database has an export button, I just exported the database to a new database on the same server, it is copying the database. Just right-click on the database name.
Take these steps to make a copy of the database in SQL Express
Stop SQL
Copy the mdf, ldf and any other file for the db to a NEW location (make sure you get the log file)
Change the name of each copied file
Start SQL
Right-click Database in SSMQ and select attach
Make sure you change the name in the column "Attach As"
Update the file location in the lower pane of "Database Details" to the location of your copied files (especially that log file)
I was able to copy a database on my SQL Express system with this method
I had a problem creating a copy of my database as well using SQL Express 2012.
I have solved it by the backup and restore method.
After making the backup I used: restore -> files and file groups
Next step was to write a new name for the new database and set the source:
Pointing the source file
and finally, a overwrite the existing database with replace must be selected
and set names for new files with extension mdf and ldf that are different from the existing where is: Restore as
This method worked for me
Just be aware if you are using SQL Server Express 2012 of going to the option Files and make sure that the destination files (Restore As column) are different from the original files *.mdf and *.log
( I tried to put an image but need 10 reputation :p)
I do not believe the Express version of the manager will have the copy database feature. Have you considered copying via the backup and restore method?
http://msdn.microsoft.com/en-us/library/ms190436.aspx
I found the problem! Click on Databases, restore, then do the following:
After choosing from where to restore, and writing destination db name, go to files [annotation 1 on picture] and change the very right column files names to different than original [annotation 2 on picture] then it works :)
I just thought of a really nifty way to get around this :) So I thought I should post my idea. Note that this is 'untested' but I think it will work.
Do a "Back Up..." database (theoretically this is on your
production server, but it doesn't have to be)
Copy the backup file (from your prod server) onto your development machine
Assuming you're using SSMS Developer Edition on your development
machine, you can then do a "Restore" onto your development machine,
then do a "Copy Database" afterwards also on your development
machine (to create a new copy of the DB)
Now do a "Back Up..." on the new DB you just created, copy the backup file (to your production server) and do a "Restore" on the sql server express server :)
Hope this helps out a few people :)
Cheers,
Jeff
The solution is definitely to create a backup and restore it, but ensure that you're restored copy is pointing to different .mdf and .ldf files.
Here's how to check that using SSMS 2014 and a SQL Server 12 installation: assuming you're creating and restoring backups on your local disk.
Create a backup of your existing database
Right click the database, and choose "back up..." under "tasks."
(If you leave the location as the default, you don't have to hunt for the back up in the next step when you restore.)
Restore your backup to a NEW database:
Right click on databases, choose "restore database"
Select "device"
Click the ellipsis button ("...") to open the "Selct Backup devices" dialog.
Choose "File" as the backup media type and click the "add" button
Select the backup you just made, click ok (twice)
Now, back in the "restore database" dialog, type a new name for your destination database
Click "files" under "select a page" and make sure that "restore as" is pointing to .mdf and .ldf file names that do not already exist
Click ok!
I think you could try import data to a new database.
Create an empty database in your local sql server
Right click on the new database -> tasks -> import data
In the SQL Server Import and Export Wizard, select product env's servername as data source. And select your new database as the destination data.
As for the first part of your question (why do you not see this Copy Database Wizard option under Tasks for your dbs), the answer is indeed in the fact that you are running SQL Server Express. SQL Server Express doesn't support the SQL Server Agent feature, which this Copy DB feature relies upon, so the Copy DB feature is not shown (but many online resources fail to make that observation).
Fortunately, most everyone else has addressed the second part of your question (how to achieve the task otherwise), and nearly all point out using the existing backup and restore options (which DO exist in Express), or the export/import (which also exists in Express, I can confirm).
Try making a backup of your database, and restoring it into a brand new database.
Create new DB.
Make a full backup of your original.
Right click on your new DB, hit restore.
Navigate to your .BAK, and ensure the .mdf and .ldf match the new.

SQL Server: how do I export entire database?

I need to export database from one server and import it into another server.
How do I export the entire database to a file, or two files mdf, ldf (either option is fine)
How do I import it into a new server using ssms?
In the instructinos frmo ponies, it says:
In the To a point in time text box,
either retain the default (Most recent
possible) or select a specific date
and time by clicking the browse
button, which opens the Point in Time
Restore dialog box. For more
information, see How to: Restore to a
Point in Time (SQL Server Management
Studio).
To specify the source and location of the backup sets to restore, click
one of the following options:
From database
Enter a database name in the list box.
I am unable to type anything in restore
https://stackoverflow.com/questions/3241108/i-backed-up-the-database-in-ssms-sql-server-how-do-i-restore-it
Using SQL Server Management Studio, you use Backup/Restore feature. The Restore process is laid out in the MSDN documentation. And here's the MSDN article for backing up a database...
Obviously, you restore to another SQL Server database instance (a "database instance" can contain multiple databases.). The version of the instance can be newer than the version the backup came from - the compatibility level will just be set accordingly.
If you want to generate a .sql file:
right click on the database in SQL Server Management Studio
select Tasks->Generate Scripts... .
In the dialog that pops up, Select All on the screen that says "Select database objects to script"
The generated .sql file can be opened again in SQL Server Management Studio and be run. If the .sql file is very large, see How do you import a large MS SQL .sql file?
If you want to export / save all data of a database into a .sql file, do this:
Right click on the database in SQL Server Management Studio
Tasks -> Generate Scripts
Script entire database and all database objects
Next
Click - Advanced
Scroll down to Types of data to script and set from Schema only -> Schema and data -> Ok
Save as script file (name it and save it where you want it)
Next
Next
Done ✔️
You can open the file now and see that all values are also included now
The best way to do this is to backup the database. This will backup to one file. Then take that file to your new server and do a restore. This should restore everything, from tables to stored procedures to foreign keys and all the data.
Also, if you just want to move a database to a new server, Detach/Attach is a quicker option. Backup/Restore is what you want if you want to keep the original database in place.

How can I use a SQL Scripts in a Database Project with the System.Data.SQLite data provider?

I've got a project where I'm attempting to use SQLite via System.Data.SQLite. In my attempts to keep the database under version-control, I went ahead and created a Database Project in my VS2008. Sounds fine, right?
I created my first table create script and tried to run it using right-click->Run on the script and I get this error message:
This operation is not supported for the provider or data source you are using.
Does anyone know if there's an automatic way to use scripts that are part of database project against SQLite databases referenced by the databases, using the provider supplied by the System.Data.SQLite install?
I've tried every variation I can think of in an attempt to get the script to run using the default Run or Run On... commands. Here's the script in it's most verbose and probably incorrect form:
USE Characters
GO
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'Skills')
BEGIN
DROP Table Skills
END
GO
CREATE TABLE Skills
(
SkillID INTEGER PRIMARY KEY AUTOINCREMENT,
SkillName TEXT,
Description TEXT
)
GO
Please note, this is my first attempt at using a Database, and also the first time I've ever touched SQLite. In my attempts to get it to run, I've stripped any and everything out except for the CREATE TABLE command.
UPDATE: Ok, so as Robert Harvey points out below, this looks like an SQL Server stored procedure. I went into the Server Explorer and used my connection (from the Database project) to get do what he suggested regarding creating a table. I can generate SQL from to create the table and it comes out like thus:
CREATE TABLE [Skills] (
[SkillID] integer PRIMARY KEY NOT NULL,
[SkillName] text NOT NULL,
[Description] text NOT NULL
);
I can easily copy this and add it to the project (or add it to another project that handles the rest of my data-access), but is there anyway to automate this on build? I suppose, since SQLite is a single-file in this case that I could also keep the built database under version-control as well.
Thoughts? Best practices for this instance?
UPDATE: I'm thinking that, since I plan on using Fluent NHibernate, I may just use it's auto-persistence model to keep my database up-to-snuff and effectively in source control. Thoughts? Pitfalls? I think I'll have to keep initial population inserts in source-control separately, but it should work.
I built my database using an SQLite SQL script and then fed that into the sqlite3.exe console program like this.
c:\sqlite3.exe mydatabase.db < FileContainingSQLiteSQLCommands
John
Well, your script looks like a SQL Server stored procedure. SQLite most likely doesn't support this, because
It doesn't support stored procedures, and
It doesn't understand SQL Server T-SQL
SQL is actually a pseudo-standard. It differs between vendors and sometimes even between different versions of a product within the same vendor.
That said, I don't see any reason why you can't run any (SQLite compatible) SQL statement against the SQLite database by opening up connection and command objects, just like you would with SQL Server.
Since, however, you are new to databases and SQLite, here is how you should start. I assume you already have SQLite installed
Create a new Windows Application in Visual Studio 2008. The database application will be of no use to you.
Open the Server Explorer by pulling down the View menu and selecting Server Explorer.
Create a new connection by right-clicking on the Data Connections node in Server Explorer and clicking on Add New Connection...
Click the Change button
Select the SQLite provider
Give your database a file name.
Click OK.
A new Data Connection should appear in the Server Explorer. You can create your first table by right-clicking on the Tables node and selecting Add New Table.

Resources