MySQL "World" database for MS SQL Server - mysql

Does anyone know where there might be a copy of the MySQL "World" example database online somewhere that is Microsoft SQL compatible? I don't have a running MySQL server on hand, just the SQL text file that SQL Server 2008 rejects.

It is now :-) http://pastebin.com/6ATaLuNs
I have been able to load the database into my own SQL Server installation by converting the data types from MySql to SQL Server version, removing MySql-specific code (such as engine specification), and using CHECK constraints in place of the enum's. Here's my rough attempt at converting the table structure script:
BEGIN TRANSACTION
CREATE TABLE city (
ID int NOT NULL,
Name char(35) NOT NULL DEFAULT '',
CountryCode char(3) NOT NULL DEFAULT '',
District char(20) NOT NULL DEFAULT '',
Population int NOT NULL DEFAULT '0',
PRIMARY KEY (ID)
)
CREATE TABLE country (
Code char(3) NOT NULL DEFAULT '',
Name char(52) NOT NULL DEFAULT '',
Continent varchar(20) CHECK(Continent in ('Asia','Europe','North America','Africa','Oceania','Antarctica','South America')) NOT NULL DEFAULT 'Asia',
Region char(26) NOT NULL DEFAULT '',
SurfaceArea decimal(10,2) NOT NULL DEFAULT '0.00',
IndepYear smallint DEFAULT NULL,
Population int NOT NULL DEFAULT '0',
LifeExpectancy decimal(3,1) DEFAULT NULL,
GNP decimal(10,2) DEFAULT NULL,
GNPOld decimal(10,2) DEFAULT NULL,
LocalName char(45) NOT NULL DEFAULT '',
GovernmentForm char(45) NOT NULL DEFAULT '',
HeadOfState char(60) DEFAULT NULL,
Capital int DEFAULT NULL,
Code2 char(2) NOT NULL DEFAULT '',
PRIMARY KEY (Code)
)
CREATE TABLE countrylanguage (
CountryCode char(3) NOT NULL DEFAULT '',
Language char(30) NOT NULL DEFAULT '',
IsOfficial char(1) CHECK(IsOfficial IN ('T','F')) NOT NULL DEFAULT 'F',
Percentage decimal(4,1) NOT NULL DEFAULT '0.0',
PRIMARY KEY (CountryCode,Language)
)
COMMIT TRANSACTION
You can run the INSERT statements as-is if you make the following changes (you will have to manually pull out the INSERT statements by removing the CREATE TABLE code in the MySql script):
Remove all instances of back-tick (`) (Find-Replace ` with nothing in an editor)
Replace all instances of \' with '' for SQL Server's quote escaping

Related

SQL entries in French/English and Japanese

