Cannot create new SQL data tables in Visual Studio Express 2012 - sql

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.

Related

Need to View/Convert .bak file contents

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.

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 rename table using SSDT in Visual Studio

I am using visual studio 2013 and trying to learn local database operations. I have created a database using VS and create tables. But I cannot rename table names. There is no such a option anywhere or I cannot see. I searched but find nothing.
Could anyone show me how to rename table using 'VISUAL STUDIO 2013 SSDT'
Open the table, highlight the table name in the T-SQL portion of the window, click the SQL menu, then choose Refactor and Rename. You probably want to preview changes while you're at it to see what will be affected.

Attaching and detaching databases in Management Studio does not result in unloading old database and loading the new one

I have two versions of the same database, say DB1 and DB2. DB1 is a copy made of the mdb and the log file a month ago. The database structure and data has changed since then. I need to switch back and forth between these two copies in SQL Server Management Studio.
The structure of the Customer table in these versions is different. So it is easy to see which version is loaded in Management Studio.
I detach DB1 and attach DB2 and do select * on Customer and see the structure still belonging to DB1. How do I switch to DB2 properly?
I am using the right use DB statement and have the right db selcted in the dropdown on the left hand side for selecting databases.
The drop-down at the top controls which DB you are using, if the DBs are on the same instance of SQL Server. If they are different instances, use the "change connection" button at the top left, then pick your DB from the drop-down.
Somehow Management studio was caching the location of the file. When attaching the database, I had to go to the "current file path", and edit the wrong path and point to the right one. This had to be done even when after clicking the add button I had already chosen the right mdb file with the right path.

Generate changes script

Let's imagine I added new column for some table in SQL Server Management Studio. Is there any way to get change script which is executed when I press save?
What I want to achieve is to apply the same change to other databases (we have a separate database for each developer for debuggin purposes).
I assume you are using table designer in MS SSMS.
Do the changes in the designer and just before hitting Save, go to the Table Designer menu and select Generate Change Script....