SQL Server Invalid Column name after adding new column - sql

I just added an identity column to an existing table with data through the SSMS Designer, the table updates fine and I can run a select query against it successfully, but after the query finishes I noticed that the new column is underlined in red with an error indicating it's an invalid column name.
Why does this occur? I would expect the query to fail if the column was invalid.
Does the SSMS keep some type of internal reference to the old table that must be flushed?
I tried closing the DB connection and reopening it, but still the same error. Not sure what I'm missing here.
SELECT TOP 100
[PRIMARY_NDX_Col1],
[NEW_Col], --QUERY EXECUTES SUCCESSFULLY, BUT THIS IS UNDERLINED RED AS AN INVALID COLUMN
[Col3]
FROM [dbo].[MyTable]

you can either
Press Ctrl+Shift+R
OR
Go to Edit >> IntelliSense >> Refresh Local
Cache

Related

Microsoft SQL - "Invalid column name" after deleting column

I am using Azure SQL in Microsoft SQL Management studio. I firstly renamed a column called ssma$rowid to ssmarowid, then I deleted this column using
ALTER TABLE "myCoolTable" DROP COLUMN "ssmarowid";
SQL management studio prompted me that the deletion was successful, but now that I try to run any UPDATE commands on my table in different columns, I get this error message:
Invalid column name 'ssma$rowid'.
If I try to edit a cell without scripting, by right-clicking my table, then Edit top 200, I get this error message:
The data in row xxx was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: Invalid column name 'ssma$rowid'
Invalid column name 'ssma$rowid'
Invalid column name 'ssma$rowid'
Correct the errors and retry or press ESC to cancel the change(s)
The column ssma$rowid does not appear in my table at all when I run a SELECT statement, and if I explicitly try to pull the column ssma$rowid or ssmarowid SQL tells me that they don't exist.
It appears that my column has been lost in the ether somewhere, where can I start searching to find my rogue column?
Ensure the ALTER TABLE states the column between brackets like this :
ALTER TABLE [myCoolTable] DROP COLUMN [ssmarowid];

Syntax Error or Access Violation comes up when logging into the program

our program connects to a db and when you sign into the program, it's throwing this error: "Syntax error or access violation" along with "Cannot insert the value NULL into column 'ID', table 'CADDB.dbo.AuditTrail'; column does not allow nulls. INSERT fails"
I've tried Microsoft's Fix to Use ANSI Nulls, Padding and Warnings in the ODBC connections, but it still occurs.
Can someone point me where to look? I believe it's corrupt data in the db... but not 100% sure. I will attach the error that gets logged with that message if you need me to.
The exception showed you the root cause that your app is trying to insert NULL value into column ID, a column not allowing NULL. If this is caused by your application's bug and you also want to insert a NULL value into ID column. Then you may change the table to allow NULL for column ID or use a special value representing NULL (not recommended) for the insertion.
Otherwise, it is more likely to be your application's issue.
You need to make sure the column from CADDB.dbo.AuditTrail allow nulls,check your table schema for that, or you could try insert into the column ISNULL(value,'NULL'), which is the string null not actual NULL.
ANSI_NULL query option only be took into effect when doing the value comparison. which is IS NULL/IS NOT NULL when it is set to ON or using =/!=/<> when set to OFF.
Use the ISNULL() function. Example ISNULL(column Name, '')
I'm not sure if you're using T-SQL script in your code to access the table, or you can alter the column to allow nulls.
Thank you everybody! The issue was the db was corrupt. I got a working backup of the same db and it works fine without any errors.

SQL - Table not found after backup

