Saturday, January 17, 2015

SQL basics - (How to insert data to a table) - (For absolute beginners) - Tutorial 8

Option 1 

CREATE TABLE emp
(
  emp_id NUMBER(2) CONSTRAINT emp_col1_pk PRIMARY KEY,
  emp_name  VARCHAR2(20),
  emp_salary NUMBER(5)
);


INSERT INTO "HR"."EMP" VALUES('1','Achala','1500');
INSERT INTO "HR"."EMP" VALUES('2','ach','1000');
INSERT INTO "HR"."EMP" VALUES('3','Tendulkar','20000');
INSERT INTO "HR"."EMP" VALUES('4','Jayasuriya','2000');


Option 2 

CREATE TABLE dept
(
  dept_id NUMBER(2) CONSTRAINT dept_coll_pk PRIMARY KEY,
  dept_name VARCHAR(20),
  emp_id CONSTRAINT dept_col3_fk REFERENCES emp(emp_id)
);

INSERT INTO "HR"."DEPT" (DEPT_ID,DEPT_NAME,EMP_ID) VALUES('1','Sports','1');
INSERT INTO "HR"."DEPT"(DEPT_ID,DEPT_NAME,EMP_ID) VALUES('2','Accounts','2');
INSERT INTO "HR"."DEPT" (DEPT_ID,DEPT_NAME,EMP_ID)VALUES('3','Sales','3');
INSERT INTO "HR"."DEPT" (DEPT_ID,DEPT_NAME) VALUES('4','Marketing');
INSERT INTO "HR"."DEPT" (DEPT_ID,DEPT_NAME) VALUES('5','Finance');

No comments:

Post a Comment

Using Zotero for academic writing