MySQL- Invalid default value for 'lasttime' - mysql

SQL sorgusu:
CREATE TABLE online(
idonline İNT( 10 ) UNSİGNED NOT NULL AUTO_INCREMENT ,
ip VARCHAR( 16 ) ,
domain VARCHAR( 100 ) ,
FKiduyeler İNT( 10 ) UNSİGNED,
lasttime TİMESTAMP DEFAULT 'CURRENT_TIMESTAMP',
PRIMARY KEY ( idonline ) ,
KEY online_index3587( ip ) ,
KEY online_index3588( domain ) ,
KEY online_index3592( FKiduyeler ) ,
KEY online_index3604( lasttime )
);
MySQL çıktısı: Belgeler
#1067 - Invalid default value for 'lasttime'
Before everthing sorry about my english; when l upload my db ,l got this proglem.Please help me.Thanks

CURRENT_TIMESTAMP instead of 'CURRENT_TIMESTAMP'
I instead of İ at multiple places.
CREATE TABLE `online`(
idonline INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
ip VARCHAR( 16 ) ,
domain VARCHAR( 100 ) ,
FKiduyeler INT( 10 ) UNSIGNED,
lasttime TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- lose the single quotes here
PRIMARY KEY ( idonline ) ,
KEY online_index3587( ip ) ,
KEY online_index3588( domain ) ,
KEY online_index3592( FKiduyeler ) ,
KEY online_index3604( lasttime )
);

