2010-07-07 61 views
-1

可能重复:
Incorrect syntax near insert有语法错误

出于某种原因,我不能让填充表。它以前工作过,但我不知道为什么现在不运行。

CREATE DATABASE Mort; 
Go 


USE Mort; 
----------------------------------- 
/* 
**This script creates the 
** Employee table with the foreign key 
*/ 
----------------------------------- 

---------------------------------------------------- 
/* I chose Job_title as the PRIMARY KEY. 
**All rows must be unique. There is a Job_title 
**column in the Employee table that can be used as a 
**foreign key. 
*/ 
/* 
**This script creates the 
** Job title table 
*/ 
---------------------------------------------------- 
CREATE TABLE 
Job_title 
(Job_title varchar (50) PRIMARY KEY, 
EEO_1_Classification varchar(200), 
Job_description varchar(250), 
Exempt_Non_Exempt_Status bit); 
Go 

CREATE TABLE 
Employee 
(Emp_id int NOT NULL IDENTITY(1,1)PRIMARY KEY, 
Last_name varchar(25),  
First_name varchar(25), 
Address varchar(40),   
City varchar (15), 
State char(2), 
Telephone_area_code varchar(3),  
Telephone_number varchar(8),   
Job_title varchar(50) foreign key references job_title(job_title), 
Hire_date smalldatetime,  
Wage money, 
Gender char(1), 
Race varchar(25), 
Age int); 
----------------------------------------------------------------------------------------------------- 
/* (3.1) This script inserts employee records 
** for both the administrative offices 
** and the Del Mar location 
*/ 
------------------------------------------------------------------------------------------------- 

USE Mort; 
Go 


INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('McNamara', 
'Juanita', 
'923 Parkway', 
'La Jolla', 
'CA', 
'619', 
'555-0208', 
'Accounting Clerk', 
'10/07/2003', 
'$12.75', 
'F', 
'Hispanic', 
32); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Stephens', 
'Harvey', 
'7863 High Bluff Drive', 
'La Jolla', 
'CA', 
'619', 
'555-0123', 
'Dir. of Fin. 
& Acct.', 
'3/1/1998', 
'$75,000.00', 
'M', 
'Caucasian', 
51); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage,  
Gender,  
Race,   
Age) 

VALUES 
('Vu', 
'Matthew', 
'981 Torrey Pines Road', 
'La Jolla', 
'CA', 
'619', 
'555-0138', 
'Computer Support Specialist', 
'8/16/2000', 
'$18.50', 
'M', 
'Asian', 
26); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Nguyen', 
'Meredith', 
'10583 Arenas ST. ', 
'La Jolla ', 
'CA', 
'619', 
'555-0102', 
'Computer Support Specialist ', 
'9/27/1998 ', 
'$21.50 ', 
'M', 
'Caucasian', 
25); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Avery', 
'Ledonna', 
'198 Governor Dr.', 
'Del Mar', 
'CA', 
'619', 
'555-0135', 
'Asst. - Bakery & Pastry', 
'3/28/2003', 
'$10.50', 
'F', 
'African American', 
23); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Drohos', 
'Craig', 
' ', 
'Selano Beach', 
'CA', 
'619', 
'555-0202', 
'Assistant Manager', 
'6/15/2000', 
'$51,000.00 ', 
'M', 
'Caucasian', 
32); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Meier', 
'Elaine', 
'9703 Orchid Lane', 
'Del Mar', 
'CA', 
'858', 
'555-0112', 
'Cashier', 
'9/10/2000', 
'$10.25', 
'F', 
'Asian', 
51); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Quillian', 
'Stanley', 
'98542 Wandering Road Apt 2-B', 
'Del Mar', 
'CA', 
'760', 
'555-0198', 
'Asst. - Butchers & Seafood Specialists', 
'12/16/1999', 
'$11.50 ', 
'M', 
'American Indian', 
29); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Tyink', 
'Thomas', 
'87592 Pacific Heights Blvd.', 
'Del Mar', 
'CA', 
'858', 
'555-0159', 
'Asst. - Bakery & Pastry', 
'5/1/2001', 
'$9.50', 
'M', 
'African American', 
32); 

INSERT INTO 
Employee 

(Last_name, 
First_name, 
Address, 
City, 
State, 
Telephone_area_code, 
Telephone_number, 
Job_title, 
Hire_date, 
Wage, 
Gender, 
Race, 
Age) 

