cannot decipher SQL error when creating trigger - mysql

This is for a trigger I'm creating that responds to inserts on the table groceries
CREATE TABLE grocery_changes (
ID INT NOT NULL AUTO_INCREMENT,
changed_table VARCHAR(255),
date_time DATETIME,
operation CHAR(10) NOT NULL,
PRIMARY KEY(ID)
);
CREATE TRIGGER trg_grocery_audit AFTER INSERT ON groceries
for each ROW BEGIN
INSERT INTO grocery_changes (modified_table, action_date_time, operation) VALUES ('groceries', NOW(), 'INS');
I keep getting this error But I cant figure it out and could really appreciate a second pair of eyes at this point. Thank you
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

Related

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

I am trying to execute a PL/SQL statement in MySQL. but, when I try to create a table it shows a syntax error. I get the following error
CREATE TABLE supplier(supid NUMBER(5) PRIMARY KEY, suppname VARCHAR2(15));
ERROR 1064 (42000): 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 'NUMBER(5) PRIMARY KEY, suppname VARCHAR2(15))' at line 1
full code is as follows:
DROP TABLE supplier;
DROP SEQUENCE practical2_sequence;
*/
CREATE TABLE supplier(supid NUMBER(5) PRIMARY KEY, suppname VARCHAR2(15));
CREATE SEQUENCE practical2_sequence START WITH 1 MAXVALUE 100;
BEGIN
LOOP
INSERT INTO supplier VALUES(practical2_sequence.NEXTVAL, 1);
EXIT WHEN practical2_sequence.CURRVAL >= 100;
END LOOP;
END;
/
SELECT * FROM supplier;
Help me, as I am not that experienced in MySQL.
You seem to be trying to use Oracle syntax with MySQL.
MySQL doesn't have sequences, it uses the AUTO_INCREMENT attribute of the column. When inserting, either assign NULL to the column or leave it out of the column list, and it will get the next value in the sequence.
MySQL doesn't have the NUMBER datatype, it uses INT. It doesn't have VARCHAR2, just VARCHAR.
DECLARE counter INT DEFAULT 0;
DROP TABLE IF EXISTS supplier;
CREATE TABLE supplier(
supid INT(5) PRIMARY KEY AUTO_INCREMENT,
suppname VARCHAR(15)
);
WHILE counter < 100 DO
INSERT INTO supplier (suppname) VALUES('1');
END WHILE;
Note that variable declarations and WHILE loops can only be used inside stored procedures, not as ordinary queries.

mysql error for a create table statement from shell client

Im trying to run the following from the mysql shell client:
MySQL localhost:33060+ ssl plaything SQL > CREATE TABLE areas (id SERIAL PRIMARY KEY, area_name VARCHAR);
and keep getting the following error:
ERROR: 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 ')' at line 1
where could I be going wrong?
solved by yoss:
try this: CREATE TABLE areas ( id int NOT NULL AUTO_INCREMENT, area_name varchar(255), PRIMARY KEY (id) );
varchar did not have number of characters specified in the original statement

MySQL error 1064 table creation

This seems a fairly trivial problem but I am having no luck in running the following query:
create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR(20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
When I run this I get the following error message:
Error Code: 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 '(20), retweet_count INT, favourite_count INT,
tweet_followers_count ' at line 3
When I hover over the error tag on line 3 it says:
Syntax error : unexpected '(' (opening parenthesis)
I'm sure this is a simple fix, any help would be great!
Turned out to be an error with mySQL Workbench
create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR (20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
Man this code is running perfectly.
go to this link and check it your self
http://rextester.com/l/mysql_online_compiler

Create MySQL Database with Xampp

I have the following query for creating a table in my database but I am getting an error:
CREATE TABLE student (
accountNumber INT NOT NULL PRIMARY KEY,
firstName CHAR(20),
lastName CHAR(20),
courseID VARCHAR(6),
grade DOUBLE(3)
)
The error I am getting is:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
You dont need NOT NULL if declaring a Primary Key...because that key always needs to be available

Use MySQL in command prompt, ERROR 1064 (42000) occur when creating table

I am using xampp.
After creating a database
CREATE DATABASE University + use University
I create table by typing
CREATE TABLE Student
(
SNo INT NOT NULL,
SName VARCHAR(16) NOT NULL,
SAge INT NOT NULL,
SDepartment ENUM('CS', 'EE', 'Math', 'Physics') NOT NULL,
PRIMARY KEY (SNo)
);
But a beep is resulted and
ERROR 1064 (42000): 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 'use University
CREATE TABLE Student
(
SNo INT NOT NULL,
Sname VARCHAR(16) NOT NULL,
SAg'
at line 2
is shown in command prompt. But I don't know what the syntax error is in this case.
I think the + is giving you syntax error. Try getting rid of it to separate these into two statements
CREATE DATABASE University
USE University