插入附近的语法不正确

时间:2010-07-07 19:34:44

标签: sql sql-server

  

可能重复:
  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查询,该查询连接示例数据库中的两个表,并使用BETWEEN来限制记录选择。 (使用雇用日期来限制数据。) (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)选择员工的姓氏,并按工资分类中的工资分组,分为免税和非免税。

1 个答案:

答案 0 :(得分:0)

其中一个INSERT(第6个INSERT)没有VALUES部分