VALUES 
('Vance', 
'Brent', 
'927 Cynthia Lane Parkway', 
'Del Mar', 
'CA', 
'858', 
'555-0147', 
'Bagger - 30 hours/wk', 
'3/29/2001', 
'$6.75', 
'M', 
'Caucasian', 
22); 


------------------------------------------------------ 
/* This script inserts values into Job_title table 
** Note: 1 means exempt (salaried) 
** 0 means non-exempt (hourly) 
** Section (2.2) 
*/ 
------------------------------------------------------ 



INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Accounting Clerk', 'Office/Clerical', 
'Computes, classifies, records, and verifies numerical data for use in maintaining 
accounting records.', 
0); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Assistant Manager', 'Officials & Managers', 
'Supervises and coordinates activities of workers in department of food store. 
Assists store manager in daily operations of store.' , 
1); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Bagger','Sales Workers', 
'Places customer orders in bags. Performs carryout duties for customers.', 
0); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Cashier','Sales Workers', 
'Operates cash register to itemize and total customer’s purchases in grocery 
store.', 
0); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Computer Support Specialist','Technician', 
'Installs, modifies, and makes minor repairs to personal computer hardware and 
software systems, and provides technical assistance and training to system 
users.', 
0); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Dir. of Fin. & Acct.','Officials & Managers', 
'Plans and directs the finance and accounting activities for Kudler Fine Foods.', 
1); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Asst. - Bakery & Pastry','Craft Workers (Skilled)', 
'Obtains or prepares food items requested by customers in retail food store.', 
0); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Asst. - Butchers & Seafood Specialists','Operatives (Semi skilled)', 
'Obtains or prepares food items requested by customers in retail food store.', 
0); 

INSERT INTO Job_title 
(Job_title, EEO_1_Classification, Job_description, Exempt_Non_Exempt_Status) 
VALUES 
('Stocker','Office/Clerical', 
'Stores, prices and restocks merchandise displays in store.', 
0) 





------------------------------------------------------------------------------------------ 
/* 
**(3.2) This script Checks the results by selecting 
**all of the columns from both of the tables 
**Select * from 
**Select * from 
*/ 
/* 
**Format of Employee table due to requirement 
**Do not “string out” an entire query/statement so 
**that it requires the viewer to horizontally scroll to read it. 
*/ 
------------------------------------------------------------------------------------------- 




USE Mort; 

Select Emp_id, Last_name, First_name, Address, City, State from Employee 
Go 

Select Telephone_area_code, Telephone_number, Job_title, Hire_date, Wage, Gender, Race, Age from Employee 
Go 

Select * from Job_title 
Go 

/* 
**(3.3) Write a SQL query that joins two tables in the example database and uses BETWEEN **to restrict record selection. (Use salary to restrict the data.) 
*/ 


Select Employee.Wage, Job_title.Job_title 
From Employee 
inner join Job_title 
on Employee.Wage=Job_title.Job_title 
order by Employee.Last_name 

(3.4)编写加入示例数据库中的两个表和使用之间来限制记录选择一个SQL查询。 (使用可用日期来限制数据。) (3.5)编写一个连接示例数据库中两个表的SQL查询,并使用LIKE限制记录选择。 (使用电话区号限制数据。) (3.6)编写一个连接示例数据库中两个表的SQL查询,并使用LIKE限制记录选择。 (使用年龄查找20岁以上的所有人。) (3.7)编写一个使用两个表的UNION的SQL查询。有创意。

(3.8)编写一个SQL查询,显示按job_title分组的平均工资/小时工资。 (3.9)编写一个SQL查询,显示每个EE0-1分类中的人数以及每个分类的平均工资/小时工资。 (3.10)通过EEO分类对员工进行分组:按照EEO-1分类选择员工姓氏并将其分组 (3.11)按员工的EEO分类将员工分组:按照员工的薪水EEO-1分类。 (3.12)选择员工的姓氏,并将其按薪水分组,分为豁免和非豁免。

+4

一个VALUES部分。另外,如果这是作业,请标记为这样。最后,你是否收到错误?那是什么错误? – 2010-07-07 19:37:03

+1

插入错误,它会告诉你一些具体的错误,可能导致你的插入命令有问题...一些文本试图插入或什么。 – Leslie 2010-07-07 19:42:52

回答

0

如果格式化你的问题好一点,切出任何无关的文本,那么你可能有反应更好的运气,你不必为INSERT的之一(第6 INSERT)