Data has always changed(SQL Server Management Studio) - sql-server

I am using SQL Server Management studio and keep getting the same error, and the only way to get rid of it(usually) is to reset the SQL server(which is very annoying, and sometimes impossible from my remote machine)
When I add a row to a table, and then I goto "Edit Top 200 Rows" it all displays and acts fine, and I go to a field I want to change. Then I change something like 0 -> 1 and then I get a nice friendly popup saying "Data has changed since the Results Pane was last retrieved... Optimistic Concurrency Control Error" If from here I say "Yes to commit changes to database anyway" I get "No row updated... The updated row has changed or been deleted since data was last retrieved"
It's a very annoying little thing, cause I don't like having to look up RIDs and then make an update statement(and possibly having to worry about escaping 's by hand)
Is there some way to turn this concurrency checking off or something? I know the row wasn't updated or anything, and I tried completely closing Sql Server Management Studio and reopening to no avail, and also tried refreshing the result pane, or refreshing the column view. Nothing gets rid of this error, but if I do a "update ... set ...=..." then it works, so I'm not really having any concurrency error..

I had exactly the same problem. It looks like this article was pretty good at solving it. Seems all sorts of buggy things in some versions.
See: You may receive an error message when you try to use SQL Server Management Studio to update a row of a table in SQL Server 2005.
The table contains one or more columns of the text or ntext data type. The value of one of these columns contains the following characters.
Percent sign (%)
Underscore (_)
Left bracket ([)
The table does not contain a primary key.

http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/7bf48a75-58a0-41d7-b514-b804a49ae8ff/
it seems to be a bug in SSMS I don't think I have over 4000 characters, but I can confirm this only happens on rows that have more data than others.. there seems to be some abritary limit that I can't quite put my finger on..
So, plainly SSMS is complete crap. I'll be looking for a new SQL manager..

You shouldn't edit a table directly from the table view.. you should use an UPDATE sql command.

Related

SQL Server Mgmt Studio shows "invalid column name" when listing columns?

I'm used to scripting in Python or Matlab, and my first couple hours with SQL have been infuriating. I would like to make a list of columns appear on the screen in any way, shape, or form; but when I use commands like
select *
from "2Second Log.dbo.TagTable.Columns"
I keep getting the error:
Invalid column name '[the first column in my table]'.
even though I never explicitly asked for [the first column in my table], it found it for me. How can you correctly identify the first column name, and then still claim it's invalid!? Babies will be strangled.
This db was generated by Allen Bradley's FactoryTalk software. What I would really like to do is produce an actual list of "TagName" strings...but I get the same error when I try that. If there were a way to actually double click the table and open it up and look at it (like in Matlab), that would be ideal.
Echoing juergen's suggestion in the comment above. It looks like you're running the query on the master database, not the 2Second Log database that actually has your table. (You can tell this by looking at the database in the dropdown in the top left of your screenshot). Two things you can do:
Change the dropdown in the top left to 2Second Log. This will target your query to a different database
Put your database name in brackets as suggested by juergen i.e. select * from [2Second Log].dbo.TagTable
As an side, if you're looking for a good SQL tutorial, I highly recommend the Mode SQL tutorial. It's a fantastic interactive platform to get your SQL feet wet.
always use brackets when names/field have spaces or dashes.
select * from [2Second Log].dbo.TagTable

Why won't SQL Server CE for WebMatrix 3 allow me to manually add a row to a table in my database?

I haven't had this problem until I first tried to manually add data to a database since my upgrade to WebMatrix 3, so I don't know if this is a bug or some kind of fault prevention.
I have defined a very simple table with the primary key as int and set it to not allow nulls, and be of the type IsIdentity so that the int value will automatically increment, as needed.
A pic of that is shown here:
Okay, seems simple enough, but when I try to manually add data to the table, it, as it should, does NOT allow me to modify the primary key value in any way (because it is automatic).
All I do is put in a couple of string values to the type and location columns and it tells me that it couldn't commit changes to the database because of the invalid value in the primary key field (it acts as though it is gonna try to throw NULL in as the value, but this should be overridden when it automatically adds the row. The user-interface does not allow me to control or edit this value in anyway).
A pic of this is shown here:
What is this? Some kind of bug? Is it a new rule that WebMatrix does not allow a developer to add values to the database manually? Do I have to write a query every time I want to add something to the database? Am I in the Twilight Zone? (Okay, sorry about the last one...)
Also, I've noticed that if I don't have IsIdentity set, I can edit the field, put a PERFECTLY VALID integer therein, and it still errors the same way, so I use ESC to backup my changes, then hit refresh, only to find that it did, indeed, add the row anyway :/ . So, this interface seems kind of buggy to begin with. In my scenario above (using IsIdentity), it DOES NOT add the row anyway, unfortunately.
--------------------UPDATE--------------------------
I just recently downloaded a WebMatrix update, and it appears that they have fixed this! Yay! (till now I was just querying generic INSERT INTO statements and editing them manually from there).
I think the SQL CE tooling with WM3 is broken, suggest you look at other tools for editing data - I can recommend the standalone SQL Server Compact Toolbox (disclosure: I am the author)

SSAS cube processing error about column binding

This is an error message I get after processing an SSIS Cube
Errors in the back-end database access module. The size specified for a binding was too small, resulting in one or more column values being truncated.
However, it gives me no indication of what column binding is too small.
How do I debug this?
This error message has been driving me crazy for hours. I already found which column has increased its length and updated the data table in the source which was now showing the right length. But the error just kept popping up. Turns out, that field was used in a fact-to-dimension link on Dimension Usage tab of the cube. And when you refresh the source, the binding created for that link does not refresh. The fix is to remove (change relationship type to 'No Relationship') and re-create that link.
Upd: Since that answer seems to be still relevant, I thought I'd add a screenshot showing the area where you can encounter this problem. If for whatever reason you are using a string for Dimension-to-Fact link it can be affected by the increased size. And the solution is described above. This is additional to the problem with Key, Name, and Value Columns on the Dimension Attribute.
ESC is correct. Install the BIDS Helper from CodePlex. Right click on the Dimensions folder and run the Data Discrepancy Check.
Dimension Data Type Discrepancy Check
This fixed my issue.
Open your SSAS database using SQL Server Data Tools.
Open the Data Source View of the SSAS database.
Right click an empty space and click Refresh
A window will open and show all changes to the underlying data model.
Documentation
Alternate Fix #1 - SQL Server 2008 R2 (haven't tried on 2012 but assume this will work).
Update / refresh your DSV. Note any changed columns so you can review.
Open each dimension that uses the changed columns. Find the related attribute and expand the properties KeyColumns, NameColumn and ValueColumn.
Review the DataSize properties for each and if these do not match the value from the DSV, edit accordingly.
Alternate Fix #2
Open the affected *.dim file and search for your column name / binding.
Change the Data Size element: <DataSize>100</DataSize>
As Esc noted, column size updates can affect the Dimension Usage in the cube itself. You can either do as Esc suggests, or edit the *.cube file directly - search for the updated attribute and related Data Size element: <DataSize>100</DataSize>
I've tried both fixes when a column size changed, and they both work.
In my case the problem was working on the cube on live server.
If you are working on the cube live, connecting to the server this error message pops up.
But when you are working on the cube as a solution saved on the computer you do not get the error message.
So work on the cube locally and deploy after making changes.
In my particular case, the issue was because my query was reading from Oracle, and a hard-coded column had a trailing space (my mistake).
I removed the trailing space, and for a good measure, Cast the hardcoded value to be CAST ('MasterSystem' as VarChar2(100)) as SOURCE
This solved my particular issue.
I encountered this problem. The question decided by removing leading and trailing spaces and functions rtrim and ltrim.
I encountered the same problem, refreshing the data source did not work. I had a Materialized Referenced Dimension for the Fact Partition that was giving me the error. In my DEV environment I unchecked Materialize and processed the partition without the error.
Oddly, now I can enable Materialization for the same relationship and it will still process without issue.
Simple thing to try first - I've had this happen several times over the years.
Go to data source view and refresh (it may not look like anything happens, but it's good practice)
Edit dimension. Delete the problem attribute, then drag it over again from the data source view listing.
Re-process full.
As others have mentioned, data with trailing spaces can be the cause as well. Check for them: SELECT col FROM tbl WHERE col LIKE '% '
Running into the same problem, the answer from Esc can be a solution too. The cause is much more 'hidden' and the more obvious solutions 'Refresh' and 'Data type discrepancy check' don't do any good in my case.
I did not find a proper way to "debug" this problem.

Refreshing a table in SQL server management studio

I have opened a table in SQL server management studio express.
How do I update it?
As changes made outside the studio application do not show unless I close and reopen the table. Surely there must be a better way of doing this?
In SSMS (SQL Server Management Studio) press Ctrl + R
In Visual Studio Press Shift + Alt + R
I am not sure if I understand exactly what you want, but if you want to see the changes, the query that loaded the table has to be re-executed. You can do this by clicking on "Execute SQL" (or selecting it from the context menu).
Depending on what you mean with "opening the table" (select top x rows, edit top x rows, etc ) you also might try to hit F5 (works for "Select TOP x Rows") - which simply executes the previous statement.
As a rule, manually editing data in SQL Server is a bad practice.
It's not repeatable. Anything you do is limited to your window and once it's gone it's gone.
It's easy to make mistakes. Click the wrong cell, fat-finger a decimal point, etc.
A much better solution is to create and save insert or update scripts. These are editable, reviewable, and rerunnable.
If you need to recreate your database or replicate something now, you need to manually type in all the same values you typed in before. If you script it out, you just run the script and can have the same data as many times as you can hit F5.
It is much easier if you just create a query referencing on that table. Then create select statement giving all rows from that table.

Edit data from result grid

I would like to edit data directly from result grid in ssms. eg:
When I execute SELECT TOP 10 * FROM some_table, I want to edit data directly from result grid.
I don't want to open some_table and edit from there.
I know that result grid is read-only, but maybe someone written addin for it.
You can't edit the data from within the result grid. You'd have to go via the "open table" route if you want to edit the data manually instead of using UPDATE/INSERT SQL statements.
Is there a reason you specifically want to use the result grid instead?
You can specify a query when you go via open table to limit the results if that's your reason? There's a "Show SQL Pane" button in the top toolbar you need to select (square box with "SQL" written in it).
I have very large database (70+ GB) with so many tables.
I'm using Red Gate's SQL refactor for intellisense and few other things.
It's so boring to type in update sql statements every time I need to change single field.
It also takes some time to find that table in the Object explorer.
Intellisense doesn't work when I use "Show SQL Pane".
I'm new to SQL Server and have used the Oracle product 'PL/SQL developer' by All Round Automations at a previous job... It would allow you to do a SELECT in the query window and then simply add "FOR UPDATE" to the end of your refined SQL SELECT and 'ta-da' you can now edit the results in a nice grid. No need to Open Table View, click the SQL button, paste in the SQL you you have been working on and then hit execute ;)
EMS SQL Manager for SQL Server allows to update data directly inside a results grid.
This tool is boring for typing new requests (poor intellisense and error management) but fine for this. I always have the two tools opened.
If you right click on the table and choose edit top 200 records, it produces a result screen with an query.
Add to this your query and then you can edit the records in the result screen.
Also you can change the 200 to a number you want (2000).
The "results" pane is not just results.
Results in text
Assorted time and IO statistics
Estimated and actual execution plans
Row counts, Error messages, PRINT output
etc
This is why they are separate.
Feel free to write your own add-in :-) Or here
SQL Server ISN'T Access!
When you run a query and get the results - thats exactly what you are doing, reading the data, not opening the table for editing. Can you imagine the necessary transactional control around allowing the results window to be edited? The locking would probably grind SQL to a halt - I hope no-one ever writes that kind of add-in!

Resources