Create a table with select columns from Another Table - mysql

I'm trying to break down a GPS point in a new table since the old table is in CHAR my new table will be set to INT.
Drop Table LoopTest1;
CREATE TABLE LoopTest1 (
`Account Number` char(32) NULL ,
`Latitude` decimal(30,2) NULL ,
`LatDegree` int(2) NULL ,
`LatMinutes` int(2) NULL ,
`LatSeconds` decimal(5,2) NULL ,
`LatDecimal` decimal(30,6) NULL ,
`Longitude` decimal(30,2) NULL ,
`LongDegree` int(2) NULL ,
`LongMinutes` int(2) NULL ,
`LongSeconds` decimal(5,2) NULL ,
`LongDecimal` decimal(30,6) NULL
);
set
LoopTest2.`Account Number` = LoopTest1.`Account Number`,
LoopTest2.Latitude = LoopTest1.Latitude,
LoopTest2.Longitude =LoopTest1. Longitude
FROM
LoopTest2
This will only be a temp table since I will update LoopTest2 with the changes made in LoopTest1

Related

MySQL error while trying to create table,

I'm using PHPMyAdmin, hosted with hostgator, to add a table to a database, but I keep getting the following 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 ') NOT NULL , note TEXT NOT NULL , cardNumber BIGINT(20) NOT NULL , `nameC' at line 1
Here's what I have:
and here's the preview of the SQL
CREATE TABLE `nightwin_mark-inn`.`guests` (
`id` INT(3) NOT NULL AUTO_INCREMENT ,
`dateIn` DATE NOT NULL ,
`dateOut` DATE NOT NULL ,
`email` TEXT NOT NULL ,
`phone` INT(10) NOT NULL ,
`room` TINYINT(2) NOT NULL ,
`price` DOUBLE(6) NOT NULL ,
`note` TEXT NOT NULL ,
`cardNumber` BIGINT(20) NOT NULL ,
`nameCard` TEXT NOT NULL ,
`expDate` TEXT NOT NULL ,
`cvc` TINYINT(3) NOT NULL ,
PRIMARY KEY (`id`)
)
What's causing this issue? Do I have the length of one of the fields wrong?
Try to use this
price` DOUBLE(6,2) NOT NULL //9999.99 max value stored
instead of
price` DOUBLE(6) NOT NULL
Note: for price field use datatype DECIMAL more preferable. In FLOAT or DOUBLE datatype you will get rounding number issue
Reference
You can try below - DOUBLE(6) should be only DOUBLE
CREATE TABLE `nightwin_mark-inn`.`guests` ( `id` INT(3) NOT NULL AUTO_INCREMENT ,
`dateIn` DATE NOT NULL , `dateOut` DATE NOT NULL , `email` TEXT NOT NULL ,
`phone` INT(10) NOT NULL , `room` TINYINT(2) NOT NULL , `price` DOUBLE NOT NULL ,
`note` TEXT NOT NULL , `cardNumber` BIGINT(20) NOT NULL , `nameCard` TEXT NOT NULL ,
`expDate` TEXT NOT NULL , `cvc` TINYINT(3) NOT NULL , PRIMARY KEY (`id`))
please try using this MySQL statement
CREATE TABLE `guests` ( `id` INT(3) NOT NULL AUTO_INCREMENT , `dateIn` DATE NOT NULL , `dateOut` DATE NOT NULL , `email` TEXT NOT NULL , `phone` INT(10) NOT NULL , `room` TINYINT(2) NOT NULL , `price` DOUBLE(6,2) NOT NULL , `note` TEXT NOT NULL , `cardNumber` BIGINT(20) NOT NULL , `nameCard` TEXT NOT NULL , `expDate` TEXT NOT NULL , `cvc` TINYINT(3) NOT NULL , PRIMARY KEY (`id`));
please try using this MySQL statement
CREATE TABLE guests ( id INT(3) NOT NULL AUTO_INCREMENT , dateIn DATE NOT NULL , dateOut DATE NOT NULL , email TEXT NOT NULL , phone INT(10) NOT NULL , room TINYINT(2) NOT NULL , price DOUBLE(6,2) NOT NULL , note TEXT NOT NULL , cardNumber BIGINT(20) NOT NULL , nameCard TEXT NOT NULL , expDate TEXT NOT NULL , cvc TINYINT(3) NOT NULL , PRIMARY KEY (id));

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.

Having an error in sql while creating table

I am trying to create a table on my database. this is the 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 , `ctc` DOUBLE(5) NOT NULL , `ref` VARCHAR(50) NOT NULL , `date` D' at line 1
My query:
CREATE TABLE `job`.`form_details` (
`email_id` VARCHAR(50) NOT NULL ,
`name` VARCHAR(50) NOT NULL ,
`number` VARCHAR(14) NOT NULL ,
`city` VARCHAR(50) NOT NULL ,
`skill` VARCHAR(50) NOT NULL ,
`qualification` VARCHAR(50) NOT NULL ,
`position` VARCHAR(50) NOT NULL ,
`exp` DOUBLE(5) NOT NULL ,
`ctc` DOUBLE(5) NOT NULL ,
`ref` VARCHAR(50) NOT NULL ,
`date` DATE NOT NULL ,
`time stamp` TIMESTAMP(30) NOT NULL ) ENGINE = InnoDB;
A double's precision is specified by two arguments - (M, D) - M digits in total and D digits after the decimal point. A timestamp's precision must be no greater than 6. So:
CREATE TABLE `job`.`form_details` (
`email_id` VARCHAR(50) NOT NULL ,
`name` VARCHAR(50) NOT NULL ,
`number` VARCHAR(14) NOT NULL ,
`city` VARCHAR(50) NOT NULL ,
`skill` VARCHAR(50) NOT NULL ,
`qualification` VARCHAR(50) NOT NULL ,
`position` VARCHAR(50) NOT NULL ,
`exp` DOUBLE(5, 2) NOT NULL , -- Two arguments for the double's precision
`ctc` DOUBLE(5, 2) NOT NULL , -- Here too
`ref` VARCHAR(50) NOT NULL ,
`date` DATE NOT NULL ,
`time stamp` TIMESTAMP(6) NOT NULL -- Timestamp precision capped at 6
) ENGINE = InnoDB

SQL Error when creating a table

I have a problem when I run this SQL query:
CREATE TABLE `softwaredb`.`profile`
( `id` INT(11) NOT NULL AUTO_INCREMENT ,
`user_id` INT(11) NOT NULL ,
`gender` VARCHAR(255) NOT NULL ,
`height` INT(4) NOT NULL ,
`weight` INT(4) NOT NULL ,
`bodytype` INT(1) NOT NULL )
The error I keep running into is the following:
Incorrect table definition;
there can be only one auto column and it must be defined as a key
Try this
CREATE TABLE `softwaredb`.`profile`
( `id` INT(11) NOT NULL AUTO_INCREMENT ,
`user_id` INT(11) NOT NULL ,
`gender` VARCHAR(255) NOT NULL ,
`height` INT(4) NOT NULL ,
`weight` INT(4) NOT NULL ,
`bodytype` INT(1) NOT NULL ,
primary key (id) //specify id as primary key will sort out the error..try
)
OR Try
CREATE TABLE `softwaredb`.`profile`
( `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT ,
`user_id` INT(11) NOT NULL ,
`gender` VARCHAR(255) NOT NULL ,
`height` INT(4) NOT NULL ,
`weight` INT(4) NOT NULL ,
`bodytype` INT(1) NOT NULL
)