Thank for helping, but when l do that I'm getting this problem:
CREATE TABLE visitor_chats ( visitor_id varchar(32) NOT NULL,
browser_id varchar(32) NOT NULL, visit_id varchar(32) NOT NULL,
chat_id int(11) unsigned NOT NULL, fullname varchar(255) NOT NULL,
email varchar(255) NOT NULL, company varchar(255) NOT NULL, status
tinyint(1) unsigned NOT NULL, typing tinyint(1) unsigned NOT NULL,
waiting tinyint(1) unsigned NOT NULL, area_code varchar(255) NOT NULL,
first_active int(10) unsigned NOT NULL, last_active int(10) unsigned
NOT NULL, qpenalty int(10) unsigned NOT NULL, request_operator
varchar(32) NOT NULL, request_group varchar(32) NOT NULL, question
varchar(255) NOT NULL, customs text NOT NULL, allocated int(11)
unsigned NOT NULL, internal_active tinyint(1) unsigned NOT NULL,
internal_closed tinyint(1) unsigned NOT NULL, internal_declined
tinyint(1) unsigned NOT NULL, external_active tinyint(1) unsigned NOT
NULL, external_close tinyint(1) unsigned NOT NULL, exit int(11) [...]
MySQL 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 'exit int(11) unsigned NOT NULL,PRIMARY KEY
(visitor_id,browser_id,visit_id,c' at line 26"

Related

MySQL error #1089 while creating database

I am creating a database it keeps on giving me error:
CREATE TABLE `pgdavplacments`.`drive` ( `drive_id` INT(5) NOT NULL AUTO_INCREMENT ,
`drive_name` VARCHAR(200) NOT NULL ,
`drive_date` DATE NOT NULL ,
`drive_time` TIME NOT NULL ,
`drive_info` VARCHAR(8000) NOT NULL ,
`eligibility1` INT(5) NOT NULL ,
`eligibility2` INT(5) NOT NULL ,
`eligibility3` INT(5) NOT NULL ,
PRIMARY KEY (`drive_id`(1000)))
ENGINE = InnoDB;
What is the problem here?
CREATE TABLE `pgdavplacments`.`drive` (
`drive_id` INT(5) NOT NULL AUTO_INCREMENT,
`drive_name` VARCHAR(200) NOT NULL,
`drive_date` DATE NOT NULL,
`drive_time` TIME NOT NULL,
`drive_info` VARCHAR(8000) NOT NULL,
`eligibility1` INT(5) NOT NULL,
`eligibility2` INT(5) NOT NULL,
`eligibility3` INT(5) NOT NULL,
PRIMARY KEY (`drive_id` )
) ENGINE=INNODB;
You can try above query.

error in SQL syntax near primary key

CREATE TABLE `bank`.`Customer_registrationTable`
( `Account_no` INT NOT NULL ,
`Name` VARCHAR(100) NOT NULL ,
`Address` INT(100) NOT NULL ,
`Account_type` VARCHAR(100) NOT NULL ,
`Gender` VARCHAR(50) NOT NULL ,
`DOB` VARCHAR(100) NOT NULL ,
`Password` VARCHAR(100) NOT NULL ,
`Date` VARCHAR(100) NOT NULL ,
`Age` INT(10) NOT NULL ,
`Previous_Balance` DOUBLE(20) NOT NULL,
PRIMARY KEY (`Account_no`(30))) ENGINE = InnoDB;
after writing this I got problem that said,
#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, PRIMARY KEY (`Account_no`(30))) WHERE ENGINE = InnoDB' at line 1
CREATE TABLE `bank`.`Customer_registrationTable`
( `Account_no` INT NOT NULL ,
`Name` VARCHAR(100) NOT NULL ,
`Address` INT(100) NOT NULL ,
`Account_type` VARCHAR(100) NOT NULL ,
`Gender` VARCHAR(50) NOT NULL ,
`DOB` VARCHAR(100) NOT NULL ,
`Password` VARCHAR(100) NOT NULL ,
`Date` VARCHAR(100) NOT NULL ,
`Age` INT(10) NOT NULL ,
`Previous_Balance` DOUBLE NOT NULL,
PRIMARY KEY (`Account_no`)) ENGINE = InnoDB;
PRIMARY KEY (Account_no) should not have (20)
Previous_Balance DOUBLE NOT NULL should not have (20), it should like DOUBLE(20, 2)
CREATE TABLE IF NOT EXISTS `customer_registrationtable` (
`Account_no` int(11) NOT NULL,
`Name` varchar(100) NOT NULL,
`Address` int(100) NOT NULL,
`Account_type` varchar(100) NOT NULL,
`Gender` varchar(50) NOT NULL,
`DOB` datetime NOT NULL,
`Password` varchar(100) NOT NULL,
`Date` datetime NOT NULL,
`Age` int(10) NOT NULL,
`Previous_Balance` double(20,2) NOT NULL,
PRIMARY KEY (`Account_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Mysql Join / Union issue

I am trying to create a report that pulls data from 2 tables: a & b. The report is grouped by a.clock. Most of the data for the report comes from a - that part is working fine. a.clock links with b.userID.
The part i am struggling with is for one of the columns the data comes from b. I need to total up the following for each a.clock grouping in the main report (this query works standalone)
SELECT (
SUM(
TIME_TO_SEC(
TIMEDIFF(
CONCAT(b.endDate, ' ', b.outTime),
CONCAT(b.startDate, ' ', b.inTime)
)
) / 3600
)
) AS 'Misc Hours' FROM b
In other words, i need to total the Misc Hours (in b) for each a.clock. I thought maybe joining the b table was necessary but that didn't seem to work. Any suggestions?
Here are the table definitions (sorry, verbose)
CREATE TABLE `a` (
`laborID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`type` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '0=sched; 1=accepted; 2=complete; 3=authorize',
`laborType` varchar(15) NOT NULL DEFAULT '0' COMMENT 'Lookup',
`hours` varchar(15) NOT NULL DEFAULT '',
`wage` varchar(15) NOT NULL DEFAULT '',
`id` int(10) unsigned NOT NULL DEFAULT '0',
`laborDate` date NOT NULL,
`ot` varchar(15) NOT NULL,
`clock` varchar(15) NOT NULL,
`setup` varchar(15) NOT NULL DEFAULT '',
`ot2` varchar(15) NOT NULL,
`wageOT1` varchar(15) NOT NULL,
`wageOT2` varchar(15) NOT NULL,
`inTime` varchar(15) NOT NULL,
`outTime` varchar(15) NOT NULL,
`startDateString` varchar(125) NOT NULL,
`endDateString` varchar(125) NOT NULL,
`authRequestDate` datetime NOT NULL,
`authRequestUser` int(10) unsigned NOT NULL,
`authRequestReason` text NOT NULL,
`authDate` datetime NOT NULL,
`authUser` int(10) unsigned NOT NULL,
`authRequired` varchar(45) NOT NULL,
`km` varchar(45) NOT NULL,
`travelTime` varchar(45) NOT NULL,
`actualInTime` varchar(45) NOT NULL,
`actualOutTime` varchar(45) NOT NULL,
`actualKm` varchar(45) NOT NULL,
`actualTravelTime` varchar(45) NOT NULL,
`intNotes` text,
`extNotes` text,
`billableReason` text,
`billableHours` varchar(45) DEFAULT NULL,
`actualHours` varchar(45) DEFAULT NULL,
`overtime` varchar(45) DEFAULT NULL,
`followUpReason` text NOT NULL,
`responseType` varchar(45) DEFAULT NULL,
`followUpType` int(10) unsigned DEFAULT NULL,
`billableDrop` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`laborID`),
KEY `id` (`id`),
KEY `type` (`type`),
KEY `laborDate` (`laborDate`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
CREATE TABLE `b` (
`timecodeID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`userID` int(10) unsigned NOT NULL,
`inTime` varchar(45) NOT NULL,
`outTime` varchar(45) NOT NULL,
`startDateString` varchar(145) NOT NULL,
`endDateString` varchar(145) NOT NULL,
`startDate` varchar(45) NOT NULL,
`endDate` varchar(45) NOT NULL,
`type` varchar(45) NOT NULL,
`comments` text NOT NULL,
`multiDay` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`timecodeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Well if you have multiple rows in each of the table then you will get larger sum as each row in labor will join with each row in timecodes. So the idea is to have nested query group by clock and userid to get one row each as per the groupping
SELECT A.Clock, A.hours, B.'Misc Hours'
FROM
(
SELECT labor.clock,
SUM(hours) Hours
FROM labor
GROUP BY labor.clock
) A
INNER JOIN
(
SELECT timecodes.userID,
(SUM(
TIME_TO_SEC(
TIMEDIFF(
CONCAT(timecodes.endDate,' ',timecodes.outTime),
CONCAT(timecodes.startDate,' ',timecodes.inTime)
)
)/3600
)
) AS 'Misc Hours'
FROM timecodes
GROUP BY timecodes.userID
) AS B ON A.Clock = B.UserId
SELECT timecodes.userID,
(SUM(
TIME_TO_SEC(
TIMEDIFF(
CONCAT(timecodes.endDate,' ',timecodes.outTime),
CONCAT(timecodes.startDate,' ',timecodes.inTime)
)
)/3600
)
)
AS 'Misc Hours'
FROM timecodes WHERE timecodes.userID=labor.clock GROUP BY labor.clock

why Mysql is giving me error 1280 "Wrong Index"

Can anyone explain why Mysql is giving me error 1280 ("wrong index for 'fk_chart_aid_aid' ") error whend I try to create the "CHART OF ACCOUNTS" table. I'm completly confused here. How can I fix this so I can create the table? The "ACCOUNT" table already exists in the database and has data in it.
Thanks for the help.
MYSQL Server version: 5.1.54
CHART OF ACCOUNTS:
DROP TABLE IF EXISTS `rst`.`acctg_chart_of_accounts` ;
CREATE TABLE IF NOT EXISTS `rst`.`acctg_chart_of_accounts` (
`acctg_chart_of_accounts_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`account_id` INT UNSIGNED NOT NULL ,
`account_nbr` VARCHAR(45) NULL ,
`description` VARCHAR(45) NULL ,
`account_type` INT UNSIGNED NULL ,
`commissionable` TINYINT UNSIGNED NULL ,
`hidden` TINYINT UNSIGNED NULL ,
`deduct_balance_from_owner_check` TINYINT UNSIGNED NULL ,
PRIMARY KEY (`acctg_chart_of_accounts_id`) ,
CONSTRAINT `fk_chart_aid_aid`
FOREIGN KEY (`account_id` )
REFERENCES `rst`.`account` (`account_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
CREATE INDEX `fk_chart_aid_aid` ON `rst`.`acctg_chart_of_accounts` (`account_id` ASC) ;
ACCOUNTS TABLE THAT IS BEING REFERENCED:
CREATE TABLE IF NOT EXISTS `account` (
`account_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account_status_id` int(10) unsigned NOT NULL,
`company_name` varchar(155) DEFAULT NULL,
`address1` varchar(155) DEFAULT NULL,
`address2` varchar(155) DEFAULT NULL,
`city` varchar(155) DEFAULT NULL,
`state` varchar(155) DEFAULT NULL,
`zip` varchar(45) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL,
`work_phone` varchar(45) DEFAULT NULL,
`mobile_phone` varchar(45) DEFAULT NULL,
`time_zone` varchar(45) DEFAULT NULL,
`subdomain` varchar(155) DEFAULT NULL,
`cname_URL` varchar(255) DEFAULT NULL,
`promotion_code` varchar(45) DEFAULT NULL,
`can_we_contact_you` tinyint(4) DEFAULT NULL COMMENT '0=false, 1=true',
`units_managed_nbr` varchar(10) DEFAULT NULL,
`a_hear_about_us_list_id` tinyint(3) unsigned DEFAULT NULL COMMENT 'populated from dropdown list.',
`receive_special_offers` tinyint(4) DEFAULT NULL,
`receive_announcements` tinyint(4) DEFAULT NULL,
`receive_newsletter` tinyint(4) DEFAULT NULL,
`create_ts` timestamp NULL DEFAULT NULL,
`expires` timestamp NULL DEFAULT NULL,
`storage_capacity` varchar(255) DEFAULT NULL COMMENT '1073741824 = 1GB',
`logo` varchar(455) DEFAULT NULL,
`max_active_connections` int(11) DEFAULT '3',
`_product_id` int(11) DEFAULT NULL,
`report_footer` varchar(455) DEFAULT NULL,
`welcome_dialog` tinyint(4) DEFAULT '1',
`ARB_subscription_id` int(11) DEFAULT NULL,
`trashbin` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`account_id`),
KEY `fk_account_account_status_id` (`account_status_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=58 ;
Are you getting the error after the CREATE TABLE statement, or after the subsequent CREATE INDEX?
Looks like you are attempting to name both a FOREIGN KEY constraint and an INDEX fk_chart_aid_aid. Try choosing a different name for either one of them.
Also, in the accounts table, account_id is INT(10). Try also to change the column definition in acctg_chart_of_accounts to:
`account_id` INT(10) UNSIGNED NOT NULL ,
Though, I think that mysql defaults type INT to INT(10) anyway...
I met the same issue; tried manually rename the index to a different name but don't like the idea of 'manually' and neither I don't really understand why we need to generate the index separately. so I decide to generate it within the create statement by unchecking the option of 'generate separate index statement' in 'forwarding engineer', and this fix the issue.

SQL CREATE TABLE Error

The Answer was that I was using incorrect quotation marks instead of backticks. Stupid syntax hilighter tricked me.
I've been stuck on this one simple(ish) thing for the last 1/2 hour so I thought I might try to get a quick answer here.
What exactly is incorrect about my SQL syntax, assuming I'm using mysql 5.1
CREATE TABLE 'users' (
'id' INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
'username' VARCHAR(20) NOT NULL,
'password' VARCHAR(40) NOT NULL,
'salt' VARCHAR(40) DEFAULT NULL,
'email' VARCHAR(80) NOT NULL,
'created_on' INT(11) UNSIGNED NOT NULL,
'last_login' INT(11) UNSIGNED DEFAULT NULL,
'active' TINYINT(1) UNSIGNED DEFAULT NULL,
)
ENGINE InnoDB;
The error I get 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 ''users';
CREATE TABLE 'users' (
'id' INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,' at line 3
Elapsed Time: 0 hr, 0 min, 0 sec, 0 ms.
Also, does anyone have any good tutorials about how to use Zend_Auth for complete noobs?
Thanks.
Table and column identifiers are quoted using backticks (or double quotes if you've configured them).
Additionally you have a comma at the end of your column list.
CREATE TABLE `users` (
`id` MEDIUMINT( 8 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR( 20 ) NOT NULL,
`password` VARCHAR( 40 ) NOT NULL,
`salt` VARCHAR( 40 ) DEFAULT NULL,
`email` VARCHAR( 80 ) NOT NULL,
`created_on` INT( 11 ) UNSIGNED NOT NULL,
`last_login` INT( 11 ) UNSIGNED DEFAULT NULL,
`active` TINYINT( 1 ) UNSIGNED DEFAULT NULL
) ENGINE InnoDB
You are using single quotes instead of backticks for your table and field names, which is wrong. There should also be an equals sign between ENGINE and InnoDB.
Here's the fixed SQL:
CREATE TABLE `users` (
`id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(20) NOT NULL,
`password` VARCHAR(40) NOT NULL,
`salt` VARCHAR(40) DEFAULT NULL,
`email` VARCHAR(80) NOT NULL,
`created_on` INT(11) UNSIGNED NOT NULL,
`last_login` INT(11) UNSIGNED DEFAULT NULL,
`active` TINYINT(1) UNSIGNED DEFAULT NULL
)
ENGINE = InnoDB;