Reputation: 79
I am trying to create a table in my database, accountdb
. My query to create the table is:
$query1="CREATE TABLE asset( id int(16) auto_increment primary key,TotBalance double(35),creditAmnt double(35),debitAmnt double(35))";
After that when I am executing the above query, the database is created, but there is an error in creating the table. The error is as follows:
error creating tableYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '),creditAmnt double(35),debitAmnt double(35))' at line 1
How can I fix this error?
Upvotes: 2
Views: 114
Reputation: 2800
Here is the correct query:
CREATE TABLE asset(
id int(16) auto_increment primary key NOT NULL,
TotBalance double(35,3),
creditAmnt double(35,3),
debitAmnt double(35,3)
);
When the datatype is double, float, or decimal, you need to specify the decimal places.
Correct syntax to create a double datatype column:
double(D,M);
M
is the total number of digits and D
is the number of digits following the decimal point.
See also: http://code.rohitink.com/2013/06/12/mysql-integer-float-decimal-data-types-differences/
I hope this helps you.
Upvotes: 4
Reputation: 311
CREATE TABLE assets
(
id
int(16) NOT NULL AUTO_INCREMENT,
Tot_balance
bigint(20) NOT NULL,
Credit_Amt
bigint(20) NOT NULL,
Debit_Amt
bigint(20) NOT NULL,
PRIMARY KEY (id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Upvotes: 1
Reputation: 55
CREATE TABLE IF NOT EXIST asset(
id int(16) auto_increment primary key
,TotBalance double(35)
,creditAmnt double(35)
,debitAmnt double(35)
);
Upvotes: 1