I am having trouble running a sql database, I wanted to create a youtube like database. I got this error.
CREATE TABLE `Like` ( `video_id` int(5) NOT NULL DEFAULT '0', `customer_id` int(6) NOT NULL DEFAULT '0', `rating` int(1) NOT NULL DEFAULT '0', `date` date NOT NULL DEFAULT '0000-00-00', PRIMARY KEY (`video_id`,`customer_id`), KEY `date` (`date`), KEY `video_id` (`video_id`), KEY `customer_id` (`customer_id`), KEY `rating` (`rating`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1
Error report -
SQL Error: ORA-00911: invalid character
00911. 00000 - "invalid character"'
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
CREATE TABLE `movies` ( `id` int(5) NOT NULL DEFAULT '0', `year` int(4) DEFAULT '0', `title` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `Channel` ( `movie_id` int(5) NOT NULL DEFAULT '0', `customer_id` int(6) NOT NULL DEFAULT '0', KEY `movie_id` (`movie_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `qualifying` ( `customer_id` int(6) NOT NULL DEFAULT '0', `date` date NOT NULL DEFAULT '0000-00-00', `movie_id` int(5) NOT NULL DEFAULT '0', KEY `movie_id` (`movie_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `Like` ( `video_id` int(5) NOT NULL DEFAULT '0', `customer_id` int(6) NOT NULL DEFAULT '0', `rating` int(1) NOT NULL DEFAULT '0', `date` date NOT NULL DEFAULT '0000-00-00', PRIMARY KEY (`video_id`,`customer_id`), KEY `date` (`date`), KEY `video_id` (`video_id`), KEY `customer_id` (`customer_id`), KEY `rating` (`rating`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Your main problem is that you are trying to run a SQL script with MySQL syntax on an Oracle database (you are clearly on an Oracle database because you are getting the ORA-00911 error).
Either you write your script using Oracle syntax, or change databases and use MySQL.
From your Error message and script it is clear that, You are trying to run Mysql table scripts in Oracle Database which is why you are getting error.
Here are few changes that you need to make in table scripts to wokr in Oracle database
Replace back-ticks with double quotes(")
Replace int(N) datatype with Number(P)
Example
CREATE TABLE "like"
(
"video_id" Number(10) NOT NULL DEFAULT '0',
"customer_id"Number(10) NOT NULL DEFAULT '0',
"rating" Number(10) NOT NULL DEFAULT '0',
"date" DATE NOT NULL DEFAULT '0000-00-00',
CONSTRAINT video_customers_pk PRIMARY KEY ("video_id", "customer_id")
KEY "date"("date"), -- Not sure how to change this in oracle
KEY video_id("video_id"),
KEY customer_id("customer_id"),
KEY rating("rating")
)
Note : I am not sure about the equivalent of this KEY video_id("video_id") in Oracle
Related
I am trying to upgrade from MariaDB 10.0 to 10.5 to use Galera Cluster. One of our tables has a key that the later versions won't accept. The error and table structure below.
Refactoring code is a last resort, so if there is a table definition change that can fix the problem that would be fantastic!
Thank you!
Error
ERROR 1901 (HY000) at line 40239: Function or expression
'concat(tc_sequence_db_code,tc_sequence_prefix,tc_sequence_table_name)'
cannot be used in the GENERATED ALWAYS AS clause of tc_sequence_id
The table structure
CREATE TABLE `tc_sequence` (
`tc_sequence_id` char(191) AS (concat(`tc_sequence_db_code`,`tc_sequence_prefix`,`tc_sequence_table_name`)),
`tc_sequence_table_name` char(191) NOT NULL,
`tc_sequence_db_code` char(2) NOT NULL DEFAULT '',
`tc_sequence_prefix` char(5) NOT NULL DEFAULT '',
`tc_sequence_next_id` int(11) NOT NULL DEFAULT 0,
`dt_temp_id` varchar(36) DEFAULT NULL,
`tc_sequence_trf_yn` tinyint(1) NOT NULL DEFAULT 0,
UNIQUE KEY `tc_sequence_id` (`tc_sequence_id`),
KEY `tc_sequence_table_name` (`tc_sequence_table_name`),
KEY `dt_temp_id` (`dt_temp_id`),
KEY `tc_sequence_trf_yn` (`tc_sequence_trf_yn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Thanks to Paul T for the clue that led to the solution. RTRIM around the CONCAT doesn't work but this does:
CREATE TABLE `tc_sequence` (
`tc_sequence_id` char(191) AS (concat(RTRIM(`tc_sequence_db_code`),RTRIM(`tc_sequence_prefix`),RTRIM(`tc_sequence_table_name`))),
`tc_sequence_table_name` char(191) NOT NULL,
`tc_sequence_db_code` char(2) NOT NULL DEFAULT '',
`tc_sequence_prefix` char(5) NOT NULL DEFAULT '',
`tc_sequence_next_id` int(11) NOT NULL DEFAULT 0,
`dt_temp_id` varchar(36) DEFAULT NULL,
`tc_sequence_trf_yn` tinyint(1) NOT NULL DEFAULT 0,
UNIQUE KEY `tc_sequence_id` (`tc_sequence_id`),
KEY `tc_sequence_table_name` (`tc_sequence_table_name`),
KEY `dt_temp_id` (`dt_temp_id`),
KEY `tc_sequence_trf_yn` (`tc_sequence_trf_yn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Much appreciated Paul T!
I was woring on a project last year, and was exporting and importing fine, but recently I decided to import my sql file and I cannot import due to lots of errors in each table.
I deleted xampp once I stopped working on it, and now decided to download it again, but am stuck on import, here is my full file:
http://pastebin.com/mddVUU1i
My error is the following:
CREATE TABLE company_type ( company_type_id int(11) NOT NULL,
company_type varchar(50) NOT NULL, company_type_date datetime
NOT NULL DEFAULT CURRENT_TIMESTAMP, company_type_enabled
varchar(15) NOT NULL DEFAULT 'enabled' ) ENGINE=InnoDB DEFAULT
CHARSET=latin1 MySQL said: Documentation
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 '-----------------------------------------
CREATE TABLE company_type ( `comp' at line 1
But when I delete that, I get another error:
CREATE TABLE employees ( employees_id int(11) NOT NULL,
employees_page int(11) NOT NULL, employees_page_type varchar(15)
NOT NULL, employees_user int(11) NOT NULL, employees_date
datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, employees_manage
varchar(15) NOT NULL DEFAULT 'sent' ) ENGINE=InnoDB DEFAULT
CHARSET=latin1 MySQL said: Documentation
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 '-----------------------------------------
------------------------------------' at line 1
How can I fix this? I have ran the sql through checkers online, and it state'sthe sql is fine.
Your table creation is wrong, you are misplacing datetime data-type to timestamp values.
Here is your first erroneous table
CREATE TABLE company_type ( company_type_id int(11) NOT NULL,
company_type varchar(50) NOT NULL, company_type_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, company_type_enabled varchar(15) NOT NULL DEFAULT 'enabled' ) ENGINE=InnoDB DEFAULT CHARSET=latin1
The problem here is
datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
You are using datetime datatype to timestamp values.
if you want to use timestamp datatype then do it this way
CREATE TABLE employees ( employees_id int(11) NOT NULL,
employees_page int(11) NOT NULL, employees_page_type varchar(15) NOT NULL, employees_user int(11) NOT NULL,
employees_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
employees_manage varchar(15) NOT NULL DEFAULT 'sent' ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
if you want to use datetime datatype then do it this way
CREATE TABLE employees1 ( employees_id int(11) NOT NULL,
employees_page int(11) NOT NULL, employees_page_type varchar(15) NOT NULL, employees_user int(11) NOT NULL,
employees_date datetime NOT NULL,
employees_manage varchar(15) NOT NULL DEFAULT 'sent' ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
There is the following script:
CREATE TABLE IF NOT EXISTS `location_cities` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`location_region_id` int(11) NOT NULL DEFAULT '0',
`location_district_id` int(11) DEFAULT NULL,
`location_country_id` int(11) NOT NULL DEFAULT '0',
`lon` float(11,8) NOT NULL DEFAULT '0.00000000',
`lat` float(11,8) NOT NULL DEFAULT '0.00000000',
`prefix` varchar(50) DEFAULT NULL,
`name` varchar(128) NOT NULL,
`size` int(3) NOT NULL DEFAULT '0' COMMENT 'Размер города',
`tz_name` varchar(128) DEFAULT NULL,
`timezone` varchar(100) NOT NULL DEFAULT '+00:00',
`timezone2` varchar(100) NOT NULL DEFAULT '+00:00',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12393 ;
When I try to execute it using 'sqlite3 db/development.sqlite3 < alogist.sql' I got error 'Error: near line 27: near "AUTO_INCREMENT": syntax error' (27 - the line with "CREATE_TABLE ...". So, what's the trouble? How can I fix it? Thanks!
In sqlite, an autoincrement column is specified as
INTEGER PRIMARY KEY AUTOINCREMENT
Replace your int(11) NOT NULL AUTO_INCREMENT with that.
Further problems:
COMMENT is not supported. Remove COMMENT 'Размер города'
Remove PRIMARY KEY (ID) - the primary key has already been specified.
Remove the MySQL-specific ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12393.
SQLite syntax:
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
I am using Yii framework and I have got a problem with CRUD generator.
I have got two tables called Users and news with the following structures:
CREATE TABLE IF NOT EXISTS `news` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`keyword` varchar(1000) COLLATE utf8_persian_ci DEFAULT NULL,
`user_id` tinyint(3) unsigned NOT NULL,
`title` varchar(100) COLLATE utf8_persian_ci DEFAULT NULL,
`body` varchar(1000) COLLATE utf8_persian_ci DEFAULT NULL,
`publishedat` date DEFAULT NULL,
`state` tinyint(1) unsigned DEFAULT NULL,
`archive` tinyint(1) unsigned DEFAULT NULL,
`last_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `news_FKIndex1` (`keyword`(255)),
KEY `news_FKIndex2` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(128) NOT NULL,
`create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`lastvisit_at` timestamp NULL DEFAULT NULL,
`is_disabled` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
KEY `status` (`is_disabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
when I generate a CRUD using Gii for my news table I cannot see the fields for users table. Instead of user_id I want to see the username in the table created by CRUD generator. How can I make a change in the code to get the result as above?
First, user_id needs to be a foreign key field not just a key field.
Second, gii will not generate the field as you require by default. For such functionality an extension such as Giix might help. However, since a relation exists you could always use relationName.username to display the username in a grid view or a list view.
i have this tabel,
CREATE TABLE `forum_rank` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL DEFAULT '0',
`rank` int(11) NOT NULL DEFAULT '0',
`forum_id` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
now i ask about what perfome best, its * or alle felt like this 2 eg.
select * form forum_rank;
or
select id, user_id, rank, forum_id from forum_rank;
You should explicitly specify the columns. Otherwise the database engine will first have to find out what the table's columns are (resolve the * operator) and after perform the actual query.
I don't think performance will be a problem here. There's a better reason to prefer the second idiom: your code is less likely to break if you add additional columns.