Need to View/Convert .bak file contents - sql

I've got a .bak file from an HR software we used to use and have been asked to review the contents. I've never done this before, so I've pieced things together from research. So far, I've installed SQL Server 2008 R2 w/ Management Studio and managed to Restore the database from the .bak file.
I've got it in there, but don't know what I'm looking at, how to get the data in a viewable format, export it as .sql, .csv or anything. Not really sure what the next step is to view this in an understandable format. Need a push in the right direction.

With your knowledge with databases, I suggest you follow the following steps to extract a table to Excel
From object explorer, open databases by clicking the plus sign on Databases folder
You will see many databases. Click the plus sign for any of them.
Open a folder called Tables, you will see the data tables in that database.
Click on CTLR + N with the database name selected.
A query editor will open. Type SELECT * FROM TableName. You need to replace TableName with the Name of the table you want to explore.
Click F5. This will display data for you in a grid at the bottom.
Right click on the top left of the data that you see and click on Copy with Header.
Go to an excel sheet and paste the data.
This is the way to do it table by table. But you are highly encouraged to consult with a database developer or colleague with database knowledge if you want to learn how to manipulate data inside management studio.
This Link might be helpful for you http://www.w3schools.com/sql/sql_intro.asp
Hope this will help.

Related

Some useful functions of MySQL Workbench for SQL Server management studio

Our project is moving from MySQL to MS SQL and after a long time working with MySQL Workbench I really miss some features in SQL Server Management studio (2014).
Do you know whether they exist in SSMS or there is an alternative/replacement application for SSMS to work with database?
Functions are listed below:
Generate update data script to review and to be able to copy-paste it. Do not update data when I move to another row when the table is opened for editing.
Some changes are still made in database in our project, and sometimes it's easier to add some rows manually in 5 tables, get the script, test it and run the script at production environment. I don't want to write a script for each update and I don't want to make a mistake when copying data to production server using edit table option.
Review update table script BEFORE the changes were made, not after (I am talking about Tools - Options - Designer - Auto generate change scripts).
Upload a file using select file dialog into a binary field.
Again, I know about using OPENROWSET function, just interested how to do it as I used to.
Ability to view large text fields in a convenient way in SSMS. Now I have to copy data from a field and paste it into notepad. (For example, error message with a long trace log)
Save a few tabs with some useful scripts and open all of them when I open SSMS.
Is there any way to organize tabs to be able to work with 10+ tabs more effectively? Now only 6 of them can be shown on the screen (compate it to 15 tabs in MySQL WB).
Simple 'search field' (like Ctrl+F in Excel) to be able to search data in all fields displayed on the screen.
I would appreciate any ideas.
Thank you.

How to copy database in ssms Express version

