Jump to content

Question On Writing SQL Statement


HTHVampire

Recommended Posts

From the tables that I attached, a. Assume Job relation is created. Write the SQL statement that will create the EMP relation (use the structure shown in Table 2) Following is my answer:

Create Table EMP (empnum NUMBER(3), lname VARCHAR2(15) CONSTRAINT emp_lname_nn Not Null, fname VARCHAR2(25), mi CHAR(1), hiredate DATE CONSTRAINT emp_hiredate_nn Not Null, enddate DATE, Jobcode CHAR(3), Salary Number(10,2) CONSTRAINT emp_empnum_pk Primary Key (empnum), CONSTRAINT emp_jobcode_fk Foreign Key (jobcode) REFERENCES Job(job_code); 

b. Write the SQL statement that will enter the first data row into the EMP relation

 

My answer:

Insert into EMP values (101, 'O''Connel', 'John', 'mi', '11-Aug-2000', NULL, '502', 3600) 

For both of this questions, can someone checks with me whether am I doing it correctly? Please point out my mistakes if any, I appreciate your guides.Thank you!

post-172318-0-71526000-1398573635_thumb.jpg

Link to comment
Share on other sites

Is this for MySQL? I haven't seen CONSTRAINT used when setting a field as not allowing null values. Maybe you're using something other than MySQL though. Your insert query is fine, although you missed one of the values.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...