how can i change with timestamp mysql in a date - mysql

I have here MySQL code for my table but I want to change this date but I do not want time but just date what should I do I have already searched a lot on the internet but still found nothing. and I also have a week overview here how I would apply that.
I hope you can help me
regards stefaan
``-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 12, 2017 at 10:59 AM
-- Server version: 5.6.26
-- PHP Version: 5.5.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `phpcurdpdo`
--
-- --------------------------------------------------------
--
-- Table structure for table `tblusers`
--
CREATE TABLE IF NOT EXISTS `tblusers` (
`id` int(11) NOT NULL,
`Auditeur` varchar(150) NOT NULL,
`Zone` varchar(120) NOT NULL,
`NOKOK01` char(11) NOT NULL,
`NOKOK02` char(11) NOT NULL,
`NOKOK03` char(11) NOT NULL,
`NOKOK04` char(11) NOT NULL,
`Bericht` varchar(255) NOT NULL,
`PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Week` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `tblusers`
--
INSERT INTO `tblusers` (`id`, `Auditeur`, `Zone`, `NOKOK01`, `NOKOK02`, `NOKOK03`, `NOKOK04`, `Bericht`, `PostingDate`) VALUES
(1, 'Stefaan', 'Zone 2060', 'NOK', 'OK', 'OK', 'NOK', 'graag een verandering', '2017-12-12 06:27:53');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tblusers`
--
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tblusers`
--
ALTER TABLE `tblusers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;

Related

how can I spend those weeks in MySQL in this table?

So I want to release the weeks in MySQL here in this table but how do I do that I had tried something but nothing can be released here can anyone here help me and give a good example if it is possible. year weeks must be included.
a little explanation here if I have to calculate a score every week I have to see that. and if I do that every week I always see a zero here a picture
I hope you understand a little what I mean
enter image description here
-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 12, 2017 at 10:59 AM
-- Server version: 5.6.26
-- PHP Version: 5.5.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `stefaanphp`
--
-- --------------------------------------------------------
--
-- Table structure for table `tblusers`
--
CREATE TABLE IF NOT EXISTS `tblusers` (
`id` int(11) NOT NULL,
`Auditeur` varchar(150) NOT NULL,
`Afdeling` varchar(150) NOT NULL,
`Zone` varchar(120) NOT NULL,
`Stand` varchar(150) NOT NULL,
`Score` varchar(150) NOT NULL,
`number1` char(11) NOT NULL,
`number2` char(11) NOT NULL,
`number3` char(11) NOT NULL,
`number4` char(11) NOT NULL,
`number5` char(11) NOT NULL,
`number6` char(11) NOT NULL,
`number7` char(11) NOT NULL,
`PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Week` INTEGER NOT NULL -- 1 to 52/53
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `tblusers`
--
INSERT INTO `tblusers` (`id`, `Auditeur`, `Afdeling`, `Zone`, `Stand`, `Score`, `number1`, `number2`, `number3`, `number4`, `number5`, `number6`, `number7`, `Week`,`PostingDate`) VALUES
(1, 'stef', 'Combine', 'Hoofdlijn st1-4 + Onderraam 1010', 'St 6008', 'Totale Score:10', '5', '3', '3', '5', '10', '5', '1', '02', '2019-02-12 08:27:53');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tblusers`
--
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tblusers`
--
ALTER TABLE `tblusers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
and I still have a question to change that date with time to only date can not get time I had already done many other options for example date just get 000-00-0000
About your week question: you can use the MySQL week function to calculate the weeknumber of specific dates:
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week
The function expects a date or datetime, so you can just use the PostingDate that you are using in your insert statement.
About the other questions: maybe rephrase it so we can understand what you actually are asking.

importing table with primary auto_increment value zero to mariadb

I'm trying to import database dump into my mariaDb 10.2.6 database.
It's a Magento 2 database.
There is this table import:
# Dump of table store_website
# ------------------------------------------------------------
DROP TABLE IF EXISTS `store_website`;
CREATE TABLE `store_website` (
`website_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Website Id',
`code` varchar(32) DEFAULT NULL COMMENT 'Code',
`name` varchar(64) DEFAULT NULL COMMENT 'Website Name',
`sort_order` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT 'Sort Order',
`default_group_id` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT 'Default Group Id',
`is_default` smallint(5) unsigned DEFAULT 0 COMMENT 'Defines Is Website Default',
PRIMARY KEY (`website_id`),
UNIQUE KEY `STORE_WEBSITE_CODE` (`code`),
KEY `STORE_WEBSITE_SORT_ORDER` (`sort_order`),
KEY `STORE_WEBSITE_DEFAULT_GROUP_ID` (`default_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Websites';
LOCK TABLES `store_website` WRITE;
/*!40000 ALTER TABLE `store_website` DISABLE KEYS */;
INSERT INTO `store_website` (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`)
VALUES
(0,'admin','Admin',0,0,0),
(1,'my_website','MY_WEBSITE',0,1,1);
/*!40000 ALTER TABLE `store_website` ENABLE KEYS */;
UNLOCK TABLES;
This fails giving me a duplicate key 1 error. Obviously it tries to insert the value 0 as a new increment which would be 1 but that is already in the table.
This error appears even though these options are set:
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
As far as I know the InnoDB engine does not support the NO_AUTO_VALUE_ON_ZERO mode. It should be supported by MyISAM though.
Note that using zero as a key in a auto_increment column is not a recommended practice, so it is advisable to avoid it. Is it an option to import the data to MyISAM-tables, do whatever to change the zero-keys to positive numbers and then switch to InnoDB?

Cannot add foreign key constraint

First, here's my main reference table mysql dump
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 17, 2015 at 03:15 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */; /*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */; /*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Database: `j_inventory`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(200) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(500) COLLATE utf8_unicode_ci NOT NULL, `real_password` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `role` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `full_name` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `status` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=44 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
and the second table where the hopefully the foreign key resides
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 17, 2015 at 03:14 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */; /*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */; /*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Database: `j_inventory`
--
-- --------------------------------------------------------
--
-- Table structure for table `user_details`
--
CREATE TABLE IF NOT EXISTS `user_details` ( `id` int(11) NOT NULL AUTO_INCREMENT, `phone` varchar(200) NOT NULL, `age` int(100) NOT NULL, `gender` varchar(50) NOT NULL, `address` varchar(250) NOT NULL, `course` varchar(250) NOT NULL, `college` varchar(200) NOT NULL, `year` int(11) NOT NULL, `user_id` int(100) NOT NULL, `updated_at` timestamp NOT NULL, `created_at` timestamp NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
the foreign key (not set up due to mysql error "Cannot add foreign key constraint ") in the users_details is the 'user_id' and the reference table is the 'users' table where the reference key for the foreign key is the 'user_id' on the users table and I tried this
ALTER TABLE user_details ADD FOREIGN KEY fk1(user_id) REFERENCES
users(user_id) ON DELETE CASCADE ON UPDATE NO ACTION;
but sadly and unfortunately it throws me an error
Error SQL query:
ALTER TABLE user_details ADD CONSTRAINT fk1 FOREIGN KEY
(user_id) REFERENCES j_inventory.users(user_id) ON DELETE
CASCADE ON UPDATE NO ACTION; MySQL said: Documentation
1215 - Cannot add foreign key constraint Documentation
any help, clues, ideas, suggestions, recommendations please?
Your user id is unsigned on the users table. Remove 'unsigned' from this field in your users table create statement and see if it works. I think what you're seeing is an error caused by a mismatch between the user_id field types on your users and user_details tables

PHP MySQL: You have an error in your SQL syntax

Can someone help why this sql database gave me error: 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 'SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */' when i import this sql to my server?
-- phpMyAdmin SQL Dump
-- version 3.4.7.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 11, 2012 at 01:22 AM
-- Server version: 5.1.56
-- PHP Version: 5.2.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `testdb`
--
-- --------------------------------------------------------
--
-- Table structure for table `members`
--
CREATE TABLE IF NOT EXISTS `members` (
`id` int(11) NOT NULL,
`username` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`salary` int(11),
`student_year` int(11),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `members`
--
INSERT INTO `members` (`id`, `username`, `name`, `salary`, `student_year`) VALUES
(1, '11John', 'John Smith', 12000, NULL),
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
It Might be a Semicolon error at end of your insert Query
pls check it!!
INSERT INTO `members` (`id`, `username`, `name`, `salary`, `student_year`) VALUES (1, '11John', 'John Smith', 12000, NULL);

Mysql Database not creating table [messy code]

I tried to add this:
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 09, 2013 at 04:43 PM
-- Server version: 5.5.16
-- PHP Version: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `rezzion`
--
-- --------------------------------------------------------
--
-- Table structure for table `punishments`
--
CREATE TABLE IF NOT EXISTS `punishments` (
`username` varchar(20) NOT NULL AUTO_INCREMENT,
`punisher` varchar(20) NOT NULL,
`server` varchar(15) NOT NULL,
`type` int(255) NOT NULL,
`date` varchar(1024) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
to my database "rezzion" & for some reason i'm getting this error:
Anyone know why it's doing this? I have my database set to utf8-bin & it's name is rezzion... I'm confused why the code above isn't working?
Your error starts, at least, here:
`username` varchar(20) NOT NULL AUTO_INCREMENT,
This is not allowed in MySQL. And, besides, you're declaring primary key with another column:
PRIMARY KEY (`id`)
Auto Increment can only be used on a INT change it to a integer and your problem is solved
AUTO_INCREMENT my only be used with number types. You are applying it to a VARCHAR column. Also, you specify an "id" column as your primary key which does not exist.
You probably want it to look like this:
CREATE TABLE IF NOT EXISTS `punishments` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` varchar(20) NOT NULL,
`punisher` varchar(20) NOT NULL,
`server` varchar(15) NOT NULL,
`type` int(255) NOT NULL,
`date` varchar(1024) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;