Advertisement
brandblox

Assignemnt 1

Oct 6th, 2023 (edited)
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.71 KB | None | 0 0
  1. CREATE TABLE EMP (
  2.     empid NUMBER PRIMARY KEY,
  3.     name VARCHAR2(50),
  4.     date_of_birth DATE,
  5.     city VARCHAR2(50),
  6.     salary NUMBER
  7. );
  8.  
  9. -- Inserting Input 1
  10. INSERT INTO EMP (empid, name, date_of_birth, city, salary)
  11. VALUES (101, 'John Smith', TO_DATE('1990-05-15', 'YYYY-MM-DD'), 'New York', 60000);
  12.  
  13. -- Inserting Input 2
  14. INSERT INTO EMP (empid, name, date_of_birth, city, salary)
  15. VALUES (102, 'Alice Johnson', TO_DATE('1985-11-28', 'YYYY-MM-DD'), 'Los Angeles', 75000);
  16.  
  17. -- Inserting Input 3
  18. INSERT INTO EMP (empid, name, date_of_birth, city, salary)
  19. VALUES (103, 'Michael Davis', TO_DATE('1988-07-10', 'YYYY-MM-DD'), 'Chicago', 55000);
  20.  
  21.  
  22. -- Create table
  23. CREATE TABLE EMP_Constraint1 (
  24.     id VARCHAR2(10) PRIMARY KEY,
  25.     name VARCHAR2(50),
  26.     city VARCHAR2(20) CHECK (city IN ('kolkata', 'delhi', 'mumbai')),
  27.     sal NUMBER(5, 0) CHECK (sal >= 10000 AND sal <= 99999),
  28.     comm NUMBER(4, 0) CHECK (comm >= 0 AND comm <= 9999),
  29.     dob DATE,
  30.     designation VARCHAR2(50) CHECK (designation = LOWER(designation)),
  31.     dependence NUMBER DEFAULT 1,
  32.     CONSTRAINT name_unique UNIQUE (name)
  33. );
  34.  
  35. -- Insert data
  36. INSERT ALL
  37.     INTO EMP_Constraint (id, name, city, sal, comm, dob, designation, dependence)
  38.     VALUES ('A102', 'John', 'kolkata', 15000, 500, TO_DATE('1999-05-20', 'YYYY-MM-DD'), 'clerk', 1)
  39.    
  40.     INTO EMP_Constraint (id, name, city, sal, comm, dob, designation, dependence)
  41.     VALUES ('A103', 'Alice', 'mumbai', 28000, 200, TO_DATE('1995-09-12', 'YYYY-MM-DD'), 'manager', 2)
  42.    
  43.     INTO EMP_Constraint (id, name, city, sal, comm, dob, designation, dependence)
  44.     VALUES ('A104', 'Bob', 'delhi', 21000, 0, TO_DATE('1998-03-05', 'YYYY-MM-DD'), 'analyst', 3)
  45.    
  46. SELECT 1 FROM DUAL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement