I' experiencing problems while trying to run a batch file within Mysql shell.
I wrote a stored procedure :
DELIMITER $$
DROP PROCEDURE IF EXISTS creaFornitori_prova$$
CREATE PROCEDURE creaFornitori_prova ()
BEGIN
create table Fornitori_prova (id_For mediumint(5) NOT NULL auto_increment,
nome_For varchar(50) NOT NULL,
ind_For varchar(50) NOT NULL,
PRIMARY KEY (id_For)
) ENGINE=InnoDB;
END$$
DELIMITER ;
I called the file : st_F.sql
Whenever I try to execute the file through the command : source st_F.sql;
I get this error:
ERROR:
Failed to open file 'st_F.sql', error: 2
I get the same error when I use \. st_Fornitori.sql;
Thanks Mauro
source DRIVE:ABSOLUTE_PATH_TO/st_F.sql;
Related
While I created loads of procs in SQL server, I want to start using MariaDB and so tried creating the simple proc below in MySQL Workbench.
I keep on getting an error stating that there is a missing SELECT on the opening '(' after the table name:
DELIMITER $$
drop procedure if exists usp_AddSentEmail$$
CREATE PROCEDURE usp_AddSentEmail (in pSender varchar(36)
,in pTo varchar(1000)
,in pSubject varchar(100)
,in pBody varchar(10000)
,in pRecordDT datetime)
BEGIN
INSERT INTO Emails('To','Subject','Body','Sender','RecordDT','Sent','SentDT')
VALUES (pTo,pSubject,pBody,pSender,pRecordDT,1,pRecordDT);
END$$
DELIMITER ;
Maybe I am trying the wrong google search but that all comes up is delimiter errors.
remove the quotes from the column names in your insert query:
INSERT INTO Emails(To,Subject,Body,Sender,RecordDT,Sent,SentDT)
VALUES (pTo,pSubject,pBody,pSender,pRecordDT,1,pRecordDT);
I'm a noob im MYSQL and I'm trying to make a trigger who will auto-fill 2 fields(customername, customersurname) in an invoice table. Can anyoane explain me please what I do wrong in that trigger? Thank you very much! :)
CREATE TABLE customer(
customerID INT(6) PRIMARY KEY AUTO_INCREMENT,
customername VARCHAR(20) NOT NULL,
customersurname VARCHAR(20) NOT NULL,
customeraddress VARCHAR(200)
);
CREATE TABLE invoice(
invoiceID INT (6) Primary KEY AUTO_INCREMENT,
customerID INT (6) REFERENCES customer(customerID),
customername VARCHAR(20) REFERENCES customer(customername),
invoicedate DATE,
orderID INT(6) REFERENCES orders(orderID),
products VARCHAR(200) REFERENCES orderlines(productname),
FOREIGN KEY(orderID) REFERENCES orders(orderID)
);
CREATE TRIGGER autofill_invoice BEFORE INSERT ON invoice FOR EACH ROW
BEGIN
IF (new.customerID = customer.customerID,
new.customersurname = customer.customersurname )
THEN
SET new.customername = customer.customername,
new.customersurname = customer.customersurname;
END IF;
END;
As mysql documentation on defining stored programs explains:
If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.
To redefine the mysql delimiter, use the delimiter command. The
following example shows how to do this for the dorepeat() procedure
just shown. The delimiter is changed to // to enable the entire
definition to be passed to the server as a single statement, and then
restored to ; before invoking the procedure. This enables the ;
delimiter used in the procedure body to be passed through to the
server rather than being interpreted by mysql itself.
So, use the delimiter command when you define the stored procedure:
DELIMITER //
CREATE TRIGGER autofill_invoice BEFORE INSERT ON invoice FOR EACH ROW
BEGIN
IF (new.customerID = customer.customerID,
new.customersurname = customer.customersurname )
THEN
SET new.customername = customer.customername,
new.customersurname = customer.customersurname;
END IF;
END//
DELIMITER ;
Next time pls provide exact error description in your question!
I have the following procedure that when I manually import this is breaking for some unknown reason.
CREATE PROCEDURE `register_house`(
IN UID CHAR(17),
IN new_username VARCHAR(16),
IN new_signature CHAR(64),
IN email VARCHAR(128),
IN postcode VARCHAR(16),
IN customer_name VARCHAR(45),
IN phone_number VARCHAR(16)
)
BEGIN
UPDATE bb.checkin SET username = new_username, signature = new_signature WHERE _site = UID;
END
I'm getting the following error in Mysql Workbench -
Error Code: 1064. 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 11
Can someone suggest what the problem is?
UPDATE
As suggested i've amended to include the DELIMITER and now get the following error:
Error Code: 1728. Cannot load from mysql.proc. The table is probably corrupted
The tables all appear to look correct is the way to 'de-corrupt' them if they have corrupted somehow?
Based on https://stackoverflow.com/a/639356/2381157, try this
delimiter //
CREATE PROCEDURE `register_house2`(
IN UID CHAR(17),
IN new_username VARCHAR(16),
IN new_signature CHAR(64),
IN email VARCHAR(128),
IN postcode VARCHAR(16),
IN customer_name VARCHAR(45),
IN phone_number VARCHAR(16)
)
BEGIN
UPDATE bb.checkin SET username = new_username, signature = new_signature WHERE _site = UID;
END
//
delimiter ;
It worked for me in MySQL 5.5
This worked for me...
Added this to the start of the statement on line 1;
DELIMITER $$
then on the ver
END $$
Then finally to fix the 'corrupted' message I simply ran the following file:
C:\xampp\mysql\bin\mysql_upgrade.exe
I'm using MySQL ,
and trying to create stored procedure
that get CSV file (with 2 columns - ID & Name)
,delete table person_table and
create it with the CSV content.
This is the code:
DELIMITER $$
drop procedure if exists load_persons$$
CREATE PROCEDURE load_persons(in file_name varchar(300))
BEGIN
drop table if exists person_table;
CREATE TABLE `person_table` (
`ID` varchar(30) NOT NULL,
`Name` varchar(150) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOAD DATA LOCAL INFILE file_name INTO TABLE person_table;
END$$
DELIMITER ;
unfortunately I get an error : 'LOAD DATA is not allowed in stored procedures'
what can I do ?
Thank you!!
You can call to load command after stored procedure:
CALL load_persons(...);
-- and then
LOAD DATA LOCAL INFILE your_file_name INTO TABLE person_table;
I'm trying to create a table inside a mysql stored procedure, but whenever I execute this procedure, I do not see the resulting table in my database. Can anyone tell me what's going on? The create table query works whenever I enter it in the cmd outside of a stored procedure.
delimiter //
drop procedure if exists gm //
create procedure gm()
begin
create table errorMessages (
error_id int not null auto_increment,
message varchar(200) not null default '',
primary key(error_id)
);
end //
delimiter ;
Are you executing the stored procedure or just creating it?
Try
call gm();
It gives any error?