Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Junction table data insertion

$
0
0

CREATE DATABASE ABC_ORG

 USE ABC_ORG


CREATE TABLE EMPLOYEE
(
E_ID numeric(10) NOT NULL,
E_Name varchar(20) NOT NULL,
E_City varchar(10),
E_Designayion varchar(20) NOT NULL

CONSTRAINT PK_Emp PRIMARY KEY(E_ID)
)

CREATE TABLE SKILLS
(
  S_ID numeric(10) NOT NULL,
  S_Name varchar(20) NOT NULL,

  CONSTRAINT PK_SKILL PRIMARY KEY(S_ID)
)

CREATE TABLE EMP_SKILL
(

 E_ID NUMERIC(10)foreign key references EMPLOYEE(E_ID) NOT NULL,
 S_ID NUMERIC(10) foreign key references SKILLS (S_ID),

 CONSTRAINT PK_EMP_SKILL PRIMARY KEY(E_ID, S_ID),


 )

 INSERT INTO EMPLOYEE VALUES(1,'ali', 'Lahore','Manager') 
 INSERT INTO EMPLOYEE VALUES(2,'Zoahir','Islamabad','Manager') 
 INSERT INTO EMPLOYEE VALUES(3,'Arusa','Lahore','QA') 
 INSERT INTO EMPLOYEE VALUES(4,'Rehab','Lahore','Analyst') 
 INSERT INTO EMPLOYEE VALUES(5,'ali','Karachi','Manager') 

 INSERT INTO SKILLS VALUES (1,'B.A')
 INSERT INTO SKILLS VALUES (2,'MBA')
 INSERT INTO SKILLS VALUES (4,'BBA')
 INSERT INTO SKILLS VALUES (5,'CA')
 INSERT INTO SKILLS VALUES (6,'SQA')


 INSERT INTO EMP_SKILL(E_ID,S_ID) VALUES (1,1)

below two lines are giving error. I am trying to inert data in the tables. This is first time I am trying to insert data in such junction table. Is that any better way to do so. Please help me. help me in this problem and also a good resource to learn it step by step.

          INSERT INTO EMP_SKILL(E_ID,S_ID) VALUES (1,3)
          INSERT INTO EMP_SKILL(E_ID,S_ID) VALUES (1,6)

 

Asia


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>