ORA-01775: looping chain of synonyms with no synonyms - sql

I have been using a script run from a batch file to create and edit a table. As far as I cold tell it was working and I worked on a different issue.
However, at some point something has gone wrong.
In PLSQL Developer I tried to select from the table and I got the error:
ORA-01775: looping chain of synonyms
If I try to drop the table I get the error:
ORA-00942: table or view does not exist
I have never, intentionally, created and synonyms so I checked with this:
SELECT owner,synonym_name,table_owner,table_name from dba_synonyms where synonym_name='broken_table';
There are no results returned. The other similar questions on here do not seem to have the same situation or the actual solution, can anyone give any advice on how to proceed here?
(as you can guess sql is not my strong suit).

I got the ORA-01775 error from trying to access a table via a synonym where the table did not exist. The table had been dropped and had not yet been recreated. The synonym was still there. There was no looping synonym.

Related

Oracle error ORA-00942, rails 3 environment

Hoping someone will have some insight into this issue. There are a lot of posts regarding this error, and I have read all of them.
Running a Rails 3 app on an Oracle 11 db. Rails attempts to create a new object, and it blows up (500) and I get back ORA 00942, table or view does not exist. Table does exist. Sequence exists and I can both write to the table and pull sequence numbers using SQL Developer and the same credentials that are used to run the rails app. Permissions look fine. I have looked at the rails model associations, and tracked down all of the tables and sequences of those objects as well.
One of the columns in the table is a CLOB column, and it seems like there can be issues with that datatype. But those seem to come from Java environments.
I have schema owner credentials, is there a log I could check to see the exact sql statement that is causing the error? Any sort of lower level logging I could turn on to get more insight into what is going on?
This ended up being a missing grant on a sequence. Very frustrating that Oracle reports this as 00942.
If you get this problem, and the table is present, look carefully at the grants that have been made to both the table and the sequence. You can do this with the following syntax in SQL Developer:
select * from DBA_TAB_PRIVS where table_name = name_of_thing_you_want
Yes, sequences also fall under the table_name heading.
To create a grant:
grant select ON the_name_of_the_object TO name_of_the_user
I hope this helps someone.

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;

Running a basic select on SQL Sever asks for column name that doesn't exist, why?

We had another developer come through and complete some work for us. Unfortunately he didn’t work well within our team and management let him go.
Because of this now I’m stuck debugging his code and undoing work that was done. He did not document his code (one of the reasons he was let go), rarely notating anything, therefore I have no idea where to begin looking.
When I run a basic SELECT on two specific tables in our DB:
SELECT * FROM table_name
Using SQL Server Management Studio I get this...
Msg 207, Level 16, State 1, Line 1
Invalid column name 'eventTime'.
There was an eventTime column but wasn’t necessary and wasn't being used in any PHP file, however it seems somehow directly tied to the table now and I have no idea where to look to find it. The error message provided is pointing to my SELECT statement, but there is nothing wrong with it, nor does it even reference the eventTime column.
I’ve looked and there don’t seem to be any triggers or stored procedures referencing this table. Is there another way I can try to track this down?
This sounds like a hard'ish problem. Here are some ideas.
My first thought is that table_name is a view, and somehow the view has gotten out-of-sync with the underlying table definitions. I have seen problems with types in some circumstances. I imagine the same could happen with column names.
The next thought is that table_name has computed columns. In this case, the computed columns could be using a function and the function call could be generating the error. I cannot think of any other way to run code with a simple select.
I don't think the problem would be a foreign key constraint unless. So, a third option is that a foreign key constraint is referencing a table in the same database but a different schema. The different schema could have permissions that make the table inaccessible.
For any of these, scripting out the definition in SSMS will help you fix the problem.

Creating View Using Synonyms in a Database Project (Visual Studio 2012)

I am hitting my head against the wall for a weird error I am getting in VS2012.
I have a database project which includes some Synonyms. They are basically table references to another database in order to avoid dynamic SQL generation. I already added the required reference database for the Synonyms. Everything works great except a couple of views that are using some of those Synonyms! Since I am using the same Synonyms in my stored procedures and they are not causing any build failure, I am not sure why the views are causing problem.
The error message says: "SQL05313: Synonym 'xxx' refers to an invalid object.'
Here is a sample code -
dbo.MyTable.sql...
CREATE SYNONYM [dbo].[MyTable] FOR [$(FOO_DB)].[dbo].[MyTable];
dbo.MyProc
CREATE [dbo].[MyProc] AS SELECT col1, col2, col3 FROM [dbo].[MyTable];
SUCCESS: this works
dbo.MyView.sql...
CREATE VIEW [dbo].[MyView] AS SELECT col1, col2, col3 FROM [dbo].[MyTable];
ERROR: SQL05313 Synonym '[dbo].[MyTable]' refers to an invalid object.
Has anyone else faced this issue? If yes, I appreciate your assistance :)
For some reason, reference errors in SPs are treated as warnings, while the same in views is treated as an error. Thus the error just means that the reference to $(FOO_DB) is not working - double check that the variable reference is set up correctly.
If you are referencing another DB project, it must be compilable to .dacpac individually (e.g. you cannot create circular references). If you really need circular reference (view in FOO_DB1 references FOO_DB2, and view in FOO_DB2 references FOO_DB1), look into composite objects (database reference of type same database).
I got this error, and I eventually found that I had run CREATE SYNONYM fred FOR ... instead of CREATE SYNONYM **dbo**.fred FOR ...
It therefore created the synonym in my personal schema, instead of dbo, and this stopped the CREATE VIEW.
I know that your code includes [dbo].[MyTable], but do you have an identical synonym in your own schema, from a previous CREATE SYNONYM command that did not include the [dbo], which might be confusing the CREATE VIEW command?

How to deal with a Firebird table that's apparently both there and not there

I've just had something very strange happen to me with a Firebird database.
I was trying to create a table, and the CREATE TABLE failed for some reason. But now it's stuck in a very strange state:
If I try to CREATE TABLE again with the same table name, it gives an error: the table already exists. But if I try to DROP TABLE that table, it gives an error: the table does not exist. Trying to SELECT * FROM that table gives the "table does not exist" error, and the name does not show up in the metadata query:
SELECT RDB$RELATION_NAME
FROM RDB$RELATIONS
WHERE RDB$SYSTEM_FLAG=0
So for some reason, the table really seems to not be there, but I can't create it because something somewhere indicates that it does exist.
Does anyone have any idea how to fix this? I've already tried closing all connections to that database, which has helped with inconsistency issues in the past, but this time it doesn't help.
You didn't give details about what was the error when you tried to create the table, so I cannot comment it. But RDB$RELATIONS is not the only system table affected when you create a table. Maybe you are now in an inconsistent situation where some information about that table exists in some system tables and doesn't exists in others.
Another option is corrupted indexes in the system tables, so the record is not there but the index think it still exists.
Try to do a backup/restore and see if it helps. It it doesnt work, try to search for records related to that "non created" table in the other system tables (RDB$RELATION_FIELDS, etc) and if you find any, try to delete them.
As a last option, you may create a new clean database with correct metadata and pump your data to it using IBDataPump.