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
Related
Whenever I try to create a table
CREATE TABLE registration` (`id` INT NOT NULL , `name` VARCHAR(30) NOT NULL , `email` VARCHAR(20) NOT NULL , `password` VARCHAR(15) NOT NULL , `DOB` DATE NOT NULL , `age` INT NOT NULL , `number` BIGINT NOT NULL , `religion` VARCHAR(10) NOT NULL , `education` VARCHAR(20) NOT NULL , `profession` VARCHAR(20) NOT NULL , `gender` ENUM NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
The following error occurs
#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 (id)) ENGINE = InnoDB' at line 1
ENUM needs values so you need to define the values they can get
CREATE TABLE registration (
`id` INT NOT NULL
, `name` VARCHAR(30) NOT NULL
, `email` VARCHAR(20) NOT NULL
, `password` VARCHAR(15) NOT NULL
, `DOB` DATE NOT NULL
, `age` INT NOT NULL
, `number` BIGINT NOT NULL
, `religion` VARCHAR(10) NOT NULL
, `education` VARCHAR(20) NOT NULL
, `profession` VARCHAR(20) NOT NULL
, `gender` ENUM ('male','female')
, PRIMARY KEY (`id`)
) ENGINE = InnoDB;
When you declare a ENUM column (your gender column) you have to assign all possible values for the enumeration (See here for syntax)
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 `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;
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
)
I am using MySQL to create a small database. and facing some issues in foreign keys and primary key. I really don't understand as it seems a simple problem.
CREATE TABLE IF NOT EXISTS `db_trimms`.`urban_area` (
`area_id` INT(10) NOT NULL ,
`city` VARCHAR(60) NOT NULL ,
`state` VARCHAR(60) NOT NULL ,
`urban_area` VARCHAR(60) NOT NULL ,
`census_region` VARCHAR(60) NOT NULL ,
`area_no` VARCHAR(60) NOT NULL ,
`freeway_speed` VARCHAR(60) NOT NULL ,
`arterial_speed` VARCHAR(60) NOT NULL ,
PRIMARY KEY (`area_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
its running successfully. But while create another table and creating foreign key referring to the area_id of the above table...its creating issues...
#1005 - Can't create table 'db_trimms.emiss_others_offpeak' (errno: 150) (Details...)
and here is the query
CREATE TABLE IF NOT EXISTS `db_trimms`.`emiss_others_offpeak` (
`area_id` INT(10) UNSIGNED NOT NULL ,
`ammonia` VARCHAR(60) NOT NULL ,
`atm_carbon_dio` VARCHAR(60) NOT NULL ,
`carbon_dio_equiv` VARCHAR(60) NOT NULL ,
`carbon_mono` VARCHAR(60) NOT NULL ,
`methane` VARCHAR(60) NOT NULL ,
`nitrogen_dio` VARCHAR(60) NOT NULL ,
`nitrogen_oxide` VARCHAR(60) NOT NULL ,
`nitrous_oxide` VARCHAR(60) NOT NULL ,
`non_meth_hydrocarbs` VARCHAR(60) NOT NULL ,
`oxides_of_nitrogen` VARCHAR(60) NOT NULL ,
`particulate_matter_pm10` VARCHAR(60) NOT NULL ,
`particulate_matter_pm2_5` VARCHAR(60) NOT NULL ,
`sulfate` VARCHAR(60) NOT NULL ,
` sulfur_dioxide` VARCHAR(60) NOT NULL ,
`total_hydrocarbon` VARCHAR(60) NOT NULL ,
`vol_org_comp` VARCHAR(60) NOT NULL ,
PRIMARY KEY (`area_id`) ,
CONSTRAINT `fk_others_offpeak_urban`
FOREIGN KEY (`area_id` )
REFERENCES `db_trimms`.`urban_area` (`area_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
The data types are incompatible with each other. Make column area_id from table urban_area also UNSIGNED.
`area_id` INT(10) UNSIGNED NOT NULL ,
SQLFiddle Demo