I am trying to change the name of the column c to novaC with php and mysql. Everywhere I look seems to give the same solution but it doesn't seem to work:
if(isset($_GET["rename"])){
mysql_query("ALTER TABLE myTable
RENAME COLUMN c to novaC");
}
If I type: ALTER TABLE aaa RENAME COLUMN c to novaC directly in MySql it gives:
#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 'COLUMN c to novaC' at line 2
alter table tablename change oldColumn newColumn varchar(10) ;
Reference : Alter Table - MySQL Command
if(isset($_GET["rename"])){
mysql_query("ALTER TABLE myTable CHANGE c novaC varchar(9999)");
}
The MySQL documentation
Related
I have query
INSERT INTO subscriptions ( client_id, name, group_id, type )
SELECT clients.id, 'Индивидуал', 0, 1 FROM clients WHERE clients.individual=1;
ALTER TABLE clients DROP COLUMN clients.individual;
ALTER TABLE finance_operations ADD COLUMN sub_id INT NOT NULL DEFAULT 0;
which works fine in Mysql Workbench.
But if I use it in codeIgniter code:
$this->db->simple_query($query);
I get 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 'ALTER TABLE clients DROP COLUMN clients.individual; ALTER TABLE'
at line 4
PDO can not run more than one question one time;
This code is right:
$array = [ "query1", "query2", "query3" ];
foreach($array as $query)
$this->db->simple_query($query);
I am having problem in increment and decresing a column in value please help me...
Error at,
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
UPDATE stock SET stock=stock+$quantity WHERE ID=1;
UPDATE stock SET stock=stock-$quantity WHERE ID=1;
try static first
UPDATE `stock` SET `stock`=`stock` + 200 where `ID` = 1
try this one is work for me.
UPDATE `stock` SET `stock`=`stock`+$quantity where ID=1
also check you table field Type, incremental operator work in Integer or float type field only, in text or Varchar it will not work
I would like to show total purchase followed by date from purchase table to insert into total_purchase table as in date and buy as well as view
my purchase table structure as below:
id|companyName |purchase|date
1|housedotcom |1300 |2016-1-1
2|homedotcom |1234 |2016-1-1
3|gardendotco |1000 |2016-1-2
4|landotcom |999 |2016-1-2
5|garagedotcom|5400 |2016-1-2
6|homedotcom |2600 |2016-1-2
7|housedotcom |1900 |2016-1-2
my total_purchase table as below
id|date |buy
1|2016-1-1|2534
2|2016-2-2|20890
I tried this into sql
INSERT INTO 'total_purchase'(date,buy) SELECT date, sum(purchase)
*FROM 'purchase' GROUP BY date;
And it showed in mysql result as I expected but when I tried insert new data into purchase table as same companyName with different date in mysql it says duplicate as well as in php coding sql it did not worked and showed this error
Error Processing RequestSQLSTATE[42000]: Syntax error or access violation: 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 'FROM purchaseGROUP BY date'
Any suggestions? Thanks in advance.
remove * from your query to be:
INSERT INTO total_purchase (date,buy) SELECT date, sum(purchase)
FROM purchase GROUP BY date;
For inserting value should be entered by just column by column.In Select you use * that return row more than one remove '*'
INSERT INTO 'total_purchase'(date,buy) SELECT date, sum(purchase)
FROM 'purchase' GROUP BY date;
I want to insert and update a table using one mysql query my table structure is:
student_id ,class_no, section, started_on ,ended_on
I want to update class_no and insert a new records. For that I am using this query:
INSERT INTO student_classes (student_id,class_no,section,started_on,ended_on)
VALUES (835,5,0,2013-04-09,null)
ON DUPLICATE KEY UPDATE class_no = class_no+1
but this query is only insert a new row,not updated column if I use where clause after DUPLICATE KEY UPDATE class_no = class_no+1 its give error message.
Message is:
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 'where started_on=2013-04-09'
This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 4 years ago.
i try to update simple data to table name "order" but i still get error.
i try to many version query but still same ;
first try :
$result = mysql_query("UPDATE order SET order_status_id=200 WHERE order_id=75") or die(mysql_error());
second try :
$result = mysql_query("UPDATE order SET order_status_id='200' WHERE order_id='75'") or die(mysql_error());
error ;
first try :
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 'order SET order_id=200 WHERE order_id=75' at line 1
second try :
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 'order SET order_status_id='200' WHERE order_id='75'' at line 1
Table structure
order_id int(11)
order_status_id int(11)
i try to update others table just to make sure my query correct and all table can update.
*Im using Opencart and my site use https.
Thanks.
order is a reserved word in MySQL. You need to escape it with backticks:
UPDATE `order` SET order_status_id=200 WHERE order_id=75
See MySQL reserved words