SQL Server invalid column name error complaining about column long gone - sql

EDIT: Please read my answer below first, before you decide to read and try to understand the text below. You may not find it's worth it when you see what was going on ;)
I have a weird problem: SQL Server 2008 R2 keeps complaining about an invalid column that is indeed not there anymore, but I'm not using it either!
I can't update any rows in that table anymore from within my own application, where no reference to the column can be found, because I always get this error now.
I then wanted to update straight in SSMS as a test, but when I edit the rows there, I still get this error.
What happened before: I made a column called CertcUL varchar(1), and that worked. After a while it appeared I needed it to be a varchar(30), so I edited the table design and turned it into a varchar(30).
From that moment I saw that I could only update this column when I stored 1 character. When I tried to store more, I got an error warning me about string or binary truncation. So somehow, the previous varchar(1) info was still present in the DB.
When I renamed that column to CertcUL2 or Cert_cUL, the same things kept happening! So changing the column name does not change the underlying cause. Also when just trying to add some characters straight in SSMS.
When I deleted the column, and added a new one with varchar(30) straight away, and called 'test', the same problem remained! This column still only allows me to store one character! The column was the one but last column. Making it the last column does not help either. Only when creating an new column while keeping the other column, I can have columns that behave properly.
So somehow, SQL Server saves some meta data about a column, even when it has been deleted. And does not look at the name, but rather at the order in which the columns are created.
Does anyone have an idea how this can happen, and how I can fix this besides (probably) dropping and recreating the whole table?
Thanks!

Oh my God I feel so stupid...it's a trigger that still contains this column. I just noticed it because when trying to update with an update statement. Only this way I got a proper error message, so I now know what's going on. So stupid that I didn't check the triggers! Sorry about that!
More info: I had an update trigger on this table A, that copies all current values to a history table B that contains the same columns. So I did change the length of the column CertcUL in table A, but forgot about table B. So it was very confusing to see the old column name popping up every time, and see it complianing about string truncation while my column in table A seemed just fine.
Sorry again :)

Related

Not existing column in the current network's table but still visible in the column selection

I have imported data table to my cytoscape map for the following continuous mapping accorging to values. After some time, I have imported another data table and then deleted the previous one. The original data are not present in either the node or edge table but I still can see the names of the original columns when selecting column for continuous mapping i. g. for size or colour. Moreover, this warning appears: "The current table does not have the selected column. Please select another column." Do you know how to solve this so that I no longer see the names when these columns are not even in the table?
I would be grateful for any ideas.
I have tried to delete the data table and import the data again but it didn't help. I have also tried to clone current network and import data to the new map, but the old names are still present in the column selection.
Do you know how to solve this so that I no longer see the names when these columns are not even in the table?
I would be grateful for any ideas.
A couple points and then a couple suggestions:
The style is going to "remember" the selected column name, even if you delete it since it doesn't know what to change it to. It will add a warning icon mentioning that the column is missing. You have to choose a new column (or reload the missing column) to address that issue. [I think you know this already, but just stating for completeness :)]
The pulldown list of column names should be updated when you delete table columns. This does indeed sound like a bug.
Are you running the latest Cytoscape 3.9.1?
Have you tried selecting another style and then returning back to this style? That might "refresh" the column name list.
Have you tried saving/restoring the session?

Column Hardware_ID get's automatically renamed to Hardware-ID

can someone explain why this happens?
I don't like to call the column [Hardware-ID] if I can help it because I have to add brackets in my code if I use the dash... but it seems if I name id anything else (I tried dbhardwareid as well as Hardware_ID), I leave the table in a seemingly inconsistent status where the select shows a name different than the design view.
I deleted and recreated the table a number of times to no avail.
My guess is that table exists under two different schemas, perhaps you are looking under one schema in Object Explorer and different schema in Query Window. Could you verify the schema?

SQL identical values not matching

I'm experiencing something strange when joining SQL tables.
Let's say I want to output an image for each result where
tableA.FullNameA = tableB.FullNameB
I am entering the data in table B with a php form. To my human eyes, the names I have are identical in both columns. However, it does not detect a match. If I then manually go into the db and copy and paste the name from tableA.FullNameA to tableB.FullNameB (and when it is overwritten, there is no discernible change to the text) then it miraculously matches and my join is successful.
Is this something to do with encoding of the data when it is added to the DB? I have never come across this before - does anyone recognise this issue?
Thanks in advance for your help.

SQL Server find and replace multiple values at once for normalisation

I have a table I imported from excel. Everything was imported as strings to get started and gradually the data types were fixed.
I am now going through the process of normalisation and to start I done a select distinct on a given row to extract out the columns that were repeated to another table with an id.
Now I am trying to replace every occurrence of the string in the original table, with the id of the corresponding string in the other table.
I can do it one by one with something like this no prob...
UPDATE myTable
SET myCol = REPLACE(myCol, 'String', 'Num')
and later convert the myCol to an int.
But having to run this, and various variations on it for every string in the system is very error prone.
For example, if I accidently use the same number twice, replacing every string...I cant tell anymore which recordset originally belonged to the first update, and which were the new ones. This is a problem when the dataset is as large as mine.
Is there some way I can combine this with a join on the tables and have the system automate the process for me. I can imagine with normalisation being such a big thing for the last 30 or more years, this issue must have been met and resolved by now.
Any help would be appreciated.

Table '' could not be loaded

I was hoping someone out there may have experienced this before.
I have a database that (as far as I'm aware) is in perfect working order. I have no problems with it whatsoever. I'm trying to add a column to some of the tables but when I save the changes I get the following message
This error message is then stuck in a loop and the only thing I can do is kill the SQL Management Studio process.
The database exists, the table exists, I can run any query I want against it, I just can't make any changes to it.
The steps I'm taking are:
Right click table
Select "design"
Right click "add new column" in designer
Fill in the details as normal
Click Save
Anyone know how I can resolve this?
Thanks.
It's telling you that you haven't specified the name of the table. The name of the table should be between the two single quotes.
Without knowing how you're doing this it's hard to tell more, but the first two possibilities off the top of my head are:
If you're looping through tables in code to do something, you may be hitting a record with no table name.
If it's pure SQL, perhaps an error in your syntax