mysqldump + auto_increment causing primary key error - primary-key

I am using mysqldump to (a) dump a table, then (b) insert it elsewhere. A problem occurs when I try to do part (b). Here is the error I get.
Duplicate entry '1' for key 'PRIMARY'
Now, hold on, hold on. I know I'm not inserting duplicate primary keys .... I checked the CREATE TABLE statement. The auto_incremement on the id field is left at the greatest value for the id column: AUTO_INCREMENT=45634650. I believe that the problem is that MySQL will give this error if you try to insert any row with an id value less than what the auto_increment value is specified at .... regardless if that id is a duplicate or not.
I tried manually removing the AUTO_INCREMENT from the TABLE CREATE statement. Same error still.
UPDATE: Here are some relevant parts of the Create table statement. Leaving out the inserts, even one of them is huge:
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
/*Table structure for table `WC_ip` */
DROP TABLE IF EXISTS `WC_ip`;
CREATE TABLE `WC_ip` (
`id` int(11) NOT NULL AUTO_INCREMENT,
etc etc .. =)
`activity_date` date DEFAULT NULL,
UNIQUE KEY `userid_game_installAge` (`userid`,`game`,`install_age`),
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=45750081 DEFAULT CHARSET=latin1;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
INSERT INTO `bi_user_daily` VALUES (1,1512489,'WC','1','GR','100001229652633','asfdasdf','http://www.facebook.com/asfdasdfasdffgdf','notif','gghgf','Secondary Paid Direct','2012-01-02',0,0,0.00,0,0,0,0,194,0,0,1325491229,'Google Chrome','16.0.912.63','windows','GR','178.146.208.153',0,1325491253,24,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'incomplete',91,2,1914,2,1,3.23,0,NULL,NULL,NULL,NULL,0,'2012-01-03','2012-01-03 07:06:57','2012-01-02'),
(2,1512490,'WC','1','TW','453','asdf','http://www.facebook.com/profile.php?id=blachdfhjdfkh','dfdsfg','','Primary Paid','2012-01-02',0,0,0.00,0,0,0,0,394,0,0,1325491233,'Google Chrome','16.0.912.63','windows','TW','114.41.159.234',0,1325491258,25,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'complete',120,2,2302,2,1,6.57,0,NULL,NULL,NULL,NULL,0,'2012-01-03','2012-01-03 07:06:57','2012-01-02'),
(3,1512491,'WC','1','','1590571243','','','notif','asfd','Secondary Paid Direct','2012-01-02',0,0,0.00,0,0,0,0,0,0,0,34535,'Mozilla Firefox','9.0.1','windows','-','10.54.48.31',1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0.00,0,NULL,NULL,NULL,NULL,0,'2012-01-03','2012-01-03 07:06:57','2012-01-02')
CREATE TABLE `bi_user_daily` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userid` bigint(20) DEFAULT NULL,
`game` varchar(45) DEFAULT NULL,
`main.install_today` varchar(45) DEFAULT NULL,
`main.country` text,
`main.fbid` varchar(50) DEFAULT NULL,
`main.photo` text,
`main.main.url` text,
`main.fromstr` varchar(50) DEFAULT NULL,
`main.sourcestr` varchar(50) DEFAULT NULL,
`main.user_type` varchar(50) DEFAULT NULL,
`main.install_date_pst` date DEFAULT NULL,
`main.install_hour_pst` int(11) DEFAULT NULL,
`main.revenue_primary` int(11) DEFAULT NULL,
`main.revenue_secondary` decimal(10,2) DEFAULT NULL,
`main.trans_primary` int(11) DEFAULT NULL,
`main.trans_secondary` int(11) DEFAULT NULL,
`main.direct_installs_generated` int(11) DEFAULT NULL,
`main.indirect_installs_generated` int(11) DEFAULT NULL,
`main.timeplayed_total` int(11) DEFAULT NULL,
`main.gift_sent_total` int(11) DEFAULT NULL,
`main.monetized` int(11) DEFAULT NULL,
`install.usercreate_time` int(11) DEFAULT NULL,
`install.browser` varchar(75) DEFAULT NULL,
`install.browser_version` varchar(50) DEFAULT NULL,
`install.os` varchar(50) DEFAULT NULL,
`install.ip_address_country` varchar(50) DEFAULT NULL,
`install.ip_address` varchar(50) DEFAULT NULL,
`install.noload` int(11) DEFAULT NULL,
`install.f.reate_time` int(11) DEFAULT NULL,
`install.load_duration` int(11) DEFAULT NULL,
`l.f.time_saved` int(11) DEFAULT NULL,
`l.f.playerLevel` int(11) DEFAULT NULL,
`l.f.daysSinceInstall` int(11) DEFAULT NULL,
`l.f.resource1` int(11) DEFAULT NULL,
`l.f.resource2` int(11) DEFAULT NULL,
`l.f.resource3` int(11) DEFAULT NULL,
`l.f.resource4` int(11) DEFAULT NULL,
`l.f.f.epairTime` int(11) DEFAULT NULL,
`l.f.dockRepairTime` int(11) DEFAULT NULL,
`l.f.fleetRepairTime` int(11) DEFAULT NULL,
`l.f.maxResearchTime` int(11) DEFAULT NULL,
`l.f.shipBuildTime` int(11) DEFAULT NULL,
`l.f.buildingUpgradeTime` int(11) DEFAULT NULL,
`l.f.numf.Uncovered` int(11) DEFAULT NULL,
`l.f.attackablef.Uncovered` int(11) DEFAULT NULL,
`l.f.numTerrainsUncovered` int(11) DEFAULT NULL,
`l.f.numFleets` int(11) DEFAULT NULL,
`l.f.battlesWon` int(11) DEFAULT NULL,
`l.f.battlesTotal` int(11) DEFAULT NULL,
`l.f.numf.ttacks` int(11) DEFAULT NULL,
`l.f.numf.efends` int(11) DEFAULT NULL,
`l.f.totalResourcesCombat` int(11) DEFAULT NULL,
`l.f.totalResourcesProduced` int(11) DEFAULT NULL,
`l.f.bubbleTimeLeft` int(11) DEFAULT NULL,
`l.f.FBCSpend` int(11) DEFAULT NULL,
`l.f.numFriends` int(11) DEFAULT NULL,
`l.f.numInstallsGenerated` int(11) DEFAULT NULL,
`l.f.numGiftsRecd` int(11) DEFAULT NULL,
`l.f.numChatMessagesSent` int(11) DEFAULT NULL,
`l.f.numMissionsCompleted` int(11) DEFAULT NULL,
`l.f.numAdvancedResearched` int(11) DEFAULT NULL,
`l.f.numWeaponsResearched` int(11) DEFAULT NULL,
`l.f.numArmorsResearched` int(11) DEFAULT NULL,
`l.f.numHullsResearched` int(11) DEFAULT NULL,
`l.summary.tutorial_status` varchar(50) DEFAULT NULL,
`l.summary.tutorial_stage` int(11) DEFAULT NULL,
`l.summary.user_level` int(11) DEFAULT NULL,
`l.summary.f.points` int(11) DEFAULT NULL,
`l.summary.f.loads` int(11) DEFAULT NULL,
`key_metrics.logged_in` int(11) DEFAULT NULL,
`key_metrics.timeplayed` decimal(10,2) DEFAULT NULL,
`key_metrics.revenue` int(11) DEFAULT NULL,
`virality.secondary_direct_install` int(11) DEFAULT NULL,
`virality.secondary_indirect_install` int(11) DEFAULT NULL,
`monetization.secondary_direct_revenue` decimal(10,2) DEFAULT NULL,
`monetization.secondary_indirect_revenue` decimal(10,2) DEFAULT NULL,
`install_age` int(11) DEFAULT NULL,
`record_created_date` date DEFAULT NULL,
`record_created_datetime` datetime DEFAULT NULL,
`activity_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `userid_game_installAge` (`userid`,`game`,`install_age`)
) ENGINE=MyISAM AUTO_INCREMENT=45634650 DEFAULT CHARSET=latin1;

