我无法运行此SQL脚本。
发生此错误:
消息102,级别15,状态1,行10 构造“=”附近的语法不正确。
消息102,级别15,状态1,行28 “".
”构造附近的语法不正确 消息102,级别15,状态1,行86 构造“`”附近的语法不正确。
Message 102, Level 15, State 1, Line 56
Incorrect syntax near the construction of "
我该怎么办?
-- phpMyAdmin SQL Dump
-- version 3.3.1
-- http://www.phpmyadmin.net
--
-- Хост: localhost
-- Время создания: Дек 29 2011 г., 16:23
-- Версия сервера: 5.5.10
-- Версия PHP: 5.2.4
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- База данных: `test`
--
-- --------------------------------------------------------
--
-- Структура таблицы `customers`
--
CREATE TABLE IF NOT EXISTS `customers` (
`ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'идентификатор записи',
`FIRST_NAME` varchar(30) COLLATE utf8_bin NOT NULL COMMENT 'Имя',
`LAST_NAME` varchar(30) COLLATE utf8_bin NOT NULL COMMENT 'Фамилия',
`PHONE` varchar(10) COLLATE utf8_bin NOT NULL COMMENT 'Телефон',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='заказчики' AUTO_INCREMENT=9 ;
--
-- Дамп данных таблицы `customers`
--
INSERT INTO `customers` (`ID`, `FIRST_NAME`, `LAST_NAME`, `PHONE`) VALUES
(1, 'Борис', 'Петров', ''),
(2, 'Иван', 'Сидоров', ''),
(3, 'Сергей', 'Иванов', ''),
(4, 'Александр', 'Бойко', ''),
(5, 'Петр', 'Борисов', ''),
(6, 'Семён', 'Александров', ''),
(7, 'Александр', 'Лебедев', ''),
(8, 'Алексей', 'Ильин', '');
-- --------------------------------------------------------
--
-- Структура таблицы `items`
--
CREATE TABLE IF NOT EXISTS `items` (
`ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'идентификатор записи',
`NAME` varchar(50) COLLATE utf8_bin NOT NULL COMMENT 'название товара',
`AMOUNT` float NOT NULL DEFAULT '0' COMMENT 'цена товара',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=12 ;
--
-- Дамп данных таблицы `items`
--
INSERT INTO `items` (`ID`, `NAME`, `AMOUNT`) VALUES
(1, 'Молоток', 0),
(2, 'Бумага', 0),
(3, 'Шоколадка Snickers', 0),
(4, 'Отвёртка', 0),
(5, 'Ручка', 0),
(6, 'Шоколадка Kit-Kat', 0),
(7, 'Гаечный ключ', 0),
(8, 'Карандаш', 0),
(9, 'Конфеты Helth Bar', 0),
(10, 'Счётчик ленты', 0),
(11, 'Переплётная машина', 0);
-- --------------------------------------------------------
--
-- Структура таблицы `payments`
--
CREATE TABLE IF NOT EXISTS `payments` (
`ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'идентификатор записи',
`CUSTOMER_ID` int(11) NOT NULL COMMENT 'ИД заказчика. Связь с таблицей customers',
`ITEM_ID` int(11) NOT NULL COMMENT 'ИД товара. Связь с таблицей items',
`ITEM_COUNT` int(11) NOT NULL DEFAULT '0' COMMENT 'количество товара',
`TRANS_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'время транзакции',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='продажи' AUTO_INCREMENT=21 ;
--
-- Дамп данных таблицы `payments`
--
INSERT INTO `payments` (`ID`, `CUSTOMER_ID`, `ITEM_ID`, `ITEM_COUNT`, `TRANS_TIME`) VALUES
(1, 1, 6, 0, '2011-12-29 14:49:06'),
(2, 1, 9, 0, '2011-12-29 14:49:06'),
(3, 2, 2, 0, '2011-12-29 14:52:09'),
(4, 2, 8, 0, '2011-12-29 14:52:09'),
(5, 3, 4, 0, '2011-12-29 14:52:09'),
(6, 3, 7, 0, '2011-12-29 14:52:09'),
(7, 3, 10, 0, '2011-12-29 14:52:09'),
(8, 4, 5, 0, '2011-12-29 14:52:09'),
(9, 4, 8, 0, '2011-12-29 14:52:09'),
(10, 4, 11, 0, '2011-12-29 14:52:09'),
(11, 5, 1, 0, '2011-12-29 14:52:09'),
(12, 5, 4, 0, '2011-12-29 14:52:09'),
(13, 5, 10, 0, '2011-12-29 14:52:35'),
(14, 6, 5, 0, '2011-12-29 14:52:35'),
(15, 6, 11, 0, '2011-12-29 14:52:55'),
(16, 7, 1, 0, '2011-12-29 14:52:55'),
(17, 7, 4, 0, '2011-12-29 14:53:12'),
(18, 8, 3, 0, '2011-12-29 14:53:12'),
(19, 8, 9, 0, '2011-12-29 14:53:22'),
(20, 2, 11, 0, '2011-12-29 16:03:55');
答案 0 :(得分:1)
您正在尝试在SQL Server数据库上运行MySQL脚本。在此之前,您需要进行许多更改。试试这个(我已将你的代码移植到TSQL):
CREATE PROCEDURE #AddDescription
(@table sysname, @column sysname, @description sysname)
AS
DECLARE @level2type sysname;
IF @column COLLATE database_default IS NOT NULL
SET @level2type = 'COLUMN'
EXEC sys.sp_addextendedproperty
'MS_Description', @description,
'SCHEMA', 'dbo',
'TABLE', @table,
@level2type, @column
GO
IF 'customers' NOT IN (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'dbo')
BEGIN
CREATE TABLE [customers]
(
[ID] int NOT NULL IDENTITY(9,1),
[FIRST_NAME] nvarchar(30) NOT NULL,
[LAST_NAME] nvarchar(30) NOT NULL,
[PHONE] nvarchar(10) NOT NULL,
PRIMARY KEY ([ID])
)
EXEC #AddDescription 'customers', NULL, N'заказчики'
EXEC #AddDescription 'customers', 'ID', N'идентификатор записи'
EXEC #AddDescription 'customers', 'FIRST_NAME', N'Имя'
EXEC #AddDescription 'customers', 'LAST_NAME', N'Фамилия'
EXEC #AddDescription 'customers', 'PHONE', N'Телефон'
END
SET IDENTITY_INSERT [customers] ON
INSERT INTO [customers] ([ID], [FIRST_NAME], [LAST_NAME], [PHONE]) SELECT
1, N'Борис', N'Петров', '' UNION ALL SELECT
2, N'Иван', N'Сидоров', '' UNION ALL SELECT
3, N'Сергей', N'Иванов', '' UNION ALL SELECT
4, N'Александр', N'Бойко', '' UNION ALL SELECT
5, N'Петр', N'Борисов', '' UNION ALL SELECT
6, N'Семён', N'Александров', '' UNION ALL SELECT
7, N'Александр', N'Лебедев', '' UNION ALL SELECT
8, N'Алексей', N'Ильин', '';
SET IDENTITY_INSERT [customers] OFF
DBCC CHECKIDENT('[customers]', RESEED) WITH NO_INFOMSGS
IF 'items' NOT IN (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'dbo')
BEGIN
CREATE TABLE [items]
(
[ID] int NOT NULL IDENTITY(12,1),
[NAME] nvarchar(50) NOT NULL,
[AMOUNT] float NOT NULL DEFAULT '0',
PRIMARY KEY ([ID])
)
EXEC #AddDescription 'items', 'ID', N'идентификатор записи'
EXEC #AddDescription 'items', 'NAME', N'название товара'
EXEC #AddDescription 'items', 'AMOUNT', N'цена товара'
END
SET IDENTITY_INSERT [items] ON
INSERT INTO [items] ([ID], [NAME], [AMOUNT]) SELECT
1, N'Молоток', 0 UNION ALL SELECT
2, N'Бумага', 0 UNION ALL SELECT
3, N'Шоколадка Snickers', 0 UNION ALL SELECT
4, N'Отвёртка', 0 UNION ALL SELECT
5, N'Ручка', 0 UNION ALL SELECT
6, N'Шоколадка Kit-Kat', 0 UNION ALL SELECT
7, N'Гаечный ключ', 0 UNION ALL SELECT
8, N'Карандаш', 0 UNION ALL SELECT
9, N'Конфеты Helth Bar', 0 UNION ALL SELECT
10, N'Счётчик ленты', 0 UNION ALL SELECT
11, N'Переплётная машина', 0;
SET IDENTITY_INSERT [items] OFF
DBCC CHECKIDENT('items', RESEED) WITH NO_INFOMSGS
IF 'payments' NOT IN (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'dbo')
BEGIN
CREATE TABLE [payments]
(
[ID] int NOT NULL IDENTITY(21,1),
[CUSTOMER_ID] int NOT NULL,
[ITEM_ID] int NOT NULL ,
[ITEM_COUNT] int NOT NULL DEFAULT '0',
[TRANS_TIME] datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ([ID])
)
EXEC #AddDescription 'payments', NULL, N'продажи'
EXEC #AddDescription 'payments', 'ID', N'идентификатор записи'
EXEC #AddDescription
'payments', 'CUSTOMER_ID', N'ИД заказчика. Связь с таблицей customers'
EXEC #AddDescription
'payments', 'ITEM_ID', N'ИД товара. Связь с таблицей items'
EXEC #AddDescription 'payments', 'ITEM_COUNT', N'количество товар'
EXEC #AddDescription 'payments', 'TRANS_TIME', N'время транзакции'
END
SET IDENTITY_INSERT [payments] ON
INSERT INTO [payments]
([ID], [CUSTOMER_ID], [ITEM_ID], [ITEM_COUNT], [TRANS_TIME]) SELECT
1, 1, 6, 0, '2011-12-29T14:49:06' UNION ALL SELECT
2, 1, 9, 0, '2011-12-29T14:49:06' UNION ALL SELECT
3, 2, 2, 0, '2011-12-29T14:52:09' UNION ALL SELECT
4, 2, 8, 0, '2011-12-29T14:52:09' UNION ALL SELECT
5, 3, 4, 0, '2011-12-29T14:52:09' UNION ALL SELECT
6, 3, 7, 0, '2011-12-29T14:52:09' UNION ALL SELECT
7, 3, 10, 0, '2011-12-29T14:52:09' UNION ALL SELECT
8, 4, 5, 0, '2011-12-29T14:52:09' UNION ALL SELECT
9, 4, 8, 0, '2011-12-29T14:52:09' UNION ALL SELECT
10, 4, 11, 0, '2011-12-29T14:52:09' UNION ALL SELECT
11, 5, 1, 0, '2011-12-29T14:52:09' UNION ALL SELECT
12, 5, 4, 0, '2011-12-29T14:52:09' UNION ALL SELECT
13, 5, 10, 0, '2011-12-29T14:52:35' UNION ALL SELECT
14, 6, 5, 0, '2011-12-29T14:52:35' UNION ALL SELECT
15, 6, 11, 0, '2011-12-29T14:52:55' UNION ALL SELECT
16, 7, 1, 0, '2011-12-29T14:52:55' UNION ALL SELECT
17, 7, 4, 0, '2011-12-29T14:53:12' UNION ALL SELECT
18, 8, 3, 0, '2011-12-29T14:53:12' UNION ALL SELECT
19, 8, 9, 0, '2011-12-29T14:53:22' UNION ALL SELECT
20, 2, 11, 0, '2011-12-29T16:03:55'
SET IDENTITY_INSERT [payments] OFF
DBCC CHECKIDENT('payments', RESEED) WITH NO_INFOMSGS
DROP PROCEDURE #AddDescription