Table hiding in SQL Server database? - sql-server

I am transferring data into a table all of sudden I went throgh a crazy problem I have never seen in my career.
Msg 208, Level 16, State 1, Line 1
Invalid object name 'dbo.Table_Report'.
Then I tried to create a table with same name and again I got fallowing error
Msg 2714, Level 16, State 6, Line 2
There is already an object named 'Table_Report' in the database.
What went wrong I need to send data in to table asap but I am unable to do that at least I can't delete the table
Cannot drop the table 'Table_Report', because it does not exist or you do not have permission.
Note: I have admin rights on the database.
Can you guys look what went wrong??

select Schema_name(schema_id) from sys.tables where name ='Table_report';
which schema is the result?
If you want to move it do that:
ALTER SCHEMA dbo
TRANSFER SchemaSource.Table_report;
http://msdn.microsoft.com/en-us/library/ms173423%28v=sql.105%29.aspx

We recently had this issue at work, what has probably happened is that someone created a table called Table_report under their username (instead of as the DBO - Database Owner). You should try:
Drop Table Table_report
Then rerun your query.
EDIT: You should be able to run the following query to find all the existing tables in the database and find out which username is attached to the table
select ss.name ,st.* from sys.tables st
inner join sys.schemas ss
on ss.schema_id = st.schema_id

I know this is nearly a decade old but, hopefully, it'll help other people that land on it during a search.
Table_Report could be ANY type of object. Do a search on sys.objects (to start with). This will also return the Schema Name if there's an object named 'Table_Report' and the 'type_desc' column will let you know what the object type is. Of course, the code needs to be executed in the database you want to search in.
SELECT SchemaName = OBJECT_SCHEMA_NAME(object_id)
,*
FROM sys.objects
WHERE name = 'Table_Report'
;
I also agree with what #GBoehm stated in a comment on this thread. Don't drop any objects until you're sure your not going to make someone else's stuff go haywire. You don't want your work to become a resume generating event. :D

Related

Can create a table but doesn't display in Object explorer, can't select, or delete table?

Using SQL Server 2016. Have a locally hosted database that uses the Windows login for the sa, which is what I am using to login.
Yesterday I ran
CREATE TABLE [Otis].[AnalyzerGroups]
(
[id] [int] IDENTITY,
[Name] [varchar](50) NULL
);
and got command successfully completed. Today I tried selected from this table but got an error:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'Otis.AnalyzerGroups'
So I thought I misremembered and tried running the create statement again but then got the error -
Msg 15530, Level 16, State 1, Line 1
The object with name "AnalyzerGroups" already exists.
The statement has been terminated.
So then I tried DROP TABLE [Otis].[AnalyzerGroups]; and got
Msg 3701, Level 11, State 5, Line 1
Cannot drop the table 'Otis.AnalyzerGroups', because it does not exist or you do not have permission.
I tried making a new test table and the same thing. The first time I run the create statement command successfully completes, but then I can't select / insert / drop from the table, and I cannot see it in the Object explorer either.
I assume this must be some permissions issue but I don't know what property is keeping me from viewing these tables - its not like I'm putting security on these tables, and I can see every other table in our database. Any thoughts?
You put it most likely in the wrong database. Try this.
sp_MSforeachdb 'SELECT "?" AS DB, * FROM [?].sys.tables WHERE name like
''%AnalyzerGroups%'''
There was a trigger in the SQL Server database that fired any time a new table was created under any schema, and would then transfer it to the dbo schema. So my tables did exist, but they were under the schema I was expecting because of this trigger. Why does this trigger exist? Got me. But it's in production and has been for over a decade so there's some reason/it's definitely not changing. Thanks for the help though everyone.

Sql Server Msg 2110

I can't figure out how to solve the following error:
Msg 2110, Level 15, State 1, Procedure store, Line 113
Cannot alter trigger 'store_10' on 'Users' because this trigger does not belong to this object. Specify the correct trigger name or the correct target object name.
The above Trigger was created using the following syntax (and no error msg was generated):
Alter trigger store_10 ON Users FOR UPDATE
You can run this query to see what triggers you have assigned to what tables in the database:
SELECT
T.name AS [Trigger Name]
,O.name AS [Table Name]
FROM sys.[triggers] T
INNER JOIN sys.[Objects] O
ON O.[object_id] = T.[parent_id]
;
That might give you some indication of where things are going haywire.
Just make sure you're running the query in a new query window opened on the same database where the problem is occurring.
Once you have that information, you should be able to figure out what the issue is.
First Edit:
Can you try running this query to get the trigger definition and post the result as an edit to your question, please?
EXECUTE sys.sp_helptext 'store_10';

MSSQL - Invalid object name when attempting an update

I have a table in SQL that I can query easily when running SELECT * FROM Scheme.Table1
There are no Intellisense errors and I can see the table in the list of tables under the database
If I attempt to run an UPDATE against the table, I get the error
Msg 208 Invalid object name 'Table1'
Updates against other tabes within the same scheme all work fine
What could be causing this error? Is the wording misleading and it is really something else?
EDIT: update statement is...
UPDATE SCHEMA.TABLE1 SET SCH1 = 'DB', SCH2 = '1' WHERE MEMBERNO = 123999
All fields are correct and exist on the table
Thanks to the comments, it was a trigger on the table that was referencing itself without the SCHEMA (I was logged in using Windows Authentication)

Where to find object in SQL Server and determine if it's a view or table?

I am having a problem that I think is easy to resolve but cant put my finger on it.
I did not create this database or jobs so troubleshooting my way through it.
I have a SQL Server job that is failing, it has multiple steps.
One of the steps is
select * into [Pastel_OrderStock] from [Pastel_SOProducts]
This fails with error:
Error converting data type varchar to float.
Now if I try and go:
select * from [Pastel_SOProducts]
it gives same error.
My issue is that I can't see a table or view Pastel_SOProducts in any of my database tables or views but it obviously exists given the error.
How can I find out where this is and more importantly view the table structure or view syntax?
Thanks in advance
It will be in sys.objects. The type and type_desc will show what object type is.
Things to check:
Check your permission. Your DB administrator could have restricted your account to certain tables.
Check the table's owner is not dbo.
As mentioned in another answer you want to pull the 'type_desc' from the sys.objects table:
select name, type, type_desc from sys.objects where name = 'Pastel_SOProducts'

`Invalid object name` unless I specify database name in SQL Server 2008 queries

Up until today I've been able to run queries without using the [databaseName].[dbo].[fieldName] syntax. And all of a sudden, if I use select * from myTable I get an error for an invalid object. I can't possibly think of something that happened between shutting down my PC yesterday and today. Anyone know anything about this?
Msg 208, Level, 16, State 1 Line 1
Invalid object name 'mytable'
It's only been since today that I have to include the database name in the query. There are no other connections open and no other users of this instance of SQL Server.
I think you mean a query of the form select [fieldName] from [databaseName].[dbo].[mytable]
Here are some possible things to look out for:
Make sure that you are in the correct database context / catalogue (i.e. use [databasename], or select the correct database from the Available Databases drop down in SSMS)
Ensure that if you have a case sensitive collation on your database that the object names in your query match the exact case.
Check that the default schema for your user hasn't changed on this database. Although the default schema is usually [dbo], it can be changed.
Edit : More ideas:
Do SELECT DB_NAME() to see what the current database name is.
Check to see if someone has dropped the table or view entirely, e.g. from the target database, run:
Select * from sysobjects where name = 'myobject'
OR
Select * from sys.tables where name = 'mytable'
OR
Select * from INFORMATION_SCHEMA.TABLES

Resources