Visual Studio DataSet Designer Refresh Tables - database

In visual studio datasource designer is there any way to refresh a table and its relations/foreign key constraints while keeping the custom queries?
The way I am doing it at the moment is removing the table and adding it again. This adds all the relations and refreshes all fields.
Also if I change a fields data type, is there a way to automatically refresh all the fields in the datasource? Again without deleting the table and adding it again.
Reason for this is because some of my TableAdapters have quite a number of complex queries attached to them and when I remove the table the adapter gets removed as well including all its queries.
I am using Visual Studio 2008 and connecting to a MySQL database.
Any1 have an idea?

Each table has a default query (The one on top with the check on it). When you dragged your tables in to the dataset to create the query, it wrote a SQL statement which it uses to schema your table. Keep that query simple, you might not actually use it in code, and you can always edit that query to update the table schema.
Every time you open the default query it connects to your datasource and allows you to select new columns that weren't in there before. If you want to update your existing columns, delete all the columns out of the table before you attempt to open the query. When you save the query, your updated columns get added back.
Make sure your connection string has permissions to view column information.

I reported this to MSFT but no response. The designer hangs all the time on the simplest of SQL statements. What I found that works for me is.
Add a new table to the designer.
Save it.
Shut down visual studio 2010.
Start VS 2010.
Add one or two more SQL statements and follow steps 2-4 again.
This is a pain in the neck but the only thing that stops Visual Studio dataset designer from hanging. I experienced in this same issue in VS 2008. I am connecting to Oracle but still shutting down VS and starting it back up works, but really, this is nonsense.

You can add/change/remove fields and relation ships, but i would suggest looking into NHibernate.

You should be able to right-click the dataset in solution explorer and select "Run Custom Tool" to refresh the table and it's query/relationships.
If that command is not there, check that the dataset properties has "MSDataSetGenerator" in the Custom Tool field.

Right click on your DataSet name and select Dataset Properties
Below the Query box you will see a button for Refresh Fields.
Click on Query Designer and the new field should show in your table list.

Related

Right click to query temporal tables not working

I have SQL Server Management Studio 2016 loaded with Microsoft's test database (WideWorldImporters) but for some reason, any table that is a temporal table does not give me the option of right clicking and selecting the last 1000 rows as all other non-temporal tables allow.
Am I missing something which needs to be installed or is there an alternative way of querying the table for data?
Right Clicking does not work. But in the session that created the table you can do any kind of query that can be done against any other table.

Is it possible to edit a sql query using a query itself

I have a sample query to insert data into the table.However, a table name has been misspelled. The same mistake is continued for about 120 records. Is there any query that can be written so that I can correct it in one record and apply the changes to the rest automatically? or do I have to do it manually?
Yes, it possible in SSDT Project.
create SSDT Project
import your database
right click column in script and choose Refactor->Rename

Adding new rows that contain identities, defaults via SQL Server Management Studio GUI

In Enterprise Manager (SQL Server 2000-), you can add new rows to an existing table by right-clicking the table and selecting "Open Table". You get an MS Access-like grid with a single blank row at the bottom for adding new rows.
In Management Studio (SQL Server 2008+), the same functionality is available by right-clicking and selecting "Edit Top 200 Rows".
In the old Enterprise Manager version, any untouched columns are set with either their default value or new identity (if applicable). This happens as soon as focus leaves the row.
In Management studio, any values not explicitly typed-in are set to NULL (even if NULL is not allowed for the column). After focus leaves the row, there is a little exclamation icon to the left of the row with this tooltip:
"This row was successfully committed to the database. However, a problem occurred when attempting to retrieve the data back after the commit. Because of this, the data in this row is read-only. To fix this problem, please re-run the query."
Is there a setting somewhere to enable the old behavior? Or, is there a keyboard shortcut (similar to CTRL+0 == NULL) to indicate you want to use the default?
I feel like I must be missing something obvious--otherwise this view is pretty useless for quickly adding new rows.
I've found that this behavior only happens when SQL Management Studio is connected to a SQL 2000 database. When editing rows on a SQL 2012 database the primary key immediately updates and there is no error icon. I think the best workaround is to just continue to use Enterprise Manager if you need to make quick edits on SQL 2000 databases.
To clear the "to fix this problem please rerun the query" just right click on the read only row with the error and select "! Execute SQL".
the issue is not management studio
this will take place even on a front end application
the issue is having identity column in a table
for some reason this behavior started when SQL 2012 came to life

SQL Server Management Studio - Adding/Moving Columns require drop and re-create?