I saved a SQL table before deleting some information from it with the sql statment:
select * into x_table from y_table
After doing some operations, I want to get back some information from the table I saved with the query above. Unfortunately, MS SQL Server MGMTS shows an error saying that the table does not exist.
However, when I put the drop statement, the table is recognized - and the table is not underlined.
Any idea why this table is recognized by the drop table statement and not the select from statement. This seems strange for me.
EDIT:
Thank you
It may be that the table isn't underlined in your drop table command because its name is still in your IntelliSense cache. Select Edit -> IntelliSense -> Refresh Local Cache in SSMS (or just press Ctrl+Shift+R) and see if the table name is underlined then.
Edit:
Another possibility is that your drop table command might be in the same batch as another statement that creates the table, in which case SSMS won't underline it because it knows that even though the table doesn't exist now, it will exist by the time that command is executed. For instance:
None of the tables one, two, or three existed in my database when I took this screenshot. If I highlight line 6 and try to run it by itself, it will fail. Yet you can see that two is not underlined on line 6 because SSMS can see that if I run the whole script, the table will be created on line 5. On the other hand, three is underlined on line 9 because I commented out the code that would have created it on line 8.
All of that said, I think we might be making too much of this problem. If you try to select from a table and SQL Server tells you it doesn't exist, then it doesn't exist. You can't rely on IntelliSense to tell you that it does; the two examples above are probably not the only ways that IntelliSense might mislead you about the current status of a table.
If you want the simplest way to know whether an object with a given name (like x_table) exists, just use:
select object_id('x_table');
If this query returns null, x_table doesn't exist, regardless of what IntelliSense is telling you. If it returns non-null, then there is some object out there with that name, and then the real question is why your select statement is failing. And to answer that, I'd need to see the statement.
A lot of posts like this, you have to copy in 2 statements :
CREATE TABLE newtable LIKE oldtable;
INSERT newtable SELECT * FROM oldtable;

Delete from sql server 2000?

I want to delete all rows from table in sql server 2000 but whenever I want to delete manually or with query it shows error. In help tab it shows ODBC error: <0s>.
My table contains some '0' values but its datatype is String. Is that's the reason for this
error.
code is:
stat2=conn.createStatement();
stat2.executeUpdate("Delete * from pat.dbo.PHPL");
"Key column information is insufficient or incorrect. Too many rows were affected by update" that's warning and when click help it shows: ODBC error: <0s>. An ODBC error has been generated. You might have deleted a record that has a foreign key value related to it, or you might have violated a check constraint. For details, refer to your ODBC documentation.
Use
Truncate Table PHPL
I think you have duplicate identities, check you are not allowing duplicates on this column.

Why doesn't SSIS OLE DB Command transformation insert all the records into a table?

I have an SSIS package that takes data from Tables in an SQL database and insert (or update existing rows) in a table that is another database.
Here is my problem, after the lookup, I either insert or update the rows but over half of the rows that goes into the insert are not added to the table.
For the insert, I am using an Ole Db Command object in which I use an insert command that I have tested. I found out why the package was running without error notification but still not inserting all the rows in the Table.
I have checked in sqlProfiler and it says the command was RCP:Completed which I assume means it supposedly worked.
If I do the insert manually in sql management studio with the data the sql profiler gives me (the values it uses toe execute the insert statement with), it works. I have checked the data and everything seems fine (no illegal data in the rows that are not inserted).
I am totally lost as to how to fix this, anyone has an idea?
Any specific reason to use OLE DB Command instead of OLE DB Destination to insert the records?
EDIT 1:
So, you are seeing x rows (say 100) sent from Lookup transformation match output to the OLE DB destination but only y rows (say 60) are being inserted. Is that correct? Instead of inserting into your actual destination table, try to insert into a dummy table to see if all the rows are being redirected correctly. You can create a dummy table by clicking on the New... button on the OLE DB destination. It will create a table for you matching the input columns. That might help to narrow down the issue.
EDIT 2:
What is the name of the table that you are trying to use? I don't think that it matters. I am just curious if the name is any reserved keyword. One other thing that I can think of is whether there are any other processes that might trigger some action on your destination table (either from within the package or outside of the package)? I suspect that some other process might be deleting the rows from the table.