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
)
Related
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.
CREATE TABLE `mealorder`.`order_item`
( `order_id` INT(20) NOT NULL AUTO_INCREMENT ,
`user_id` INT(20) NOT NULL ,
`item_type` VARCHAR(50) NOT NULL ,
`item_price` DOUBLE(20) NOT NULL ,
`item_quantity` INT(20) NULL ,
`date_time` DATETIME(5) NULL ,
`total_price` DOUBLE(20) NULL ,
PRIMARY KEY (`order_id`(20))) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `order_item` (
`order_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`item_type` varchar(50) NOT NULL,
`item_price` double NOT NULL,
`item_quantity` int(11) NOT NULL,
`date_time` datetime NOT NULL,
`total_price` double NOT NULL,
PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
my code :
CREATE TABLE IF NOT EXISTS `friends` (
`Id` INT(10) NOT NULL AUTO_INCREMENT,
`providerid` INT(10) NOT NULL AUTO_INCREMENT,
`requestid` INT(10) NOT NULL AUTO_INCREMENT,
`status` BINARY(1) NOT NULL,
PRIMARY KEY (`Id`)
);
CREATE TABLE IF NOT EXISTS `messages` (
`Id` INT(255) NOT NULL AUTO_INCREMENT,
`fromuid` INT(255) NOT NULL,
`touid` INT(255) NOT NULL,
`sentdt` DATETIME NOT NULL,
`read` TINYINT(1) NOT NULL DEFAULT '0',
`readdt` DATETIME DEFAULT NULL,
`messagetext` LONGTEXT CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`Id`)
);
CREATE TABLE IF NOT EXISTS `users` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR(45) NOT NULL DEFAULT '',
`password` VARCHAR(32) NOT NULL DEFAULT '',
`email` VARCHAR(45) NOT NULL DEFAULT '',
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
`authenticationTime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`userKey` VARCHAR(32) NOT NULL DEFAULT '',
`IP` VARCHAR(45) NOT NULL DEFAULT '',
`port` INT(10) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`Id`)
);
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 'CREATE TABLE IF NOT EXISTS messages (
Id int(255) NOT NULL AUTO_INCREMENT,' at line 8
so plz help me correcting the code...
Thank you
There are few errors in your script.
1) there can be only one autoincrement key and it must be defined as a key
2) spelling mistable in third query of DEFAULT in
`email` varchar(45) NOT NULL DEFAULT '',
3) DEFAULT keyword used twice in 3rd query for below field and missing NULL for NOT NULL
`authenticationTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
CORRECT query:-
CREATE TABLE IF NOT EXISTS `friends` (
`Id` int(10) NOT NULL AUTO_INCREMENT,
`providerid` int(10) NOT NULL ,
`requestid` int(10) NOT NULL ,
`status` binary(1) NOT NULL ,
PRIMARY KEY (`Id`));
CREATE TABLE IF NOT EXISTS `messages` (
`Id` int(255) NOT NULL AUTO_INCREMENT,
`fromuid` int(255) NOT NULL,
`touid` int(255) NOT NULL,
`sentdt` datetime NOT NULL,
`read` tinyint(1) NOT NULL DEFAULT '0',
`readdt` datetime DEFAULT NULL,
`messagetext` longtext CHARACTER SET utf8 NOT NULL ,
PRIMARY KEY (`Id`)
);
CREATE TABLE IF NOT EXISTS `users` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(45) NOT NULL DEFAULT '',
`password` varchar(32) NOT NULL DEFAULT '',
`email` varchar(45) NOT NULL DEFAULT '',
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` tinyint(3) unsigned NOT NULL DEFAULT '0',
`authenticationTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`userKey` varchar(32) NOT NULL DEFAULT '',
`IP` varchar(45) NOT NULL DEFAULT '',
`port` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`Id`)
)
I have prblem with sql when i try to check if table extist.
Am making component for joomla and when make install.sql i have sql syntax error.
check this and tell me what i do wrong:
DROP TABLE IF EXIST `#__ik_property_item`;
DROP TABLE IF EXIST `#__ik_property_categories`;
DROP TABLE IF EXIST `#__ik_property_type`;
DROP TABLE IF EXIST `#__ik_property_price_type`;
DROP TABLE IF EXIST `#__ik_property_agnts`;
DROP TABLE IF EXIST `#__ik_property_companies`;
DROP TABLE IF EXIST `#__ik_property_agnts`;
CREATE TABLE `#__ik_property_item` (
`id` INT NOT NULL AUTO_INCREMENT ,
`category_id` INT NULL ,
`property_type_id` INT NULL ,
`price_type_id` INT NULL ,
`company_id` INT NOT NULL ,
`agent_id` INT NOT NULL ,
`title` VARCHAR(45) NULL ,
`street` VARCHAR(45) NULL ,
`status` INT NULL ,
`featured` INT NULL ,
`yt_video` TEXT NULL ,
`map_lattitude` INT NULL ,
`map_longitude` VARCHAR(45) NULL ,
`beds` INT NULL ,
`baths` VARCHAR(45) NULL ,
`garage` VARCHAR(45) NULL ,
`flat_size` VARCHAR(45) NULL ,
`kitchens` VARCHAR(45) NULL ,
`year_build` VARCHAR(45) NULL ,
`floor` VARCHAR(45) NULL ,
`price` INT NULL ,
`image_1` VARCHAR(45) NULL ,
`image_2` VARCHAR(45) NULL ,
`image_3` VARCHAR(45) NULL ,
`image_4` VARCHAR(45) NULL ,
`image_5` VARCHAR(45) NULL ,
`meta_title` VARCHAR(45) NULL ,
`meta_description` TEXT NULL ,
`intro_text` TEXT NULL ,
`full_text` TEXT NULL ,
PRIMARY KEY (`id`) );
CREATE TABLE `#__ik_property_categories` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) );
CREATE TABLE `#__ik_property_type` (
`id` INT NOT NULL AUTO_INCREMENT ,
`title` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) );
CREATE TABLE `#__ik_property_price_type` (
`id` INT NOT NULL AUTO_INCREMENT ,
`title` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) );
CREATE TABLE `#__ik_property_agnts` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NULL ,
`last_name` VARCHAR(45) NULL ,
`first_name` VARCHAR(45) NULL ,
`email` VARCHAR(45) NULL ,
`website` VARCHAR(45) NULL ,
`phone` VARCHAR(45) NULL ,
`company` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) );
CREATE TABLE `#__ik_property_companies` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NULL ,
`logo` VARCHAR(45) NULL ,
`email` VARCHAR(45) NULL ,
`phone` VARCHAR(45) NULL ,
`website` VARCHAR(45) NULL ,
`street` VARCHAR(45) NULL ,
`fax` VARCHAR(45) NULL ,
`intro_text` VARCHAR(45) NULL ,
`full_text` VARCHAR(45) NULL ,
`image_1` VARCHAR(45) NULL ,
`image_2` VARCHAR(45) NULL ,
`image_3` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) );
When i remove
DROP TABLE IF EXIST `#__ik_property_item`;
DROP TABLE IF EXIST `#__ik_property_categories`;
DROP TABLE IF EXIST `#__ik_property_type`;
DROP TABLE IF EXIST `#__ik_property_price_type`;
DROP TABLE IF EXIST `#__ik_property_agnts`;
DROP TABLE IF EXIST `#__ik_property_companies`;
DROP TABLE IF EXIST `#__ik_property_agnts`;
All is success executed and when i call uninstall.sql code inside is like above all work good. But i need to check on installation if that tables exist if exist i must delete and save new.
Thanks
I have 3 tables
player, goal, card
how should i build my database so it automatically deletes goal and card row containing player id?
my declarations of tables i suppose i should add on delete cascade but i don't understand it very well so can any of you help me?
CREATE TABLE IF NOT EXISTS `#__footsal_players` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`ordering` INT(11) NOT NULL ,
`state` TINYINT(1) NOT NULL DEFAULT '1',
`checked_out` INT(11) NOT NULL ,
`checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` INT(11) NOT NULL ,
`id_team` INT(11) NOT NULL ,
`first_name` varchar(255) NOT NULL ,
`last_name` varchar(255) NOT NULL ,
`birth_date` DATE NOT NULL DEFAULT '0000-00-00',
`email` varchar(255) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT COLLATE=utf8_polish_ci
CREATE TABLE IF NOT EXISTS `#__footsal_goals` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`state` TINYINT(1) NOT NULL DEFAULT '1',
`checked_out` INT(11) NOT NULL ,
`checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` INT(11) NOT NULL ,
`id_player` INT(11) NOT NULL ,
`id_resault` INT(11) NOT NULL ,
`id_game` INT(11) NOT NULL ,
`goals_number` VARCHAR(255) NOT NULL ,
`id_session` VARCHAR(11) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT COLLATE=utf8_polish_ci;
CREATE TABLE IF NOT EXISTS `#__footsal_yellow_cards` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`state` TINYINT(1) NOT NULL DEFAULT '1',
`checked_out` INT(11) NOT NULL ,
`checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` INT(11) NOT NULL ,
`id_player` INT(11) NOT NULL ,
`id_game` INT(11) NOT NULL ,
`id_resault` INT(11) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT COLLATE=utf8_polish_ci;
I don't have MySQL running atm, but code below should work for goals. The idea is that when you define the foreign key, you assign delete and update rules. These apply when the primary key (id in player) is modified. So when the primary key in player is deleted (i.e. the player is deleted), the rows with corresponding foreign keys, behave according to their rule. Cascade means 'follow', so in this case delete it too.
CREATE TABLE IF NOT EXISTS `#__footsal_goals` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`state` TINYINT(1) NOT NULL DEFAULT '1',
`checked_out` INT(11) NOT NULL ,
`checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by` INT(11) NOT NULL ,
`id_player` INT(11) NOT NULL ,
`id_resault` INT(11) NOT NULL ,
`id_game` INT(11) NOT NULL ,
`goals_number` VARCHAR(255) NOT NULL ,
`id_session` VARCHAR(11) NOT NULL ,
PRIMARY KEY (`id`),
FOREIGN KEY goals_player_fk (`id_player`)
REFERENCES `#__footsal_players` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT COLLATE=utf8_polish_ci;