-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.sql
More file actions
112 lines (92 loc) · 1.81 KB
/
key.sql
File metadata and controls
112 lines (92 loc) · 1.81 KB
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
106
107
108
109
110
111
112
-- Create the table in the specified schema
CREATE TABLE home_cats
(
cat_id INT NOT NULL,
name VARCHAR (100),
age INT,
PRIMARY KEY
(cat_id)
);
INSERT INTO home_cats
( -- columns to insert data into
cat_id, name, age
)
VALUES
(
1, 'blue', 2
),
(
2, 'Kash', 3
);
-- but if we try to add data, with the same id (whichis pk)
INSERT INTO home_cats
(
cat_id, name, age
)
VALUES
(
1, 'Fred', 5
);
-- GET ERROR: Duplicate entry '1' for key 'PRIMARY'
-- !AUTO_INCREMENT
/* CREATE TABLE outside_cats
(
cat_id INT NOT NULL
AUTO_INCREMENT,
name VARCHAR
(100),
age INT,
PRIMARY KEY
(cat_id)
); */
INSERT INTO outside_cats
(
name, age
)
VALUES
(
'Fred', 5
),
('Jef', 3);
-- Problem:
/*
Define an Employee table, with the following fileds:
- id : number (automatically increments) primarykey,
- last_name : text, mandatory
- first_name : text, mandatory
- middle_name : text, not mandatory,
- age : number, mandatory,
- current_status : text, mandatory, default to 'employeed'
*/
/*
CREATE TABLE employee_prac
(
eid INT NOT NULL AUTO_INCREMENT,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
middle_name VARCHAR(50) NULL,
age INT NOT NULL,
current_status VARCHAR(20) NOT NULL DEFAULT 'employeed',
PRIMARY KEY (eid)
);
*/
INSERT INTO employee_prac
(
first_name, middle_name, last_name, age
)
VALUES
(
'Tejas', 'Shailesh', 'Sabunkar', 25
);
-- !Another Solution
/*
CREATE TABLE employee_prac
(
eid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
middle_name VARCHAR(50) NULL,
age INT NOT NULL,
current_status VARCHAR(20) NOT NULL DEFAULT 'employeed'
);
*/