TripleNad
TripleNad

Reputation: 37

Using DECLARE to create variable in MySQL

I will admit, I am a T-SQL guy, not a MySQL guy, but I don't quite understand why I am getting this error message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @UpdatedID VARCHAR(5)' at line 1 

Here is my query:

DECLARE @UpdatedID VARCHAR(5);

SET @UpdatedID = 63;

CREATE TABLE tmp_markers (SELECT * FROM tmp_markers2);

UPDATE tmp_markers
SET Id = Id+1
WHERE Id >= @UpdatedID;

UPDATE tmp_markers
SET Id = @UpdatedID
WHERE Id = MAX(Id);

DELETE from tmp_markers2;

INSERT INTO tmp_markers2
(SELECT * FROM tmp_markers ORDER BY id);

DROP TABLE tmp_markers

Upvotes: 2

Views: 66

Answers (1)

Oli
Oli

Reputation: 919

Declaring a variable in MySQL is done with what you have done with:

SET @UpdatedID = 63;

The DECLARE statement is for use within stored procedures. See this.

Upvotes: 2

Related Questions