Why do I get message that the table needs to dropped and re-created when I add/move columns?
I believe this happens after adding foreign key constraints.
What can I do to add new columns without dropping table?
If you're more interested in simply getting SSMS to stop nagging, you can uncheck the "Prevent saving changes that require table re-creation" setting in Options->Designers->Table And Database Designers. The table(s) will still be dropped and re-created, but at least SSMS won't pester you quite as much about it.
(This assumes you're working in an dev/test environment or in a production environment where a brief lapse in the existence of the table won't screw anything up)
Because that's how SQL Server Management Studio does it (sometimes)!
Use TSQL's ALTER TABLE instead:
ALTER TABLE
ADD myCol int NOT NULL
SQL Server (and any other RDBMS, really) doesn't have any notion of "column order" - e.g. if you move columns around, the only way to achieve that new table structure is be issuing a new CREATE TABLE statement. You cannot order your columns any other way - nor should you, really, since in the relational theory, the order of the columns in a tuple is irrelevant.
So the only thing SQL Server Management Studio can do (and has done all along) is:
rename the old table
create the new table in your new layout you wish to have
copy the data over from the old table
drop the old table
The only way to get around this is:
not reordering any columns - only add new columns at the end of your table
use ALTER TABLE SQL statements instead of the interactive table designer for your work
When you edit a table definition in the designer, you are saying "here's what I want the table to look like, now work out what SQL statements to issue to make my wishes come true". This works fine for simple changes, but the software can't read your mind, and sometimes it will try to do things in a more complicated way for safety.
When this happens, I suggest that, instead of just clicking OK, click the "Script" button at the top of the dialog, and let it generate the SQL statements into a query window. You can then edit and simplify the generated code before executing it.
There are bugs in SSMS 2008 R2 (and older) that are useful to know:
when the table data is changed, ерушк rendering in SSMS is autorefreshed by SSMS in its already opened tabs (windows) - one should press Ctrl+R to refresh. The options to force refreshing do not appear in SSMS GUI - through buttons, menus or context-sensitive options (on right-clicking)
when a (table or database) schema is modified, like adding/deleting/removing a column in a table, SSMS does not reflect these changes in already opened tabs(windows) even through Ctrl+R, one should close and reopen tabs(windows)
I reported it few years ago through Microsoft Connect feedback, but bugs were closed due to it is "by design"
Update:
This is strange and irritating to see in desktop product developed during 2 decades, while this (autorefreshing) is being done by most webapplications in any browser

How come the message "Table is marked for deletion" keeps appearing?

Using SQL Server 2008 and I'm doing some schema construction in the Management Studio designer.
I created a table early in the process called "Animal", but then decided to delete shortly after. I deleted it via the tree view in Management Studio (right-click delete).
Now I'm late in the process, I would like to recreate the table "Animal" but with different fields.
The second time round with Animal gets created fine, but when I try to add the table to my diagram I get the message "Table 'Animal' is marked for deletion, can't be added to the diagram or opened in the table designer".
What's the deal? How can I use this table normally again and not suffer from older table naming conflicts?
Alternatively, if the table is marked for deletion, can I actually invoke deletion somehow? Then recreate another table with the same name.
This is a little annoying. Would appreciate any help.
I was able to fix this problem by closing SQL Management Studio and re-opening it. I bet simply severing the connection to the server and reinstating it would work.
Just Severing the connection from SQL Management Studio did not work. But restarting the SQL Management Studio worked. Still better than restarting the system.
What worked: rebooting.
Restarting the entire computer worked.
Simply restarting the db server didn't work, but rebooting the entire machine did.
I have no idea why!
I know this is old, but I came across this same problem. I found the solution here:
http://weblogs.asp.net/atlaszhu/archive/2010/04/04/sql-server-2008-database-diagram-quot-saving-changes-is-not-permitted-quot.aspx
which basically says there is an option in the "Tables and Database Designers" section called "Prevent saving changes the require table re-creation" - when this is checked, you will receive errors like you've asked about.
When I disabled this option, I was able to save my database diagram.
If you're using the schema tool, it may be simpler to recreate the schema. In my experience I've found that tool to have some odd quirks that have been fixed by simply recreating the schema ( the graphical view of it, not the whole db :) )
From MSDN, to delete a table from the Visual Database Designer:
In your database diagram, select the table you want to remove.
Right-click the table and choose Remove Table from Diagram from the
shortcut menu.
-or-
Press the ESC key.
If the table has unsaved changes as a
result of edits you made in the
database diagram, a message prompts
you to save the table before removing
it.
The table is removed from your diagram
but it continues to exist in the
database.
So, to delete it, you'll have to do that from script or object explorer (MSDN):
To delete a table from the database
In Object Explorer, select the table you want to delete.
Right-click the table and choose Delete from the shortcut menu.
A message box prompts you to confirm the deletion. Click Yes.
There might be any link remaining of that table on any diagram just open DB diagrams and it will tell you that this table is removed.
Just close SQL Server Management Studio, disable network connection (unplug cable or disable wifi), re-open SQL Management Studio and reconnect the network. It should work fine now.

Resources