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
Related
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?
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
my new created table appears in master(in system databases) instead of my created database in sql server.
here's my code:
create table patients(
id int not null ,
fname char(20) not null,
lname char(20) not null,
disease char(30),
primary key(id)
);enter image description here
Because you forget to begin with the
USE MyDatabase
Statement, that wil executes your DDL queries into the right db.
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?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have column named HireDate in table named employeeInfo. I simply need to check whenever the value or Date in the HireDate column gets updated using simple SQL script.
I am unable to write a simple script by which I can check it.
You need to put trigger on the table. And if you want to execute your script when HireDate changed you can use "IF UPDATE(HireDate)". Check the following sample :
CREATE TRIGGER dbo.TR_employeeInfo_CheckHireDate
ON dbo.employeeInfo
AFTER UPDATE--,INSERT
AS BEGIN
SET NOCOUNT ON;
IF UPDATE (HireDate)
BEGIN
--put your Update,Delete or Insert statments here
END
END
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
In my database I have one table which when there is a record inserted into it a trigger will use information from the data inserted, run a select statement on the rest of the database, and insert the result into another database on the same server.
Ive never written a trigger before and Im not entirely sure that the examples out there help a lot.
Thanks in advance
its always good to start learning ...here is some sample code and some links to start ..
create trigger <<give your triggername>>
on
<<give your tablename>>
after insert
as
begin
select * from inserted--gives me data inserted
--run on rest of database--your logic goes here
select * from inserted i
join
some table tbl
on
tbl.id=i.id
insert into anotherdatabase.dbo.anotherdatabasetable
select * from inserted
end
Also please be aware that ,if the above trigger fails due to some reason ,your insert also will be rolled back..
some good links:
http://www.sqlteam.com/article/an-introduction-to-triggers-part-i
Insert Update trigger how to determine if insert or update
sql server trigger