-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice8.sql
41 lines (34 loc) · 996 Bytes
/
practice8.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
CREATE DATABASE g_f_g;
USE g_f_g;
-- Create the 'employees' table
CREATE TABLE geeksforgeeks(
geeks_id INT PRIMARY KEY,
geeks_name VARCHAR(50),
geeks_salary INT
);
-- Insert or update operation using MySQL syntax
INSERT INTO geeksforgeeks(geeks_id, geeks_name, geeks_salary)
VALUES (1, 'Sourabh Sahu', 50000)
ON DUPLICATE KEY UPDATE
geeks_id = VALUES(geeks_name),
geeks_salary = VALUES(geeks_salary);
-- Display the 'employees' table after upsert
SELECT * FROM geeksforgeeks;
DROP TABLE geeksforgeeks;
-- Create the table
CREATE TABLE IF NOT EXISTS geeksforgeeks (
id INT PRIMARY KEY,
column1 VARCHAR(255),
column2 VARCHAR(255)
);
-- Insert initial data
INSERT INTO geeksforgeeks (id, column1, column2)
VALUES (1, 'initial_value1', 'initial_value2');
-- Upsert operation
INSERT INTO geeksforgeeks (id, column1, column2)
VALUES (1, 'Geek1', 'Geek2')
ON DUPLICATE KEY UPDATE
column1 = 'Geek1',
column2 = 'Geek2';
-- Display the data
SELECT * FROM geeksforgeeks;