2014-04-06 166 views
0

我試圖從phpMyAdmin來SQL服務器導入我的數據庫,但得到的時候我試圖執行SQL代碼來創建此錯誤:導入數據庫MS SQL Server的

Msg 156, Level 15, State 1, Line 10 
Incorrect syntax near the keyword 'IF'. 
Msg 102, Level 15, State 1, Line 10 
Incorrect syntax near 'nih_bw'. 
Msg 911, Level 16, State 1, Line 11 
Database 'nih_bw' does not exist. Make sure that the name is entered correctly. 

這是數據庫:

SET time_zone = "+00:00"; 


/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */; 
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */; 
/*!40101 SET @[email protected]@COLLATION_CONNECTION */; 
/*!40101 SET NAMES utf8 */; 

-- 
-- Database: "nih_bw" 
-- 
CREATE DATABASE IF NOT EXISTS "nih_bw" DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; 
USE nih_bw; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "emps" 
-- 

CREATE TABLE "emps" (
    "id" int NOT NULL, 
    "user_name" varchar(25) NOT NULL, 
    "first_name" varchar(15) NOT NULL, 
    "last_name" varchar(15) NOT NULL, 
    "email" varchar(25) NOT NULL, 
    "password" varchar(25) NOT NULL, 
    "user_type" char(5) NOT NULL, 
    PRIMARY KEY ("id") 
); 

-- 
-- Dumping data for table "emps" 
-- 

SET IDENTITY_INSERT "emps" ON ; 
INSERT INTO "emps" ("id", "user_name", "first_name", "last_name", "email", "password", "user_type") VALUES 
(1, 'root', 'root', 'root', '[email protected]', 'hei123', 'user'); 

SET IDENTITY_INSERT "emps" OFF; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "measurements" 
-- 

CREATE TABLE "measurements" (
    "id" int NOT NULL, 
    "title" varchar(25) NOT NULL, 
    PRIMARY KEY ("id") 
); 

-- 
-- Dumping data for table "measurements" 
-- 

SET IDENTITY_INSERT "measurements" ON ; 
INSERT INTO "measurements" ("id", "title") VALUES 
(1, 'T_Badende_per_Time'), 
(2, 'T_Temperatur'), 
(3, 'T_Luft_Temperatur'), 
(4, 'M_Fritt_Klor'), 
(5, 'M_Bundet_Klor'), 
(6, 'M_Total_Klor'), 
(7, 'M_PH'), 
(8, 'M_Auto_Klor'), 
(9, 'M_Auto_PH'), 
(10, 'M_Redox'), 
(11, 'O_Vannbalanse'), 
(12, 'O_Alakalitet'), 
(13, 'O_Hardhet'), 
(14, 'O_Natrium_Bk'), 
(15, 'O_Kals_Klor'), 
(16, 'O_Sjokklor'), 
(17, 'O_Fellingsmiddel'), 
(18, 'O_Sirkulasjonsmengde'), 
(19, 'O_Filtertrykk'), 
(20, 'O_Spyl_Av_Filter'), 
(21, 'O_Vannforbruk'), 
(22, 'O_Slamsuging'), 
(23, 'O_Harsil'), 
(24, 'O_Ren_Utj_Tank'); 

SET IDENTITY_INSERT "measurements" OFF; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "measure_routine" 
-- 

CREATE TABLE "measure_routine" (
    "routine_id" int NOT NULL, 
    "measure_id" int NOT NULL, 
    "pool_id" int DEFAULT NULL, 
    PRIMARY KEY ("routine_id","measure_id"), 
    KEY "pool_id" ("pool_id"), 
    KEY "link3" ("measure_id") 
); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "pools" 
-- 

CREATE TABLE "pools" (
    "id" int NOT NULL, 
    "name" varchar(20) NOT NULL, 
    PRIMARY KEY ("id") 
); 

-- 
-- Dumping data for table "pools" 
-- 

SET IDENTITY_INSERT "pools" ON ; 
INSERT INTO "pools" ("id", "name") VALUES 
(1, 'Hovedbasseng'), 
(2, 'Plaskebasseng'), 
(99, 'Svommehall'); 

SET IDENTITY_INSERT "pools" OFF; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "routines" 
-- 

CREATE TABLE "routines" (
    "id" int NOT NULL, 
    "date" datetime NOT NULL, 
    "time" time NOT NULL, 
    "value" varchar(10) NOT NULL, 
    "emp_id" int NOT NULL, 
    PRIMARY KEY ("id"), 
    KEY "emp_id" ("emp_id") 
); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "tasks" 
-- 

CREATE TABLE "tasks" (
    "id" int NOT NULL, 
    "title" varchar(25) NOT NULL, 
    PRIMARY KEY ("id") 
); 

-- 
-- Dumping data for table "tasks" 
-- 