I just now joined my first job (two days ago) and I am using Microsoft sql server management studio express version here. I want to create a new database by copying data, indexes and all properties from production database(We don't have a QA database) so that I can practice on it. How can I do that. I tried by taking backup of prod db and importing it into new database but it didn't worked and I got this error:
.
I am using Express version so no copy database option.
This might be a possible duplicate of this question: ssms copy database but I am using express version.
Can somebody tell me how can I do this.
Thanks
This is not hard to do in SSMS when working with SQLEXPRESS databases. I just executed these steps myself to verify that it works.
Create a full backup of the database you want to duplicate. To do this, right click on the database you want to duplicate, select Tasks, then Back Up .... Accept the defaults (or alter them if you wish) and click the "OK" button.
Now we will restore this backup to a new database. In SSMS, right click on the Databases folder icon. Choose Restore Database .... In the To database: text box, give your new database a name. I used "test". The name should not duplicate the name of any existing database. In the From database: dropdown, select the backup you created in Step 1. Click the "OK" button.
You should now have a copy of your original database, and it is named "test". To see it you may need to right click on the Databases folder icon and choose Refresh.
Hope it helps. Good luck!

How to view and change data of a .mdf file using MS Access?

Background: I have an .mdf database containing some numeric values that I need to change (specifically, scale and offset values for sensors). The database was created by a Visual Basic program that controls some lab equipment and stores pertinent data in the .mdf file. Please excuse my rudimentary knowledge of the topic; I'm a complete novice when it comes to SQL Server and VB.
After searching through many posts, I understand that to open the .mdf file, you must "attach" it in Microsoft Server Management Studio (I'm using that with SQL Server 2005), which I have successfully done.
Problem: It seems that this only allows me to view and modify the structure of the database, ie. tables, columns, data types etc., rather than the values of the database itself.
Is there a way to do this manually, like how you can edit the field data of .mdb files in MS Access? Again, sorry for my limited knowledge on the topic. I'll gladly provide extra details where needed.
You mention you want to use access. That can be done. Your database is up and running after attaching it.
In Access you can simply create an ODBC connection in access and use Access to edit/modify your data as much as you want. you can also create queries.
It is in the menu item "external data" [I'm guessing because I use a dutch version]. You select to create a "linked table", choose your server and you are done.
Right-click on the table you want to modify in SSMS and select "Edit Top 200 Rows".
If you have more than 200 rows to edit, you can connect to the SQL Server database with either Access or Excel.
Here are the instructions for Access:
http://office.microsoft.com/en-us/access-help/connect-an-access-project-to-a-microsoft-sql-server-database-adp-HP005274586.aspx

Cannot create new SQL data tables in Visual Studio Express 2012

I have created a new SQL database in my Visual Studio Express 2012 website. This appears in the AppData folder. I can open the database in the Database explorer and now I want to add some empty data tables.
I right click on the Tables folder and select Add New Table. I get the screen (below). When I have finished I click Update and it appears to do something but then the table has not appeared in the Tables folder.
I have also tried clicking the save button, and saving the table manually in the AppData folder, but yet it still does not appear in the Tables folder.
What am I doing wrong please?
Here is the solution-
https://www.youtube.com/watch?v=HwA-tNvU3hw
Steps 1-Change the name of table [dbo].[table---(change this)]
Step 2-Don't save the table after creating them rather choose option update table and then update database.
Step 3-On refreshing the tables you will be able to see your table.
In my case, Visual Studio was saving the table to my documents. It should be writing the table to the MDF file. I used the designer to generate the T-SQL, then I copied the T-SQL right clicked on the tables folder, chose 'New Query' pasted the T-SQL commands, set the target database as shown in the image and ran the query. Finally!
In the 'New Query' window within VS 2012 Express, there is an 'available databases' drop down. Choose your database that is part of your solution and execute the T-SQL
Have you tried refreshing the tables list on the right hand side?
Make following change:
CREATE TABLE [dbo][change_this_name]
click the update button on top left corner.
I was up against this same problem in Visual Studio 2013 Community. The solution was to go to Tools -> Extensions and Updates and then download the SQL server compact / sql lite toolbox. VS2013 will prompt you to restart for the new extension to take effect.
After the restart, your databases will have a red "x" on them. Right click them, select modify connection and then take the defaults.
Visual Studio will then pull its head out of its hind parts, and those tables you've been saving that never appeared in the tables folder before will be auto-magically there.
Hope this helps.

How to get script of SQL Server data? [duplicate]

This question already has answers here:
What is the best way to auto-generate INSERT statements for a SQL Server table?
(24 answers)
Closed 6 years ago.
I'm looking for a way to do something analogous to the MySQL dump from SQL Server. I need to be able to pick the tables and export the schema and the data (or I can export the schema via SQL Server Management Studio and export the data separately somehow).
I need this data to be able to turn around and go back into SQL Server so it needs to maintain GUIDs/uniqueidentifiers and other column types.
Does anyone know of a good tool for this?
From the SQL Server Management Studio you can right click on your database and select:
Tasks -> Generate Scripts
Then simply proceed through the wizard. Make sure to set 'Script Data' to TRUE when prompted to choose the script options.
SQL Server 2008 R2
Further reading:
Robert Burke: SQL Server 2005 - Scripting your Database
SQL Server Management Studio
This is your best tool for performing this task. You can generate a script that will build whichever tables you wish from a database as well as insert the data in those tables (as far as I know you have to export all of the data in the selected tables however).
To do this follow these steps:
Right-click on your database and select Tasks > Generate Scripts
In the Generate and Publish Scripts wizard, select the "Select specific database objects" option
Expand the "Tables" tree and select all of the tables you wish to export the scheme and data for, then click Next
In the next screen choose how you wish to save the script (the Output Type must remain set as "Save scripts to a specific location"), then click the Advanced button in the top right corner
In the newly opened window, under the General section is a setting called "Types of data to script", set this to "Scheme and data" and click OK
Click Next, review the export summary and click Next again. This will generate the script to your selected destination.
To restore your database, simply create a new database and change the first line of your generated script to USE [Your.New.Database.Name], then execute. Your new database will now have all of the tables and data you selected from the original database.
I had a hell of a time finding this option in SQL Management Studio 2012, but I finally found it. The option is hiding in the Advanced button in the screen below.
I always assumed this contained just assumed advanced options for File generation, since that's what it's next to, but it turns out someone at MS is just really bad at UI design in this case. HTH somebody who comes to this thread like I did.
If you want to script all table rows then
Go with Generate Scripts as described by Daniel Vassallo. You can’t go wrong here
Else
Use third party tools such as ApexSQL Script or SSMS Toolpack for more advanced scripting that includes some preprocessing, selective scripting and more.
Check out SSMS Tool Pack. It works in Management Studio 2005 and 2008. There is an option to generate insert statements which I've found helpful moving small amounts of data from one system to another.
With this option you will have to script out the DDL separately.
SqlPubWiz.exe (for me, it's in C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Publishing\1.2>)
Run it with no arguments for a wizard. Give it arguments to run on commandline.
SqlPubWiz.exe script -C "<ConnectionString>" <OutputFile>
BCP can dump your data to a file and in SQL Server Management Studio, right click on the table, and select "script table as" then "create to", then "file..." and it will produce a complete table script.
BCP info
https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/datacenter/?p=319
http://msdn.microsoft.com/en-us/library/aa174646%28SQL.80%29.aspx
I know this has been answered already, but I am here to offer a word of warning.
We recently received a database from a client that has a cyclical foreign key reference. The SQL Server script generator refuses to generate the data for databases with cyclical references.