question

vio avatar image
vio asked

sql code+insert values

Create Table Employee( Emp_NINO VARCHAR (13) NOT NULL, Emp_FName CHARACTER (10) NOT NULL, Emp_LName CHARACTER (10)NOT NULL, Emp_Gender CHARACTER(10) NOT NULL, Emp_Address VARCHAR (36) NOT NULL, Emp_Manager VARCHAR (13) , Job_Type CHARACTER (10) NOT NULL, Emp_MonthlySalary NUMERIC (5) NOT NULL, Machine_Num NUMERIC(8) NOT NULL, Dept_Num NUMERIC(8) NOT NULL, Dept_Name CHARACTER (8) NOT NULL, -- This indicates which attribute(s) uniquely identify each row of data. CONSTRAINT pk_Employee PRIMARY KEY (Emp_NINO));

Insert Into Employee Values (‘SJ 58 82 40 D’,’Jonson’,’Luigi’,’Male’,’23 Denmark Hill’,London,SE14 8PT’,’AC 68 32 10 G’,’Operator’,’600’,’16899’,’12468’,’ ESPRIMO’);

Insert Into Employee Values (‘KI 47 60 41 F’,’Maria’,Popa’,’Female’,’15 Lewisham Way,London,SE12 4NT’,’AC 68 32 10 G’,’Maintenance’,’1296’,’23778’, ‘12469’, ’CENTRINO’);

Insert Into Employee Values (‘DL 48 12 20 H’,’Emanuel’,’Gheorghe’,’Male’,’21 Amersham Road,London,W34 6DR’,’AC 68 32 10 G’,’Designer’,’2184’,’30657’, ‘12470’, ‘WINDOWS’);

Insert Into Employee Values (‘AC 68 32 10 G’,’Alice’,’Ciubotariu’,’Female’,’20 A Shardeloes Road,London,WE1 24RE’,’’,’Manager’,’2400’,’37536’, ‘12471’,’COMPASS’);

Insert Into Employee Values (‘WE 15 79 60 O’,’Mary’,’Rades’,’Female’,’12 New Cross Road,London,S24 6TU’,’AC 68 32 10 G’,’Designer’,’2772’,’44415’, ‘12472’,’SHELL’);

hi,i would kindly ask if anyone would know why my code only inserts the last 3 rows and not the first two.it gives me an error:01756 .it inserts the last three rows successfully,but not the first two,even if they are all the same format.Thx a lot!!!!!!

sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jason Cumberland avatar image
Jason Cumberland answered

There are a lot of things wrong with these statements.

  • Extra single quote at "23 Denmark Hill'" in the first statement
  • Missing single quote at "Popa'" in the second statement
  • Did not include a column list in the INSERT clause
  • The first insert statement has a mismatch of columns to insert into and values to insert from due to the missing single quotes
  • The second insert statement has a string value that is too big to insert into the column for the table, job_type column is ( varchar (10)) not big enough for the string value "Maintenance" (11 characters)

Cleaned up script so you won't fail your homework assignment, you are welcome.

drop table Employee            
go            
            
Create Table Employee (            
    Emp_NINO VARCHAR (13) NOT NULL            
    ,Emp_FName CHARACTER (10) NOT NULL            
    ,Emp_LName CHARACTER (10)NOT NULL            
    ,Emp_Gender CHARACTER(10) NOT NULL            
    ,Emp_Address VARCHAR (36) NOT NULL            
    ,Emp_Manager VARCHAR (13)            
    ,Job_Type CHARACTER (11) NOT NULL            
    ,Emp_MonthlySalary NUMERIC (5) NOT NULL            
    ,Machine_Num NUMERIC(8) NOT NULL            
    ,Dept_Num NUMERIC(8) NOT NULL            
    ,Dept_Name CHARACTER (8) NOT NULL, -- This indicates which attribute(s) uniquely identify each row of data.            
    CONSTRAINT pk_Employee PRIMARY KEY (Emp_NINO)            
);            
go            
            
Insert Into Employee ( Emp_NINO, Emp_FName, Emp_LName, Emp_Gender, Emp_Address, Emp_Manager, Job_Type, Emp_MonthlySalary, Machine_Num, Dept_Num, Dept_Name )            
Values ('SJ 58 82 40 D','Jonson','Luigi','Male','23 Denmark Hill,London,SE14 8PT','AC 68 32 10 G','Operator','600','16899','12468',' ESPRIMO');            
go            
            
Insert Into Employee ( Emp_NINO, Emp_FName, Emp_LName, Emp_Gender, Emp_Address, Emp_Manager, Job_Type, Emp_MonthlySalary, Machine_Num, Dept_Num, Dept_Name )            
Values ('KI 47 60 41 F','Maria','Popa','Female','15 Lewisham Way,London,SE12 4NT','AC 68 32 10 G','Maintenance','1296','23778', '12469', 'CENTRINO');            
go            
            
Insert Into Employee ( Emp_NINO, Emp_FName, Emp_LName, Emp_Gender, Emp_Address, Emp_Manager, Job_Type, Emp_MonthlySalary, Machine_Num, Dept_Num, Dept_Name )            
Values ('DL 48 12 20 H','Emanuel','Gheorghe','Male','21 Amersham Road,London,W34 6DR','AC 68 32 10 G','Designer','2184','30657', '12470', 'WINDOWS');            
go            
            
Insert Into Employee ( Emp_NINO, Emp_FName, Emp_LName, Emp_Gender, Emp_Address, Emp_Manager, Job_Type, Emp_MonthlySalary, Machine_Num, Dept_Num, Dept_Name )            
Values ('AC 68 32 10 G','Alice','Ciubotariu','Female','20 A Shardeloes Road,London,WE1 24RE','','Manager','2400','37536', '12471','COMPASS');            
go            
            
Insert Into Employee ( Emp_NINO, Emp_FName, Emp_LName, Emp_Gender, Emp_Address, Emp_Manager, Job_Type, Emp_MonthlySalary, Machine_Num, Dept_Num, Dept_Name )            
Values ('WE 15 79 60 O','Mary','Rades','Female','12 New Cross Road,London,S24 6TU','AC 68 32 10 G','Designer','2772','44415', '12472','SHELL');            
go            
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.