sql server - An expression of non-boolean type specified in a context where a condition is expected, near 'dbo' - sql

i'm getting the above error when i try and run any alter table type script, even an add column script returns this error eg:
alter table up_retail add StockGroupID int null
running the above will return the above error, i have tried restarting sql, restore ansi settings etc, does anyone have any advice on what might be causing this?
UPDATE:
when i try and drop constraints as per
ALTER TABLE [dbo].[ZSeeAlso] DROP CONSTRAINT [FK_ZSeeAlso_Performers]
i get this:
Incorrect syntax near 'dbo'.
again, any ideas what would cause this?
** UPDATE 2 **
for everyone checking this is the only thing in my query window, here is my ssms:

Your query is okey , try to Use YourDB that contains the table up_retail Not Master like this :
Use YourDB
Alter Table up_retail Add StockGroupID int null
Go

after trying everything i can think and that, that was suggested in here, i basically ended up re-installing sql and that seems to have fixed. it looks like the syntax engine or sql itself became corrupt for some reason
thanks all for the suggestions

Related

SQL Server : drop schema with special characters

I've got an old schema that needs to be removed. Problem is it's got the special character \ in the name (believe me I'm no fan of special characters in schema names). I have tried commands like the following
DROP SCHEMA databasename."COMPANY\user1"
where COMPANY\user1 is the name of the schema.
However, I end up getting errors like the following
SQL Error: Incorrect syntax near '.'.`
I've dropped all of the tables inside of the schema, so I don't think there should be any objects remaining. I had success dropping tables with the following command
DROP TABLE databasename."COMPANY\user1".persontable;
Any idea why my attempt to drop the schema is failing? I'm sure it's something obvious I'm missing in the syntax.
Have you tried using square braces?
drop schema databasename.[COMPANY\user1]
Actually, this doesn't work, because drop schema doesn't accept the database (as sort of implied by the syntax in the documentation). Just go into the database and do:
drop schema [COMPANY\user1]
This works for me with names that have unusual characters.

Add Column to Table

I looked around for an answer to this. How to add a column using SQL in an Oracle Database.
I keep finding the same answer, but my Oracle SQL Developer tool keeps telling me that the syntax is wrong even though I write it exactly as they do.
What am I missing exactly? (Before you ask, yes I do use ALTER TABLE before this)
The syntax is supposed to be:
ADD Column_Name constraint Data_Type;
Issue is, I have no constraints for this column so I've seen examples not use it. I tried that as well and I get the same error. The value can be null and have no constraints, yet I am not allowed to do this:
ADD SERIES_YEAR NUMBER(2,10);
Any suggestions? It's probably something incredibly simple.
EDIT: Here is the error it gives me:
You are missing parentheses. Try the following:
ALTER TABLE
Foo
ADD
(
SERIES_YEAR NUMBER(2,10) NOT NULL,
);
You have to write the data type before the constraint, not the opposite, like:
ADD
(
column1_name column1_datatype column1_constraint,
column2_name column2_datatype column2_constraint
);

Can an ALTER TABLE accept query results in Access 2010

I am getting a syntax error on the below code trying to execute an ALTER TABLE query in Access 2010. The ulimate goal was to execute this from a VB.net app. Both queries work indepently within Access.
ALTER TABLE [Test_table] DROP CONSTRAINT (SELECT [MSysRelationships].[szRelationship]FROM [MSysRelationships] WHERE MSysRelationships.[szObject]='Test_table');
I guess the issue is whether or not the ALTER statement can accept query results as the input?
I'm quite sure that Access SQL does not support the syntax you tried to use. You'll probably have to run the SELECT query first, pull the constraint names into a recordset (or similar), then loop through the rows and issue the ALTER TABLE statements one by one.

Lost trigger in SQL Server

I have lost a trigger. I know it is active, since when I try to change a field, it restores its value back, and from the SQL Server Management Studio I can see that when I execute the query, an extra one is executing (the trigger one).
I tried SELECT * FROM sys.triggers WHERE 1 = 1 but it does not return anything. Also, I know the name of the trigger, but when I try to ALTERit returns an error saying that
the name of the object 'myTrigger' is not valid.
And if I try to DROP TRIGGER myTrigger ON DATABASE
Trigger 'myTrigger' can not be removed because it does not exists, or the user has not enough priviledges.
Ok, as Lieven said, I was not querying the right database... This is odd, since the query had the DB defined on it
ALTER TRIGGER myTrigger
ON [DB].[dbo].[table]
But the upper select of the SQL Server Management Studio was pointing to other DB...
Edit:
I have been investigating a little bit (trying to clean my image), and I found a weird behaviour on SQL Server Management Studio.
If you execute a query like:
UPDATE [DB].[dbo].[table] SET column = 'value' WHERE column2 = 'foo'
It executes the query in the right DB. No matter what DB is pointed by the upper select.
But, if you try to do the same, with a trigger, you must have the upper select pointing the right DB, or you will face the same problems I had.
I had a subtle error kind of like yours; I did something like this:
CREATE TRIGGER [TrigCustomerInsertDelete]
ON [mobile].[Customers]
AFTER INSERT, DELETE
AS
select 'I' [ACTION],* from inserted
select 'D' [ACTION],* from deleted
GO
and then later tried to update it with:
ALTER TRIGGER [TrigCustomerInsertDelete]
and got this error: Invalid object name
The problem was that I did not specify the schema on the trigger (thinking it would just be dbo), but the table does have a schema. So, I figured out the error after including the schema on the trigger.
CREATE TRIGGER [DBO].[TrigCustomerInsertDelete]
This gave me the following error: Cannot create trigger 'DBO.TrigCustomerInsertDelete' because its schema is different from the schema of the target table or view.
I know this is an old post, but hopefully it will help someone else.

Force DATABASE ALTER ignoring errors

As the name says, force the alter database to alter its collation ignoring the error message that I get from functions or calculated columns that compare data.
Is there a way to do so?
Like IGNORE_ERRORS or something like that?
Thanks a lot!
No, because your data and database will be broken if you could ignore errors. Which is bad thing.
See this recent question about changing collation for inspiration, hopefully
Maybe you can use transactions.
begin transaction;
alter table ...
... repair calculated colums ...
commit;
Normally it should not be possible that you can make changes to your database which leave it in an inconsistent state. See ACID