T-SQL insert into doesn't recognize a table name [closed] - sql-server

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
The following code doesn't work:
INSERT INTO [dbo].[Customers]
([CustName]
,[CustSurname]
,[City])
VALUES
("Joe", "Dassen", "London")
The table definitely exists, and column names are definitely correct.
However, all object references are red-underlined. Pointing the cursor show this: "invalid object name Customers" for the table name, and "Invalid column name CustName" for [CustName] and so on.
Running the code generates errors, but different ones:
Msg 207, Level 16, State 1, Line 19
Invalid column name 'Joe'.
Msg 207, Level 16, State 1, Line 19
Invalid column name 'Dassen'.
Msg 207, Level 16, State 1, Line 19
Invalid column name 'London'.
I use SQL Server 2017 Express edition and latest SSMS.

It should be as below: You are passing values in double quote it should be in single quote.
INSERT INTO [dbo].[Customers]
([CustName]
,[CustSurname]
,[City])
VALUES
('Joe', 'Dassen', 'London')
Somehow if you want to insert values like Jo'e then you need to pass two times single quote as '' not the double quote. So, it should be Jo''e.

Your query should be like below :
INSERT INTO [dbo].[Customers]
([CustName]
,[CustSurname]
,[City])
VALUES
('Joe', 'Dassen', 'London')
Double quotes are for identifiers but String values must be quoted with single quotes.
So instead of using double quotes, just replace them by single quotes.How do I use single quotes in SQL query?

Related

Incorrect syntax near 'RAISEERROR' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
Using the following query to change a stored procedure in SQL Server 2008 RC2:
ALTER PROCEDURE SetPackageCurrentVersion
(#PackName VARCHAR(32),
#PackVersion VARCHAR(32))
AS
BEGIN
SET NOCOUNT ON;
UPDATE Packages
SET CurrentPackageVersionId = (SELECT pv.id
FROM PackageVersions pv
JOIN Packages p ON p.Id = pv.Package_Id
WHERE p.Name = #PackName
AND pv.Name LIKE '%' + #PackVersion + '_Tag'),
UpdatedAt = CURRENT_TIMESTAMP
WHERE Name = #PackName;
IF ##ROWCOUNT < 1
RAISEERROR('No row updated for package %s', 11, 1, #PackName)
ELSE IF ##ROWCOUNT > 1
RAISEERROR('More than one row updated for package %s', 11, 1, #PackName)
END;
However, I get the following unhelpful error:
SQL Error [102] [S0001]: Incorrect syntax near 'RAISEERROR'.
Incorrect syntax near 'RAISEERROR'.
I tried changing the RAISEERROR to a THROW but then realized that this was only added to SQL Server 2012. Similarly I tried adding and removing semicolons (I'm never quite sure about when to use them or not in SQL) but to no avail.
What's wrong with my query?

Incorrect syntax of sp_rename [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to rename team view to myteam.
create view team as (select * from employees);
I'm writing the sp_rename command but it, showing error.
sp_rename team myteam;
[12:31:15 pm] Started executing query at Line 685
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'myteam'.
Total execution time: 00:00:00.012
sp_rename syntax:
sp_rename old_name, new_name;
There is a , between old_name and new_name.
Syntax:
sp_rename 'old_table_object', 'new_table_object'
The result outputs of this procedure might be 0 or non-zero values. 0 value indicates that the procedure execution successfully completed and non-zero values indicate failure.
How to rename tables in SQL Server with the sp_rename command

SSMS Showing diff error message in 2008 and 2014 on Violation of UNIQUE KEY constraint [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
While inserting a record to my table table1 in SQL Server 2008 instance, I'm getting the following error
Msg 2627, Level 14, State 1, Line 1
Violation of UNIQUE KEY constraint 'IX_table1'. Cannot insert duplicate key in object 'dbo.table1'.
But while executing the same query in SQL Server 2014 (copy of the above database), I am getting some difference in the error messsage
Msg 2627, Level 14, State 1, Line 2
Violation of UNIQUE KEY constraint 'IX_table1'. Cannot insert duplicate key in object 'dbo.table1'.
The duplicate key value is (xxx, ).
In 2014 the error message specifies the duplicated value in the message (The duplicate key value is xxx), but in 2008 it does not.
Why this? Is this a new feature on 2014? or there is any settings to change/format the error messages?
There was a big demand from users that when the PK violation occurs, to display the value that crated the conflict. When the violation occurs in a simple INSERT statement that inserts one row then is a no brainer, the violation occurred due to the value being inserted. But INSERT can insert also a set, eg. INSERT INTO ... SELECT ... FROM... and then is much harder to figure out which row from the set caused the violation.
In SQL Server 2014 there was an improvement to capture the duplicate key that caused the violation and display it in the error message.

SQL Server : Adding Column Error [duplicate]

This question already has answers here:
SQL Query to add a new column after an existing column in SQL Server 2005
(7 answers)
Closed 7 years ago.
I am still finding my feet in SQL Server, and I am trying to do a simple column addition and it is throwing an error. I am trying to add the KinAdr3 column after the KinAdr2 column but it is throwing the following error
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'AFTER'.
Below is the SQL statement I am trying to execute
ALTER TABLE TBL_MEDICAL_Patient
ADD KinAdr3 nVARCHAR(50)
AFTER KinAdr2
Thanks in advance
The reason is simple as the above syntax is valid in MySQL but is not valid in SQL Server. In SQL Server following syntax is valid:
ALTER TABLE tablename ADD columnname INT
However, a user wanted to add the column between two of the columns. SQL Server is relational engine. The order of the column should not matter in any of the T-SQL operations. It does not matter in most of the cases (except when the table is extra large, and it has many NULL columns it impacts the size of the table). In reality whenever user wants to add a column to the table, he/she should just the column and later retrieve the column in a specific order in the table using column names.
It is always a good idea to specify the name of the column in the T-SQL query (using * is indeed a bad idea but that is out of scope of this blog post).
For more details please see the SQL SERVER – How to Add Column at Specific Location in Table

SQL Server 2005 Alter table column not being recognized

This is on a replicated table in SQL Server 2005
I used the following command:
ALter table dbo.apds alter column docket nvarchar(12) null
and it executed with no errors, everything looks clean.
Column spec shows it now has 12 (was previously set to 6) on both tables, publisher
and subscriber.
But when I try to put more than 6 characters in that column, I get the error:
Msg 8152 lefel 16, state 13, procedure trgapdsupdate, line 5
String or binary data would be truncated.
I can still only write 6 characters of data to that column even though it shows 12 as the
column specification..
Any ideas?
Thank you in advance..
You say
I get the error: msg 8152 lefel 16, state 13, procedure trgapdsupdate,
line 5 string or binary data would be truncated. The statement has
been terminated
So what is trgapdsupdate?
From the name it looks like an update trigger on the table apds?
Does that need to be updated to deal with the new column value? For example writing to an audit table whose definition needs to be updated.

Resources