Sql Server Msg 2110 - sql-server

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';

Related

Creating SQL Server trigger to debug database issue

I have a database where one of the columns in one table keeps going blank. There's nothing in our software that can clear that column, so we are quite perplexed how it keeps happening.
Any suggestions on how I can figure this out? I'm thinking of creating a trigger that runs every time this table gets updated, and ideally when that field becomes empty.
But what kind of info can I actually track that will help me figure this out? Can I store the SQL statement that gets run when that update occurs? Can I store the Windows process that is connected to the database?
Any other suggestions? Thanks
You could also throw an error from trigger and have your client fail. If your client code is written to handle errors and log them, you can find out what causes the issue that way.
One thing you can try is using a trigger and testing for the specific column being updated with if update(column).
You can then capture some diagnositc data such as the following into a logging table:
select ##Spid, r.plan_handle, p.program_name, p.loginame, b.event_info
from sys.dm_exec_requests r
join sys.sysprocesses p on p.spid=r.session_id
cross apply sys.dm_exec_input_buffer(r.session_id, r.request_id)b
where session_id=##Spid
Something like this may work, if you create the correct set of columns in some kind of logging table:
IF EXISTS (SELECT 1 FROM inserted WHERE LEN(ProblemColumn) = 0)
BEGIN
INSERT INTO dbo.SomeLoggingTable(cols)
SELECT getdate(), i.key, buf.*
FROM inserted AS i
CROSS APPLY sys.dm_exec_input_buffer(##SPID, NULL)
WHERE LEN(ProblemColumn) = 0;
END

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.

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)

Table hiding in SQL Server database?

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

`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