I ran into this very same issue a few months ago (posted solution on my blog). There is a known issue with MySQL 5.1.11+ where if you do a mysqldump, it also outputs the auto_increment count (as you stated in your post). You can use sed (stream edit) and parse out the auto_increment construct when generating your dump file:
mysqldump -u username -p -h <db-host> --opt <db-name> -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > <filename>.sql

Are the auto_increment values set as NULL or as a particular number if they are NULL they will use the next value as specified by the table definition. If they are explicitly expressed then they shall be inserted as that value unless a duplicate exists?

I hope this help you
ALTER TABLE table2 AUTO_INCREMENT = 1;
or remove primary key on table2 and find same records.

Related

SQL Syntax Error: "Error: near "CHARACTER": syntax error"

I am trying to create a table to separate a huge database I have in a textfile into just username:email instead of their entire user:email:hash:etc
I have this:
>>>CREATE TABLE `database`(
`UserGUID` varchar(40) CHARACTER SET latin1 NOT NULL,
`UserName` varchar(80) CHARACTER SET utf8 NOT NULL,
`Email` varchar(128) CHARACTER SET latin1 NOT NULL,
`Password` varchar(128) CHARACTER SET latin1 NOT NULL,
`Salt` varchar(128) CHARACTER SET latin1 NOT NULL,
`Strikes` int(10) unsigned NOT NULL DEFAULT '0',
`Locked` tinyint(1) unsigned NOT NULL DEFAULT '0',
`Deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
`CreatedDate` datetime NOT NULL,
`UpdatedDate` datetime DEFAULT NULL,
`DeletedDate` datetime DEFAULT NULL,
`CreatedBy` varchar(40) CHARACTER SET latin1 NOT NULL DEFAULT 'System',
`UpdatedBy` varchar(40) CHARACTER SET latin1 DEFAULT NULL,
`DeletedBy` varchar(40) CHARACTER SET latin1 DEFAULT NULL,
`EmailAuthenticated` tinyint(1) unsigned NOT NULL DEFAULT '0',
`FollowID` int(10) unsigned DEFAULT NULL,
`DefaultLocationID` int(10) unsigned DEFAULT NULL,
`birthDay` int(10) unsigned DEFAULT NULL,
`birthMonth` int(10) unsigned DEFAULT NULL,
`birthYear` int(10) unsigned DEFAULT NULL,
`BirthDate` datetime DEFAULT NULL,
`EmailAuthKey` varchar(45) COLLATE latin1_general_ci DEFAULT NULL,
`CurrentCrowns` int(11) NOT NULL DEFAULT '0',
`CurrentCardpoints` int(11) NOT NULL DEFAULT '0',
`LastFreeCrowns` datetime DEFAULT NULL,
`plaintextpassword` varchar(500) COLLATE latin1_general_ci DEFAULT NULL,
`LastAuthEmail` datetime DEFAULT NULL,
`premiumcards` int(11) DEFAULT NULL,
`steamid` varchar(80) COLLATE latin1_general_ci DEFAULT NULL,
`ExternalPromotionID` varchar(45) COLLATE latin1_general_ci DEFAULT NULL,
`culture` varchar(40) COLLATE latin1_general_ci DEFAULT NULL,
PRIMARY KEY (`UserGUID`) USING BTREE,
UNIQUE KEY `Username` (`UserName`),
UNIQUE KEY `Email` (`Email`),
UNIQUE KEY `Follow` (`FollowID`) USING BTREE,
KEY `EmailAuthenticated` (`EmailAuthenticated`),
KEY `SteamID` (`steamid`),
KEY `authkey` (`EmailAuthKey`),
KEY `IX_CreatedDate` (`CreatedDate`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
I keep getting this error: Error: near "CHARACTER": syntax error
help?

Gii CRUD generator and related tables

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.

converting mysql database to sql server

i have a mysql database:
/*
MySQL Data Transfer
Source Host: 10.0.0.5
Source Database: jnetdata
Target Host: 10.0.0.5
Target Database: jnetdata
Date: 5/26/2009 12:27:33 PM
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for chavrusas
-- ----------------------------
CREATE TABLE `chavrusas` (
`id` int(11) NOT NULL auto_increment,
`date_created` datetime default NULL,
`luser_id` int(11) default NULL,
`ruser_id` int(11) default NULL,
`luser_type` varchar(50) default NULL,
`ruser_type` varchar(50) default NULL,
`SessionDay` varchar(250) default NULL,
`SessionTime` datetime default NULL,
`WeeklyReminder` tinyint(1) NOT NULL default '0',
`reminder_phone` tinyint(1) NOT NULL default '0',
`calling_card` varchar(50) default NULL,
`active` tinyint(1) NOT NULL default '0',
`notes` mediumtext,
`ended` tinyint(1) NOT NULL default '0',
`end_date` datetime default NULL,
`initiated_by_student` tinyint(1) NOT NULL default '0',
`initiated_by_volunteer` tinyint(1) NOT NULL default '0',
`student_general_reason` varchar(50) default NULL,
`volunteer_general_reason` varchar(50) default NULL,
`student_reason` varchar(250) default NULL,
`volunteer_reason` varchar(250) default NULL,
`student_nli` tinyint(1) NOT NULL default '0',
`volunteer_nli` tinyint(1) NOT NULL default '0',
`jnet_initiated` tinyint(1) default '0',
`belongs_to` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5913 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for tbluseravailability
-- ----------------------------
CREATE TABLE `tbluseravailability` (
`availability_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`weekday_id` int(11) NOT NULL,
`timeslot_id` int(11) NOT NULL,
PRIMARY KEY (`availability_id`)
) ENGINE=MyISAM AUTO_INCREMENT=10865 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for tblusers
-- ----------------------------
CREATE TABLE `tblusers` (
`id` int(11) NOT NULL auto_increment,
`password` varchar(50) default NULL,
`title` varchar(255) default NULL,
`first` varchar(255) default NULL,
`last` varchar(255) default NULL,
`gender` varchar(255) default NULL,
`address` varchar(255) default NULL,
`address_2` varchar(255) default NULL,
`city` varchar(255) default NULL,
`state` varchar(255) default NULL,
`postcode` varchar(255) default NULL,
`country` varchar(255) default NULL,
`email` varchar(255) default NULL,
`emailnotes` varchar(255) default NULL,
`Home_Phone` varchar(255) default NULL,
`Office_Phone` varchar(255) default NULL,
`Cell_Phone` varchar(255) default NULL,
`Contact_Preference` varchar(255) default NULL,
`Birthdate` datetime default NULL,
`Age` varchar(255
and it goes on for about 10mb
i need to convert it to ms sql, how do i do it?
i remember that i used this small tool to convert maybe it may help you, check here.
Another tool MySQL-to-MSSQL is more powerful.
Some options:
Microsoft SQL Server Migration Assistant 2008 for MySQL v1.0 CTP1
Guide to Migrating from MySQL to SQL Server 2008
Migrating from MySQL to SQL Server 2005
Haven't used this, so can't comment on it's effectiveness:
Migrate MySQL to Microsoft SQL Server
Might be useful (if you don't already have it):
Microsoft® SQL Server® 2008 Management Studio Express
Take a look at the Microsoft SQL Server Migration Assistant 2008 for MySQL v1.0 CTP1
Microsoft SQL Server Migration Assistant (SSMA) 2008 is a toolkit that dramatically cuts the effort, cost, and risk of migrating from MySQL to SQL Server 2008 and SQL Azure. SSMA 2008 for MySQL v1.0 CTP1 provides an assessment of migration efforts as well as automates schema and data migration.
Try SQL Examiner Suite 2010

running 8mb of sql code in wamp?

i have about 8mb of sql code i need to run. it looks like this:
/*
MySQL Data Transfer
Source Host: 10.0.0.5
Source Database: jnetdata
Target Host: 10.0.0.5
Target Database: jnetdata
Date: 5/26/2009 12:27:33 PM
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for chavrusas
-- ----------------------------
CREATE TABLE `chavrusas` (
`id` int(11) NOT NULL auto_increment,
`date_created` datetime default NULL,
`luser_id` int(11) default NULL,
`ruser_id` int(11) default NULL,
`luser_type` varchar(50) default NULL,
`ruser_type` varchar(50) default NULL,
`SessionDay` varchar(250) default NULL,
`SessionTime` datetime default NULL,
`WeeklyReminder` tinyint(1) NOT NULL default '0',
`reminder_phone` tinyint(1) NOT NULL default '0',
`calling_card` varchar(50) default NULL,
`active` tinyint(1) NOT NULL default '0',
`notes` mediumtext,
`ended` tinyint(1) NOT NULL default '0',
`end_date` datetime default NULL,
`initiated_by_student` tinyint(1) NOT NULL default '0',
`initiated_by_volunteer` tinyint(1) NOT NULL default '0',
`student_general_reason` varchar(50) default NULL,
`volunteer_general_reason` varchar(50) default NULL,
`student_reason` varchar(250) default NULL,
`volunteer_reason` varchar(250) default NULL,
`student_nli` tinyint(1) NOT NULL default '0',
`volunteer_nli` tinyint(1) NOT NULL default '0',
`jnet_initiated` tinyint(1) default '0',
`belongs_to` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5913 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for tbluseravailability
-- ----------------------------
CREATE TABLE `tbluseravailability` (
`availability_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`weekday_id` int(11) NOT NULL,
`timeslot_id` int(11) NOT NULL,
PRIMARY KEY (`availability_id`)
) ENGINE=MyISAM AUTO_INCREMENT=10865 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for tblusers
-- ----------------------------
CREATE TABLE `tblusers` (
`id` int(11) NOT NULL auto_increment,
`
etc
how do i run it on http://www.wampserver.com/en/download.php
see Executing SQL Statements from a Text File
Find the mysql.exe in your wamp installation, then run
mysql.exe -u username -p password database < textfile.sql
Presuming that WAMP means Windows, Apache, MySQL, Perl/Php, you would use the MySQL command line client to apply the SQL script.
The process is documented here: https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html
If Wampserver installs MySQL in the normal place, the mysql client will be found somewhere such as C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql .

running sql code with microsoft sql 2008

i have about 8mb of sql code i need to run. it looks like this:
/*
MySQL Data Transfer
Source Host: 10.0.0.5
Source Database: jnetdata
Target Host: 10.0.0.5
Target Database: jnetdata
Date: 5/26/2009 12:27:33 PM
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for chavrusas
-- ----------------------------
CREATE TABLE `chavrusas` (
`id` int(11) NOT NULL auto_increment,
`date_created` datetime default NULL,
`luser_id` int(11) default NULL,
`ruser_id` int(11) default NULL,
`luser_type` varchar(50) default NULL,
`ruser_type` varchar(50) default NULL,
`SessionDay` varchar(250) default NULL,
`SessionTime` datetime default NULL,
`WeeklyReminder` tinyint(1) NOT NULL default '0',
`reminder_phone` tinyint(1) NOT NULL default '0',
`calling_card` varchar(50) default NULL,
`active` tinyint(1) NOT NULL default '0',
`notes` mediumtext,
`ended` tinyint(1) NOT NULL default '0',
`end_date` datetime default NULL,
`initiated_by_student` tinyint(1) NOT NULL default '0',
`initiated_by_volunteer` tinyint(1) NOT NULL default '0',
`student_general_reason` varchar(50) default NULL,
`volunteer_general_reason` varchar(50) default NULL,
`student_reason` varchar(250) default NULL,
`volunteer_reason` varchar(250) default NULL,
`student_nli` tinyint(1) NOT NULL default '0',
`volunteer_nli` tinyint(1) NOT NULL default '0',
`jnet_initiated` tinyint(1) default '0',
`belongs_to` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5913 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for tbluseravailability
-- ----------------------------
CREATE TABLE `tbluseravailability` (
`availability_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`weekday_id` int(11) NOT NULL,
`timeslot_id` int(11) NOT NULL,
PRIMARY KEY (`availability_id`)
) ENGINE=MyISAM AUTO_INCREMENT=10865 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Table structure for tblusers
-- ----------------------------
CREATE TABLE `tblusers` (
`id` int(11) NOT NULL auto_increment,
`
etc
how do i run it on microsoft sql 2008?
You don't, you'd have to convert the code to use SQL Server's T-SQL syntax. You could use a conversion tool though, like this one.
Run a tool to automatically convert MySQL sentences to T-SQL,
Intensive use of Find&Replace can make the work too. As an example:
CREATE TABLE `chavrusas` (
`id` int(11) NOT NULL auto_increment,
`date_created` datetime default NULL,
`luser_id` int(11) default NULL,
`ruser_id` int(11) default NULL,
`luser_type` varchar(50) default NULL,
`ruser_type` varchar(50) default NULL,
`SessionDay` varchar(250) default NULL,
`SessionTime` datetime default NULL,
`WeeklyReminder` tinyint(1) NOT NULL default '0',
`reminder_phone` tinyint(1) NOT NULL default '0',
`calling_card` varchar(50) default NULL,
`active` tinyint(1) NOT NULL default '0',
`notes` mediumtext,
`ended` tinyint(1) NOT NULL default '0',
`end_date` datetime default NULL,
`initiated_by_student` tinyint(1) NOT NULL default '0',
`initiated_by_volunteer` tinyint(1) NOT NULL default '0',
`student_general_reason` varchar(50) default NULL,
`volunteer_general_reason` varchar(50) default NULL,
`student_reason` varchar(250) default NULL,
`volunteer_reason` varchar(250) default NULL,
`student_nli` tinyint(1) NOT NULL default '0',
`volunteer_nli` tinyint(1) NOT NULL default '0',
`jnet_initiated` tinyint(1) default '0',
`belongs_to` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5913 DEFAULT CHARSET=latin1;
Find: \s`
Replace with [
Find: `\s
Replace with: ]
Find: PRIMARY KEY (id)
Replace with: CONSTRAINT PK_[SOME IDENTIFIER] PRIMARY KEY ([$1])
Find: ENGINE=MyISAM AUTO_INCREMENT=5913 DEFAULT CHARSET=latin1;
Replace with: ;
a few more Find&Replace and you'll get this script, T-SQL compliant:
CREATE TABLE [chavrusas] (
[id] INT IDENTITY(1,1) NOT NULL ,
[date_created] datetime NULL,
[luser_id] INT NULL,
[ruser_id] INT NULL,
[luser_type] varchar(50) NULL,
[ruser_type] varchar(50) NULL,
[SessionDay] varchar(250) NULL,
[SessionTime] datetime NULL,
[WeeklyReminder] INT NOT NULL,
[reminder_phone] INT NOT NULL,
[calling_card] varchar(50) NULL,
[active] INT NOT NULL,
[notes] TEXT,
[ended] INT NOT NULL,
[end_date] datetime NULL,
[initiated_by_student] INT NOT NULL,
[initiated_by_volunteer] INT NOT NULL,
[student_general_reason] varchar(50) NULL,
[volunteer_general_reason] varchar(50) NULL,
[student_reason] varchar(250) NULL,
[volunteer_reason] varchar(250) NULL,
[student_nli] INT NOT NULL,
[vvolunteer_nli] INT NOT NULL,
[jnet_initiated] INT,
[belongs_to] varchar(50) NULL,
CONSTRAINT PK_chavrusas PRIMARY KEY ([id])
)
At a glance, the code snippet you provided looks acceptable for SQL Server. I would suggest using one of the many tools available for executing SQL against an existing SQL Server instance (SQL Server Management Studio, Query Analyzer, etc.). Paste the code into a new query window (or open up the associated file with the query) and parse it to see if you uncover any errors. Once you tweak the code to work with SQL Server 2008 (assuming that's necessary), you should just be able to execute it to create the tables and such.
EDIT: I tested your code against SQL Server 2005 and there were some problems that would be annoying like replacing ` with ', fixing table/column references surrounded by apostrophes, etc.. Automated tool would be your best approach given the prevelance of errors.