T4JNE

Untitled

Dec 7th, 2021 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.46 KB | None | 0 0
  1. 1
  2. CREATE OR REPLACE VIEW GET_EMPLOYEES_BY_DEP AS
  3. SELECT e.*,d.department_name as DEP_NAME FROM employees e
  4. JOIN departments d ON e.department_id = d.department_id;
  5.  
  6. SELECT * FROM GET_EMPLOYEES_BY_DEP WHERE DEP_NAME = 'Marketing';
  7.  
  8. 2
  9. CREATE OR REPLACE VIEW INSERT_NEW_ROW_REGIONS AS
  10. SELECT region_id, region_name FROM regions;
  11.  
  12. INSERT INTO INSERT_NEW_ROW_REGIONS (region_id, region_name)
  13. VALUES(5, 'Antarctica');
  14.  
  15. 3
  16. SAVEPOINT ROWS_INSERTING;
  17.  
  18. CREATE SEQUENCE GET_UNIQUE_INDEX
  19. Minvalue 0
  20. Maxvalue 99999
  21. Start with 1
  22. Increment by 1;
  23.  
  24. DROP SEQUENCE GET_UNIQUE_INDEX;
  25.  
  26. CREATE OR REPLACE VIEW DUPLICATE_DATA_REGIONS AS
  27. SELECT (SELECT COUNT(*)FROM regions)
  28. AS ROW_COUNT, region_name AS RN FROM regions;
  29.  
  30. INSERT INTO regions
  31. SELECT (ROW_COUNT + GET_UNIQUE_INDEX.nextval),
  32. RN FROM DUPLICATE_DATA_REGIONS;
  33.  
  34. ROLLBACK TO ROWS_INSERTING;
  35.  
  36. 4.a
  37. CREATE OR REPLACE VIEW MANAGERS_DEPARTMENTS AS
  38. (SELECT e1.employee_id, e1.first_name, e1.last_name,
  39. d.department_name FROM employees e1 JOIN departments d
  40. ON (e1.department_id = d.department_id) WHERE e1.employee_id IN
  41. (SELECT DISTINCT e2.manager_id FROM employees e2));
  42.  
  43. 4.b
  44. CREATE OR REPLACE VIEW JOBS_WITH_EMPLOYEES AS
  45. (SELECT * FROM jobs WHERE job_id IN
  46. (SELECT DISTINCT job_id FROM employees));
  47.  
  48. 4.c
  49. CREATE OR REPLACE VIEW SH_CLERKS_BETWEEN_91_06 AS
  50. (SELECT  e.last_name, e.hire_date, e.job_id FROM employees e
  51. WHERE (e.hire_date >= TO_DATE('01.01.1991', 'DD.MM.YYYY')) AND
  52. (e.hire_date <= TO_DATE('01.01.2006', 'DD.MM.YYYY')) AND
  53. (e.job_id = 'SH_CLERK'));
  54.  
  55. 4.d
  56. CREATE OR REPLACE VIEW EMP_INCREASED_SALARIES AS
  57. (SELECT e.last_name, ROUND((e.salary + (e.salary / 100) * 20), 0)
  58. "Salary + 20%" FROM employees e);  
  59.  
  60. 4.e
  61. CREATE OR REPLACE VIEW MANAGERS_EMPLOYEES AS
  62. (SELECT manager_id, employee_id, first_name, last_name FROM employees)
  63. ORDER BY (manager_id);
  64.  
  65. 5
  66. CREATE SEQUENCE SEQ_FROM_1_TO_4000
  67. Minvalue 0
  68. Maxvalue 4000
  69. Start with 1
  70. Increment by 1;
  71.  
  72. 6
  73. CREATE SEQUENCE SEQ_FROM_4000_TO_1
  74. Minvalue 1
  75. Maxvalue 99995
  76. Start with 4000
  77. Increment by 5;
  78.  
  79. 7.a
  80. CREATE TABLE CITIES(
  81.     CITY_ID NUMBER,
  82.     CITY_NAME VARCHAR2(25 BYTE),
  83.     REGION_ID NUMBER,
  84. CONSTRAINT CITY_FK FOREIGN KEY (REGION_ID)
  85. REFERENCES REGIONS(REGION_ID)
  86. );
  87.  
  88. 7.b
  89. ALTER TABLE CITIES ADD
  90. CONSTRAINT CITY_PK PRIMARY KEY (CITY_ID);
  91.  
  92. 7.c
  93. ALTER TABLE CITIES ADD
  94. CONSTRAINT CITY_UK UNIQUE (CITY_NAME);
  95.  
  96. 7.d
  97. ALTER TABLE CITIES ADD
  98. (DISTRICT VARCHAR2(25 BYTE));
  99.  
  100. 7.e
  101. CREATE INDEX CITY_DISTRICT_INDEX ON CITIES (DISTRICT);
  102.  
Add Comment
Please, Sign In to add comment