Getting 1064 mysql error in this code....
CREATE TABLE User(
user_id int(10),
first_name varchar2(30) NOT NULL,
last_name varchar2(30) NOT NULL,
user_name varchar2(20),
email_id varchar2(50),
password varchar2(20) NOT NULL,
contact_no varchar2(15),
highest_degree varchar2(30) NOT NULL,
photo longblob,
STATE varchar2(25),
score int NOT NULL,
institute_name varchar2(50),
PRIMARY KEY(user_id),
UNIQUE (user_name),
UNIQUE(email_id)) ENGINE=InnoDB;
Can't figure out how to eliminate it.. Can anyone please help?
No varchar2 in mysql use varchar
This works
create table User(
user_id int(10),
first_name varchar(30) NOT NULL,
last_name varchar(30) NOT NULL,
user_name varchar(20),
email_id varchar(50),
password varchar(20) NOT NULL,
contact_no varchar(15),
highest_degree varchar(30) NOT NULL,
photo longblob,
state varchar(25),
score int NOT NULL,
institute_name varchar(50),
PRIMARY KEY(user_id),
UNIQUE (user_name),
UNIQUE(email_id)
) ENGINE=InnoDB;
Related
CREATE TABLE `chuchutvlogin`. (
`id` INT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(20) NOT NULL ,
`gender` CHAR(1) NOT NULL ,
`email` VARCHAR(50) NOT NULL ,
`password` VARCHAR(20) NOT NULL ,
`number` BIGINT(10) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
what's issue?
i was creating a login databse and error #1064 came syntax error in localhost phpmyadmnin
Fix syntax error in your query, remove dot char after table name:
CREATE TABLE chuchutvlogin (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(20) NOT NULL,
gender CHAR(1) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(20) NOT NULL,
number BIGINT(10) NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB;
dbfiddle
I have three tables. employee, salary and bill.
==================================
employee
create table employee
(
E_ID int(10) UNSIGNED not null primary key,
E_Name varchar(20) not null,
E_Address varchar(20) not null,
E_Phone varchar(20) not null,
E_HireDate DATETIME not null,
E_Mail varchar(20) not null,
E_Post varchar(20) not null,
E_Dept varchar(20) not null
);
==================================
salary
create table salary
(
s_id int(10) UNSIGNED not null AUTO_INCREMENT primary key,
E_ID int(10) UNSIGNED not null,
S_Amount varchar(20) not null,
S_Date DATETIME,
Total_s varchar(20) not null,
foreign key (E_ID) references employee(E_ID)
);
They are working fine. I can insert values in these tables and join them with this query-
SELECT employee.E_ID as E_ID
, employee.E_Name as E_Name
, salary.S_Amount as S_Amount
, salary.S_Date as S_Date
from employee
INNER
JOIN salary
ON employee.E_ID = salary.E_ID
But then I have another table bill.
==================================
bill
create table bill
(
B_ID int(10) UNSIGNED not null AUTO_INCREMENT primary key,
E_ID int(10) UNSIGNED not null,
Electric varchar(20) not null,
Water varchar(20) not null,
Gas varchar(20) not null,
B_Others varchar(20) not null,
B_Date DATETIME,
Total_B varchar(20) not null,
foreign key (E_ID) references employee(E_ID)
);
I am trying to insert values with this procedure
$eb= $_POST['Electric'];
$wb= $_POST['Water'];
$gb= $_POST['Gas'];
$b_others= $_POST['B_Others'];
$Total_B= "$eb"+"$wb"+"$gb"+"$b_others";
date_default_timezone_set("Asia/Dhaka");
$raw=date('Y-m-d H:i:s');
$date= date("Y-m-d H:i:s", strtotime($raw));
INSERT INTO bill (Electric, Water, Gas, B_Others, B_Date, Total_B) VALUES ('$eb','$wb','$gb', '$b_others', '$date', '$Total_B');
I want to join this "bill" table with "salary" table too. But after adding foreign key E_ID in this table i can't insert any value in the "bill" table. I know i have some problem with the foreign key data type and null function. can anyone please help me to fix it.
I am trying to run this query in my database:
CREATE TABLE users(
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR NOT NULL,
userpass VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
email VARCHAR NOT NULL,
address VARCHAR NOT NULL,
phone BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(user_id)
)
MySQL returns this error:
#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 'NOT NULL,
userpass VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
' at line 3
I cant figure out what is wrong with the code...
You need to specify size for VARCHAR columns:
CREATE TABLE users( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(100) NOT NULL,
userpass VARCHAR(100) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
address VARCHAR(100) NOT NULL,
phone BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(user_id) );
SqlFiddleDemo
Storing phone number as BIGINT is not best idea. Consider normal string instead.
I am creating three tables and when trying to tie the primary and foreign keys I am receiving the error message "Key column 'username' doesn't exist in table".
Could someone take a look at my code and tell me what I am doing wrong? I have tried dropping the database and revamped the tables a few times but I am still getting the same message. Here is my code, thank you in advance for any help!
create database testproject
use testproject
create table caller_info
(
caller_id int(11) unsigned auto_increment primary key not null,
first_name varchar(35) not null,
Last_name varchar(35) not null,
phone_number int(25) not null
);
create table caller_call_record
(
call_record_id int(11),
Call_Description varchar(50),
franchise_id int(10) not null,
email varchar(40) not null,
username varchar(25) primary key not null
);
create table caller_escalation
(
call_escalation_id int(11) unsigned auto_increment not null,
Second_Level varchar(5) not null,
caller_id int(11) not null,
PRIMARY KEY(call_escalation_id),
FOREIGN KEY(caller_id)
REFERENCES caller_info(caller_id),
FOREIGN KEY(username) REFERENCES caller_call_record(username)
);
As pointed out, your table caller_escalation needs a column called username in order to create the foreign key.
It sounds like once you've added that, you're now getting a Cannot add foreign key constraint error from MySQL. The first thing that comes to mind with this kind of error is that you're using the wrong engine for your tables. You are most likely using MyISAM which does not support foreign key references - in order to use these, you will need to change the engine on all of your tables to InnoDB.
try this:
create table caller_call_record
(
call_record_id int(11),
Call_Description varchar(50),
franchise_id int(10) not null,
email varchar(40) not null,
username varchar(25) not null,
PRIMARY KEY (username)
);
create table caller_escalation
(
call_escalation_id int(11) unsigned auto_increment not null,
Second_Level varchar(5) not null,
caller_id int(11) not null,
username varchar(25) not null,
PRIMARY KEY(call_escalation_id,username),
FOREIGN KEY(caller_id)
REFERENCES caller_info(caller_id),
FOREIGN KEY(username) REFERENCES caller_call_record
);
The table caller_escalation also needs a column username, which is not there
create table caller_escalation
(
call_escalation_id int(11) unsigned auto_increment not null,
Second_Level varchar(5) not null,
caller_id int(11) unsigned not null, ;; <--- added unsigned type here
PRIMARY KEY(call_escalation_id),
username varchar(25) not null, ;; <--- added field here
FOREIGN KEY(caller_id)
REFERENCES caller_info(caller_id),
FOREIGN KEY (username) REFERENCES caller_call_record (username)
);
Also ensure the column data types are the same in both tables. You have "caller_id int(11) unsigned" in caller_info and "caller_id int(11)" in caller_escalation. I added the unsigned specifier above to make it work.
My server is on hostgator running on a linux centOS.
I'm simply trying to create a table within my database and I figured out how to get the table to get created. Although when I add the AUTO_INCREMENT setting the code doesn't execute and the table isn't created.
Why would this be and how can I correct it?
Here is my code:
$members2_table = "CREATE TABLE ninja08_codin.members2(
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(40),
last_name VARCHAR(40) NOT NULL,
email VARCHAR(64) NOT NULL,
date_joined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cred VARCHAR(10) NOT NULL)";
To use AUTO_INCREMENT you may have to assign the column as a primary key:
$members2_table = "CREATE TABLE ninja08_codin.members2(
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(40),
last_name VARCHAR(40) NOT NULL,
email VARCHAR(64) NOT NULL,
date_joined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cred VARCHAR(10) NOT NULL,
PRIMARY KEY (id))";
Your query will give error
there can be only one auto column and it must be defines as a key, so add primary key to id field
$members2_table = "CREATE TABLE ninja08_codin.members2(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(40),
last_name VARCHAR(40) NOT NULL,
email VARCHAR(64) NOT NULL,
date_joined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cred VARCHAR(10) NOT NULL)";