I have an old SQL4 database and I'm trying to re-upload it to our newly created database on Phpmyadmin. The characters in the tables are latin and japanese. I tried to change those specific columns but the result is still broken characters for the columns I need to display in Japanese.
Here is a screenshot of my problem : https://imgur.com/a/P6GWrnF
As an example, the SQL code looks like this :
CREATE TABLE `bdd` (
`id` int(11) NOT NULL,
`ville` varchar(50) NOT NULL DEFAULT '',
`nom_fr` varchar(80) NOT NULL DEFAULT '',
`nom_jp` varchar(250) CHARACTER SET sjis NOT NULL DEFAULT '',
`adr_fr` text NOT NULL,
`adr_jp` varchar(3000) CHARACTER SET sjis NOT NULL,
`tel` varchar(20) NOT NULL DEFAULT '0',
`plan` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `bdd` (`id`, `ville`, `nom_fr`, `nom_jp`, `adr_fr`, `adr_jp`, `tel`, `plan`) VALUES
(47, 'Tokyo', 'THE KNOT TOKYO Shinjuku', '?U ?m?b?g ?????V?h', '4-31-1 Nishi Shinjuku, Shinjuku Ku, Tokyo', '?????s?V?h???V?h4-31-1', '03-3375-6511', 'the knot.JPG'),
(3546, 'Tokyo', 'HOSHINOYA Tokyo', '???????', '1-9-1 Otemachi, Chiyoda-ku, Tokyo 100-0004', '??100-0004 ?????s?????c??????????9??1', '0570-073-066', 'HOSHINOYA TOKYO.JPG'),
SET NAMES "utf8";
CREATE TABLE `bdd` (
`id` int(11) NOT NULL,
`ville` varchar(50) NOT NULL DEFAULT '',
`nom_fr` varchar(80) NOT NULL DEFAULT '',
`nom_jp` varchar(250) CHARACTER SET sjis NOT NULL DEFAULT '',
`adr_fr` text NOT NULL,
`adr_jp` varchar(3000) CHARACTER SET sjis NOT NULL,
`tel` varchar(20) NOT NULL DEFAULT '0',
`plan` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT whatever you want
It would be better if you stored everything in utf8 as you have multiple langueages. And before insertion you neeed to set your connection parameters accordingly so server can understand what you're sending. Btw maybe you'll have to
SET NAMES 'sjis';
Problem solved.
I didn't try to change encoding any longer but created a new table with all rows in utf8mb4_unicode_ci and imported the data within this new table.

MariaDB - CONNECT ENGINE - ORDER BY error

I'm trying to get Asterisk CDR records from MySQL table (5.5.45) by CONNECT engine on other server running MariaDB (10.0.29).
I can create the connection between table easily:
CREATE TABLE `calls` engine=CONNECT table_type=MYSQL
CONNECTION='mysql://user#IP/asteriskcdrdb/calls';
When I run simple SELECT * FROM calls, everything works good, when I add some WHERE conditions, still everything okay.
But the problem start when I add ORDER BY column parameter, then I got this error from MariaDB:
#1032 - Can't find record in 'calls'
I checked MySQL log, MariaDB log - there are no errors at all.
Did I miss something?
Thank you!
Update: The whole query is simple:
SELECT * FROM `calls` ORDER BY `calldate`
The table structure:
CREATE TABLE `calls` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`uniqueid` varchar(32) NOT NULL default '',
`userfield` varchar(255) NOT NULL default '',
`recordingfile` varchar(255) NOT NULL default '',
`cnum` varchar(40) NOT NULL default '',
`cnam` varchar(40) NOT NULL default '',
`outbound_cnum` varchar(40) NOT NULL default '',
`outbound_cnam` varchar(40) NOT NULL default '',
`dst_cnam` varchar(40) NOT NULL default '',
`call_charge` float NOT NULL default '0',
`from_did` varchar(30) NOT NULL,
`did` varchar(50) NOT NULL default '',
`user_id` int(8) unsigned default NULL,
`client_id` int(8) unsigned default NULL,
KEY `IDX_UNIQUEID` (`uniqueid`),
KEY `src` (`src`),
KEY `dst` (`dst`),
KEY `calldate` (`calldate`),
KEY `uniqueid` (`uniqueid`),
KEY `userfield` (`userfield`),
KEY `from_did` (`from_did`),
KEY `user_id` (`user_id`),
KEY `client_id` (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Update #2: Update the table names, to don't confuse, but it's not the issue. The CONNECTION table is created okay.
Query works:
SELECT * FROM `calls`
Query works:
SELECT * FROM `calls` WHERE `user_id`=X
Query return error:
SELECT * FROM `calls` ORDER BY `calldate`
Update #3: The MySQL was updated to veriosn 5.5.45, the type was changed to InnoDB and the charset was converted to UTF8. But no success.
PROBLEM SOLVED
Well, it's MariaDB bug, when I changed to FederatedX engine (which is basically little bit limited version of CONNECT), everything works as expected.
In your query you do
SELECT * FROM calls
but in your table structure you have
CREATE TABLE cdr
and both have calldate column. Check if you querying the right table.

MySQL - Unable to create and ENUM column

On MySQL 5.1.73 I've created a table with an Enum column as following:
create table IF NOT EXISTS rollover_profile
(
rollover_profile_id BIGINT(20) PRIMARY KEY NOT NULL AUTO_INCREMENT,
max_period INT(10) NOT NULL,
percentage INT(10) NOT NULL,
type VARCHAR(10) NOT NULL,
description VARCHAR(1024) NOT NULL,
logical_delete_yn ENUM('Y','N') NOT NULL DEFAULT 'N',
published_yn ENUM('Y','N') NOT NULL DEFAULT 'N'
);
but when I inspect the table logical_delete_yn and published_yn are defined as ENUM('','')
I tried on another MySQL server (ver 5.0.77) and there seems to be fine.
Is it some MySQL option wrong?
Turns out the charset on the new server had been changed to UCS2. Changing it to UTF8 solved the issue.
The weird thing is that changing the query to
create table IF NOT EXISTS rollover_profile
(
rollover_profile_id BIGINT(20) PRIMARY KEY NOT NULL AUTO_INCREMENT,
max_period INT(10) NOT NULL,
percentage INT(10) NOT NULL,
type VARCHAR(10) NOT NULL,
description VARCHAR(1024) NOT NULL,
logical_delete_yn ENUM('Y','N') NOT NULL DEFAULT 'N',
published_yn ENUM('Y','N') NOT NULL DEFAULT 'N'
);
or to anything where the two ENUMs don't have the same values works fine on UCS2.

MySQL #1064 - You have an error in your SQL syntax at line 2

What's wrong on this code? I receive that message when try to import this sql:
#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 ''codigo' int(11) unsigned NOT NULL auto_increment, 'razao_social' varchar(11) N' at line 2
CREATE TABLE IF NOT EXISTS `char` (
'codigo' int(11) unsigned NOT NULL auto_increment,
'razao_social' varchar(11) NOT NULL DEFAULT '',
'fantasia' varchar(11) NOT NULL DEFAULT '',
'data_de_cadastro' datetime NOT NULL DEFAULT '',
'cep' varchar(11) NOT NULL DEFAULT '',
'logradouro' varchar(11) NOT NULL DEFAULT '',
'numero' varchar(11) NOT NULL DEFAULT '',
'complemento' varchar(11) NOT NULL DEFAULT '',
'bairro' varchar(11) NOT NULL DEFAULT '',
'cidade' varchar(11) NOT NULL DEFAULT '',
'uf' varchar(11) NOT NULL DEFAULT '',
'cnpj' varchar(11) NOT NULL DEFAULT '',
'insc_estadual' varchar(11) NOT NULL DEFAULT '',
'incs_municipal' varchar(11) NOT NULL DEFAULT '',
'telefone01' varchar(11) NOT NULL DEFAULT '',
'telefone02' varchar(11) NOT NULL DEFAULT '',
'contato' varchar(11) NOT NULL DEFAULT '',
'associados' varchar(11) NOT NULL DEFAULT '',
'funcionários' varchar(11) NOT NULL DEFAULT '',
'data_socio' datatime NOT NULL DEFAULT '',
'data_desligamento' datatime NOT NULL DEFAULT '',
'email' varchar(11) NOT NULL DEFAULT '',
'website' varchar(11) NOT NULL DEFAULT '',
'situacao' int(11) NOT NULL DEFAULT '',
PRIMARY KEY (`codigo`),
UNIQUE KEY `razao_social` (`razao_social`),
KEY `fantasia` (`account_id`),
KEY `cnpj` (`cnpj`),
KEY `insc_estadual` (`insc_estadual`),
KEY `incs_municipal` (`incs_municipal`)
) ENGINE=MySQL;
you should use backticks ` in MySQL to escape column name identifiers, not single quotes ' (actually, all identifiers, just like you've done with you table name);
you provide datatime as the datatype for data_socio and
data_desligamento, which is invalid (because it doesn't exist, I think you've meant datetime);
MySQL is not a valid engine option (maybe you've meant MyISAM?), here is a list of storage engines;
'' is not a valid default value for the datetime datatype (data_desligamento, data_socio and data_de_cadastro);
you are creating an index fantasia using a key for the column account_id that doesn't even exist in your table (or it is just a typo and either fantasia column should be called account_id or vice versa? - just guessing here).
SQLFiddle
Do not use single quotes(') in column names, instead use tild symbol (`).
For example:
this column 'razao_social' should be write as `razao_social`

MySql don't create these table [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
1064 error in CREATE TABLE … TYPE=MYISAM
I am trying to install a PHP script named php-stats, this one: http://www.php-stats.it/ that is a Php that provides information about statistic of web site.
I have used it in the past and it is pretty good.
Today I am trying to install it on my server but I have some problem
It need to be installed on the server and use the database...my problem is when it try to create the database table...go into error with many tables...
The errors have the form of the following one (this is related to one specific table):
Error executing: CREATE TABLE php_stats_cache ( user_id varchar(15) NOT NULL default '0', data int(11) NOT NULL default '0', lastpage varchar(255) NOT NULL default '0', visitor_id varchar(32) NOT NULL default '', hits tinyint(3) unsigned NOT NULL default '0', visits smallint(5) unsigned NOT NULL default '0', reso varchar(10) NOT NULL default '', colo varchar(10) NOT NULL default '', os varchar(20) NOT NULL default '', bw varchar(20) NOT NULL default '', host varchar(50) NOT NULL default '', lang varchar(8) NOT NULL default '', giorno varchar(10) NOT NULL default '', level tinyint(3) unsigned NOT NULL default '0', UNIQUE KEY user_id (user_id) ) TYPE=MyISAM
Error string: 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 'TYPE=MyISAM' at line 17
I have also try to access inside the *.sql file that contains the query definition and execute the creation query table inside PHP MyAdmin, for example this query (related to the previus error):
DROP TABLE IF EXISTS php_stats_cache;
CREATE TABLE php_stats_cache (
user_id varchar(15) NOT NULL default '0',
data int(11) NOT NULL default '0',
lastpage varchar(255) NOT NULL default '0',
visitor_id varchar(32) NOT NULL default '',
hits tinyint(3) unsigned NOT NULL default '0',
visits smallint(5) unsigned NOT NULL default '0',
reso varchar(10) NOT NULL default '',
colo varchar(10) NOT NULL default '',
os varchar(20) NOT NULL default '',
bw varchar(20) NOT NULL default '',
host varchar(50) NOT NULL default '',
lang varchar(8) NOT NULL default '',
giorno varchar(10) NOT NULL default '',
level tinyint(3) unsigned NOT NULL default '0',
UNIQUE KEY user_id (user_id)
) TYPE=MyISAM;
Ig I try to execute this query inside PhpMyAdmin I obtain the following error message:
#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 'TYPE=MyISAM' at line 17
I also try to execute it on my local mysql server on my PC but I obtain always the same error message...
Why? What is the problem? How can I do to solve this problem?
Thank you
Andrea
Using TYPE has been deprecated and it was removed in MySQL 5.5. Use ENGINE = MYISAM instead.
CREATE TABLE php_stats_cache (....) ENGINE = MYISAM;