-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.sql
106 lines (92 loc) · 1.43 KB
/
insert.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
SELECT
*
FROM
employees
ORDER BY emp_no DESC
LIMIT 10;
insert into employees
(
emp_no,
birth_date,
first_name,
last_name,
gender,
hire_date
) values
(
999901,
'1986-04-21',
'JOHN',
'Smith',
'M',
'2011-01-01'
);
insert into employees
(
birth_date,
emp_no,
first_name,
last_name,
gender,
hire_date
) values
(
'1973-03-26',
999902,
'Patricia',
'Lawrence',
'F',
'2005-01-01'
) ;
select * from titles
order by emp_no desc
limit 10;
insert into titles
(
emp_no,
title,
from_date
) values
(
999902,
'Senior Engineer',
'1997-10-01'
) ;
select * from dept_emp
order by emp_no desc
limit 10 ;
insert into dept_emp values ( 999903, 'd005', '1997-01-01', '9999-01-01' ) ;
SELECT
*
FROM
departments;
CREATE TABLE departments_dup (
dept_no CHAR(4) NOT NULL,
dept_name VARCHAR(40) NOT NULL
);
/*
INSERT DATA INTO A NEW TABLE :
INSERT INTO table_2 ( col1, col2, ...coln)
SELECT col1, col2, ....coln
FROM table_1
WHERE condition ;
*/
-- example
select * from departments_dup ; #created a new table to duplicate departments table
INSERT INTO departments_dup
(
dept_no,
dept_name
)
SELECT * # * as we are copy all columns from departments
FROM departments ;
-- exercise
select * from departments ;
insert into departments (
dept_no,
dept_name
) values
(
'd010',
'Business Analysis'
)