SET IDENTITY_INSERT "tasks" ON ; 
INSERT INTO "tasks" ("id", "title") VALUES 
(40, 'D_Slamsuge_Pl_Bass'), 
(41, 'D_Filter_Rens'), 
(42, 'D_Bypass_Pl_Bass'), 
(43, 'D_Vaske_Gulv_CM'), 
(44, 'D_Garderobe_0730'), 
(45, 'D_Garderobe_Dag'), 
(46, 'D_Male_Temp_Just'), 
(47, 'D_Vaske_Pl_Bass'), 
(48, 'D_Vaske_H_Bass'), 
(49, 'D_Renhold_Av_Wc'), 
(50, 'D_Ettersyn_Utst_Skap'), 
(51, 'D_Handicap_Heis'), 
(52, 'D_Ettersyn_solarier'), 
(53, 'D_Vannprove_0745'), 
(54, 'D_Vannprover_1100'), 
(55, 'D_Vannprover_1400'), 
(56, 'D_Enkle_Vedliks_Oppg'), 
(57, 'D_Sjekk_Skiftplan'), 
(58, 'K_Oppdatere_Seg_IkkeUtf'), 
(59, 'K_Vannprover_1700'), 
(60, 'K_Vannprover_2000'), 
(61, 'K_Vaske_Pl_Bass'), 
(62, 'K_Vaske_H_Bass'), 
(63, 'K_Sla_Av_Bypass'), 
(64, 'K_Ettersyn_Materiell'), 
(65, 'K_Ettersyn_Solarier'), 
(66, 'K_Ettersyn_Sal_4'), 
(67, 'K_Runde_Gard_Kveld'), 
(68, 'K_Runde_Gard_For_Steng'), 
(69, 'K_Enkle_Vedlik_Oppg'), 
(70, 'K_Rullestolheis_lading'), 
(71, 'K_Etterfylle_Skoposer'), 
(72, 'K_Skap_Lases'), 
(73, 'K_Sjekk_Skiftplan'), 
(74, 'K_Rydd_Tribune'), 
(75, 'K_Slamsug_H_Bass'), 
(76, 'K_Stenge_Prosedyre'), 
(77, 'K_Beskjed_H_Vakt'), 
(78, 'K_Timeteller'), 
(79, 'C_Timeteller'), 
(80, 'C_AllRent'), 
(81, 'C_Grovrent_Ekstra'), 
(82, 'C_Ren_Opplos_Tank'), 
(83, 'C_Ren_Opps_Tank'), 
(84, 'C_Ren_Flott_gitter'), 
(85, 'C_Ren_Opplos_Filter'), 
(86, 'C_Ren_Nal'), 
(87, 'C_Kontr_Slang_Tank'), 
(88, 'C_Kont_Ren_KostPad'); 

SET IDENTITY_INSERT "tasks" OFF; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table "task_routine" 
-- 

CREATE TABLE "task_routine" (
    "routine_id" int NOT NULL, 
    "task_id" int NOT NULL, 
    PRIMARY KEY ("routine_id","task_id"), 
    KEY "link6" ("task_id") 
); 

-- 
-- Constraints for dumped tables 
-- 

-- 
-- Constraints for table "measure_routine" 
-- 
ALTER TABLE "measure_routine" 
    ADD CONSTRAINT "link2" FOREIGN KEY ("routine_id") REFERENCES "routines" ("id") ON DELETE CASCADE ON UPDATE CASCADE, 
    ADD CONSTRAINT "link3" FOREIGN KEY ("measure_id") REFERENCES "measurements" ("id") ON DELETE CASCADE ON UPDATE CASCADE; 

-- 
-- Constraints for table "routines" 
-- 
ALTER TABLE "routines" 
    ADD CONSTRAINT "link1" FOREIGN KEY ("emp_id") REFERENCES "emps" ("id") ON DELETE CASCADE ON UPDATE CASCADE; 

-- 
-- Constraints for table "task_routine" 
-- 
ALTER TABLE "task_routine" 
    ADD CONSTRAINT "link5" FOREIGN KEY ("routine_id") REFERENCES "routines" ("id") ON DELETE CASCADE ON UPDATE CASCADE, 
    ADD CONSTRAINT "link6" FOREIGN KEY ("task_id") REFERENCES "tasks" ("id") ON DELETE CASCADE ON UPDATE CASCADE; 

/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */; 
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */; 
/*!40101 SET [email protected]_COLLATION_CONNECTION */; 
+0

好的,讓我澄清一點。 YOu導出了一個MySql數據庫並認爲它會奇蹟般地導入到SQL Server中?你曾經想過,每一個sql語言都不一樣。壞消息:是的。可悲的是。 YOu將不得不清理你生成的SQL。用手。或者使用其他工具來生成腳本。 – TomTom

+0

是的,我通過選擇數據庫系統或較舊的MySQL服務器,從sql中導出phpmyadmin,以最大化與選項中的mssql的輸出兼容性。 – user3185936

+0

如果它應該創建一個SQL Server兼容的腳本,它似乎失敗了。 '如果不存在,創建數據庫nih_bw'將不起作用,所以你不會得到一個數據庫。 –

回答

0

我認爲你需要看看你的第一個聲明,你要創建一個數據庫,東西開始你的腳本如下

USE master; 
GO 

IF DB_ID('dbname') IS NOT NULL 
    DROP DATABASE nih_bw 
GO 

CREATE DATABASE [nih_bw] ON PRIMARY 
(NAME = N'nih_bw' 
, FILENAME = N'C:\Path_mdf_File\nih_bw.mdf' , SIZE = 5120000KB , FILEGROWTH = 1024KB) 
LOG ON 
(NAME = N'nih_bw_log' 
    , FILENAME = N'D:\Path_For_ldf_File\nih_bw_log.ldf' , SIZE = 512000KB , FILEGROWTH = 10%) 
COLLATE SQL_SwedishStd_Pref_CP1_CI_AS 
GO 


USE [nih_bw] 
GO 


/* Now from here continue with rest of your script */ 
相關問題