What does the engine and char set means after the ()?

DROP DATABASE IF EXISTS `Database` ;
CREATE DATABASE `Database` ;
DROP TABLE IF EXISTS `Registration Form` ;
CREATE TABLE `Registration Form`
(
`ID` int(11) NOT NULL AUTO_INCREMENT ,
`Username` varchar(50) NOT NULL ,
`Password` varchar(50) NOT NULL ,
`Display Name` varchar(255) NOT NULL ,
`Question` varchar(255) NOT NULL ,
`Answer` varchar(255) NOT NULL ,
`Title` varchar(10) NOT NULL ,
`Name` varchar(255) NOT NULL ,
`Date Of Birth` date NOT NULL ,
`Gender` varchar(10) NOT NULL ,
`Address` varchar(255) NOT NULL ,
`Postal Code` int(11) NOT NULL ,
`City / Town` varchar(255) NOT NULL ,
`Federal Territory / State` varchar(255) NOT NULL ,
`Citizenship` varchar(255) NOT NULL ,
`E-mail` varchar(255) NOT NULL ,
`Contact Number` int(20) NOT NULL ,
`Registration Date` datetime NOT NULL ,
PRIMARY KEY ( `ID` )
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
I'm just starting to work arounnd mysql and php ... so bear with me as im a newbie ...
What does ALL the code after the CREATE() mean ? Why is there a ENGINE and DEFAULT what do they do ? Is CHARSET same as collation , if yes why not put it inside the row instead ? Do you need to give a length/value for date and daetime ?
CREATE TABLE is the sql clause which is required to creating a table.
After that you have to give a table name i.e "Registration Form" .but avoid spaces in between table name
Next what ever you gave those are column name along with their datatype and size.NOT NULL means while inserting data those column can't be blank.
For more details check the below link
http://www.tutorialspoint.com/mysql/mysql-create-tables.htm