Information Systems for Engineers Fall Data Definition with SQL

Size: px
Start display at page:

Download "Information Systems for Engineers Fall Data Definition with SQL"

Transcription

1 Ghislain Fourny Information Systems for Engineers Fall Data Definition with SQL Rare Book and Manuscript Library, Columbia University.

2 What does data look like? Relations 2

3 Reminder: relation 0 to many A B 3

4 Reminder: partial function 0 to 1 A B 4

5 Reminder: function exactly 1 A B 5

6 Reminder: the two alternate definitions Definition 1: A table is a relation over its attribute domains. Extension + Domain + a 0 Domain + a 3 Definition 2: A table is a set of partial functions mapping strings to values, and with identical support. Extension + S V s.t. t Extension +, support t = Attributes + 6

7 The two alternate definitions Definition 1: A table is a relation over its attribute domains. Extension + Domain + a 0 Domain + a 3 (Domain integrity is always satisfied by definition) Definition 2: A table is a set of partial functions mapping strings to values, and with identical support. (Domain integrity is defined separately) Extension + S V s.t. t Extension +, support t = Attributes + 7

8 The two alternate definitions Definition 1: A table is a relation over its attribute domains. Extension + Domain + a 0 Domain + a 3 Very popular in database books, but imprecise regarding attribute (non-)order Definition 2: A table is a set of partial functions mapping strings to values, and with identical support. Extension + S V s.t. t Extension +, support t = Attributes + More rigorous, and pedagogically nice to separate definition from domain integrity 8

9 Reminder: definition with partial functions A relation R is made of 1. Attributes Attributes + Attributes + S 9

10 Reminder: definition with partial functions A relation R is made of 1. Attributes Attributes + Attributes + S 2. An extension (set of tuples) Extension + Extension + S V such that: t Extension +, support t = Attributes + 10

11 Domain integrity Given a relation R and a domain constraint Domain + Domain integrity is fulfilled if Attributes + Domain + Extension + a d t Extension +, a Attributes + In other words: t. a Domain + (a) Tuples must have their values in the domains associated with their attributes. t t.a d 11

12 Reminder: definition with relations A relation R is made of Schema +, Domain +, Extension + as follows: Attributes + 1. a set of schema attributes, ordered for convenience (arbitrarily) a 0, a L,..., a 3 12

13 Reminder: definition with relations A relation R is made of Schema +, Domain +, Extension + as follows: 1. a set of schema attributes, ordered for convenience (arbitrarily) Attributes + Domain + a 0, a L,..., a 3 2. a family of domains associated with these attributes (the types) a Domain + (a) 13

14 Reminder: definition with relations A relation R is made of Schema +, Domain +, Extension + as follows: 1. a set of schema attributes, ordered for convenience (arbitrarily) a 0, a L,..., a 3 Attributes + Domain + Extension + 2. a family of domains associated with these attributes (the types) a Domain + (a) 3. a set of tuples (the extension) Extension + Domain + a 0 Domain + a 3 Domain integrity holds by definition. Instead of partial function 14

15 In practice Customer ID Security ID Quantity Integer String Integer 1 CH CH CH CH CH CH This is how database people think. 15

16 SELECT name, mayor WHERE country = "Switzerland" FROM cities SQL 16

17 SQL History Don Chamberlin Raymond Boyce 17

18 The early days (early 1970s) First commercial relational database System R + SEQUEL First commercial relational query language Almaden (San Jose) First customer (1977) 18

19 SEQUEL Structured English QUEry Language Declarative language Set-based (Manipulates entire relations with a single command) 19

20 Renaming SEQUEL (Trademark issue) SQL ESS-kew-EL or SEE-kwəl 20

21 Domain types 21

22 Data types Customer ID Security ID Quantity Integer String Integer 1 CH CH CH CH CH CH

23 Kinds of domains 23

24 Kinds of domains Strings Booleans Numbers Date & Time Enumeration Binary Duration 24

25 Strings "foo" "Zurich" "Ilsebill salzte nach." 25

26 Strings "foo" "Zurich" "Ilsebill salzte nach." f o o Z u r i c h I l s e b i l l s a l z t e n a c h. 26

27 Strings Fixed length 27

28 Strings Fixed length Example: Swiss cantons ZH AG ZG GE BE NE AI AR... 28

29 Strings Fixed length Variable length with limit 29

30 Strings Fixed length Variable length with limit Example: international licence plate country code F D GB CH EIR 30

31 Strings Fixed length Variable length with limit Variable length without limit 31

32 Strings Fixed length Variable length with limit Variable length without limit Example: the content of a webpage on a blog 32

33 Strings Fixed length character(10) Variable length with limit Variable length without limit 33

34 Strings Fixed length character(10) char(10) char Variable length with limit Variable length without limit 34

35 Strings Fixed length Variable length with limit character(10) char(10) char character varying(10) Variable length without limit 35

36 Strings Fixed length Variable length with limit character(10) char(10) char character varying(10) varchar(10) Variable length without limit 36

37 Strings Fixed length Variable length with limit Variable length without limit character(10) char(10) char character varying(10) varchar(10) clob 37

38 Strings Fixed length Variable length with limit Variable length without limit character(10) char(10) char character varying(10) varchar(10) clob text Non-standard varchar Non-standard 38

39 String types: Behavior A B C char(3) varchar(5) text 39

40 String types: Behavior A B C char(3) varchar(5) text 40

41 String types: Behavior f A B C char(3) varchar(5) text 41

42 String types: Behavior f A B C char(3) varchar(5) text f f f 42

43 String types: Behavior f foo A B C char(3) varchar(5) text f f f 43

44 String types: Behavior f foo A B C char(3) varchar(5) text f f f foo foo foo 44

45 String types: Behavior f foo foobar A B C char(3) varchar(5) text f f f foo foo foo 45

46 String types: Behavior f foo foobar A B C char(3) varchar(5) text f f f foo foo foo foobar 46

47 String types: Behavior f foo foobar fo A B C char(3) varchar(5) text f f f foo foo foo foobar 47

48 String types: Behavior f foo foobar fo A B C char(3) varchar(5) text f f f foo foo foo foobar fo fo fo 48

49 String types: Design choices text is not standard Favor varchar(n) char(n) eats up space 49

50 Numbers: Integer types 50

51 Numbers: Integer types Mathematically: Z (A ring with addition and multiplication) 51

52 Lexical space vs. value space Value space Lexical space 52

53 Lexical space vs. value space "1" "01"... Value space Lexical space 53

54 Lexical space vs. value space "4" "04" "100b"... Value space Lexical space 54

55 If you program in Java... 55

56 If you program in Java... byte short int long 56

57 If you program in Java... byte short int long 8 bits 16 bits 32 bits 64 bits 57

58 Numbers: Integer types Small integers to (16 bits) 58

59 Numbers: Integer types Small integers to Integers to (16 bits) (32 bits) 59

60 Numbers: Integer types Small integers to Integers to Big Integers to (16 bits) (32 bits) (64 bits) 60

61 Numbers: Integer types Small integers to Integers to Big Integers to smallint integer int bigint 61

62 Binary numeral system Decimal Binary

63 Binary numeral system 3S0 number = O d Q. 2 Q QTU = d 3S0 d L d 0 d U Decimal Binary

64 Numbers: Arbitrary precision

65 Numbers: Arbitrary precision Precision 32 digits 65

66 Numbers: Arbitrary precision Scale 22 digits 66

67 Numbers: Arbitrary precision types Any precision and scale numeric decimal

68 Numbers: Arbitrary precision types Any precision and scale Limit precision, any scale numeric decimal numeric(32) decimal(32) 68

69 Numbers: Arbitrary precision types Any precision and scale Limit precision, any scale numeric decimal numeric(32) decimal(32) Example: disk capacity

70 Numbers: Arbitrary precision types Any precision and scale Limit precision, any scale Limit precision and scale numeric decimal numeric(32) decimal(32) numeric(32,22) decimal(32,22) 70

71 Numbers: Arbitrary precision types Any precision and scale Limit precision, any scale numeric decimal numeric(32) decimal(32) Limit precision and scale Example: amount of money numeric(32,22) decimal(32,22) 71

72 Arbirary precision types: Behavior 0 A B C numeric numeric(3) numeric(3,1) 72

73 Arbirary precision types: Behavior 0 A B C numeric numeric(3) numeric(3,1)

74 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

75 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

76 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

77 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

78 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

79 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

80 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

81 Arbirary precision types: Behavior A B C numeric numeric(3) numeric(3,1)

82 Numbers: Approximate (finite) precision

83 Numbers: Approximate (finite) precision Base 2, canonical x

84 Numbers: Approximate (finite) precision Base 2, canonical x 2 31 Encoding

85 Numbers: Approximate (finite) precision Base 2, canonical x 2 31 Encoding Read back

86 IEEE 754 standard 32 bits ca. 7 digits to single precision 86

87 IEEE 754 standard 32 bits 64 bits ca. 7 digits ca. 15 digits to to single precision double precision 87

88 IEEE 754 types Single precision real float(24) Double precision Arbitrary precision 88

89 IEEE 754 types Single precision real float(24) Double precision double precision float(53) Arbitrary precision 89

90 IEEE 754 types Single precision real float(24) Double precision double precision float(53) Arbitrary precision float(1)... float(24) float(25)... float(53) real double precision Non-standard 90

91 IEEE 754: special values - '-Infinity' 91

92 IEEE 754: special values - + '-Infinity' 'Infinity' 92

93 IEEE 754: special values - + NaN '-Infinity' 'Infinity' 'Nan'! Behavior differs from IEEE754: Equal to itself Higher than all other numbers 93

94 Booleans 94

95 Booleans TRUE FALSE 95

96 Booleans TRUE FALSE t true y yes Non-standard f false n no Non-standard on off

97 Booleans: three-valued logics? TRUE FALSE NULL t true y yes on Non-standard f false n no off Non-standard

98 Boolean type Boolean boolean 98

99 Dates and times Date 99

100 Dates and times Date Time 100

101 Dates and times Date Time Timestamp 101

102 Dates (Gregorian calendar) 102

103 Dates (Gregorian calendar) Year + Month + Day 2017 August 1st (AD) 103

104 Times 104

105 Times Hours + Minutes + Seconds 10 : 31 : Up to the µs (6 decimals) 105

106 Timestamps 106

107 Timestamps Year + Month + Day + Hours + Minutes + Seconds 2017 August 1 st 10 : 31 : (AD) 107

108 Dates and times: types Dates date 108

109 Dates and times: types Dates Times No time zone date time time(3) time without time zone time(5) without time zone 109

110 Dates and times: types Dates Times No time zone With time zone! [usage discouraged] date time time(3) time without time zone time(5) without time zone time with time zone time(1) with time zone 110

111 Dates and times: types Dates Times Timestamps No time zone! [usage discouraged] With time zone No time zone date time time(3) time without time zone time(5) without time zone time with time zone time(1) with time zone timestamp timestamp(6) timestamp without time zone timestamp(4) without time zone 111

112 Dates and times: types Dates Times Timestamps No time zone! [usage discouraged] With time zone No time zone With time zone date time time(3) time without time zone time(5) without time zone time with time zone time(1) with time zone timestamp timestamp(6) timestamp without time zone timestamp(4) without time zone timestamp with time zone timestamp(0) with time zone112

113 Durations 113

114 Duration kinds Year Month Day Hour Minute Second 114

115 Duration kinds Year Month Day Hour Minute Second Example: 2 years and 4 months 115

116 Duration kinds Year Month Day Hour Minute Second Example: 2 years and 4 months 116

117 Duration kinds Year Month Day Hour Minute Second Example: 2 years and 4 months Example: 3 hours and 14 minutes 117

118 Duration kinds Year Month Day Hour Minute Second Example: 2 years and 4 months Example: 3 hours and 14 minutes 118

119 "Duration wall": why not month to days? 2 months and 4 days 119

120 "Duration wall": why not month to days? 2 months and 4 days 2 months and 30 days 2 months and 31 days 3 months Ambiguity zone!! 120

121 Durations: types interval interval(3) Durations 121

122 Durations: types Durations interval interval(3) interval year interval year to month interval month (0) interval day (6) interval day to hour interval day to minute (2) interval day to second interval hour interval hour to minute (5) interval hour to second interval minute interval minute to second (4) interval second 122

123 Binaries

124 Binary content 124

125 Binary content: types Fixed length binary(10) 125

126 Binary content: types Fixed length Variable length with limit binary(10) varbinary(100) 126

127 Binary content: types Fixed length Variable length with limit binary(10) varbinary(100) Variable length without limit blob bytea Non-standard 127

128 Summary of standardized SQL types Kind Types Character char(p) varchar(p) clob 128

129 Summary of standardized SQL types Kind Types Character Binary char(p) varchar(p) clob binary(p) varbinary(p) blob 129

130 Summary of standardized SQL types Kind Types Character Binary Number, exact char(p) varchar(p) clob binary(p) varbinary(p) blob numeric(p,s) decimal(p,s) smallint integer(p) bigint 130

131 Summary of standardized SQL types Kind Types Character Binary Number, exact Number, approximate char(p) varchar(p) clob binary(p) varbinary(p) blob numeric(p,s) decimal(p,s) smallint integer(p) bigint float(p) real double precision 131

132 Summary of standardized SQL types Kind Types Character Binary Number, exact Number, approximate Boolean char(p) varchar(p) clob binary(p) varbinary(p) blob numeric(p,s) decimal(p,s) smallint integer(p) bigint float(p) real double precision boolean 132

133 Summary of standardized SQL types Kind Types Character Binary Number, exact Number, approximate Boolean Date and time char(p) varchar(p) clob binary(p) varbinary(p) blob numeric(p,s) decimal(p,s) smallint integer(p) bigint float(p) real double precision boolean date time time with time zone timestamp timestamp with time zone 133

134 Summary of standardized SQL types Kind Types Character Binary Number, exact Number, approximate Boolean Date and time Intervals char(p) varchar(p) clob binary(p) varbinary(p) blob numeric(p,s) decimal(p,s) smallint integer(p) bigint float(p) real double precision boolean date time time with time zone timestamp timestamp with time zone interval year to month interval day to second 134

135 Creating and dropping tables Vitaly Korovin / 123RF Stock Photo 135

136 DDL on tables + Create a table 136

137 DDL on tables + Create a table * Modify a table 137

138 DDL on tables + Create a table * Modify a table - Drop a table 138

139 Relations (the math, for database scientists) A relation R is made of 1. Attributes Attributes + Attributes + S 2. An extension (set of tuples) Extension + Extension + S V such that: t Extension +, attributes t = Attributes + 139

140 Domain integrity Given a relation R and a domain constraint Domain + Domain integrity is fulfilled if Attributes + Domain + Extension + a d t Extension +, a Attributes + In other words: t. a Domain + (a) Tuples must have their values in the domains associated with their attributes. t t.a d 140

141 Creating a table 141

142 Creating a table + A new table has an empty extension 142

143 Creating a table + So we only specify: - a name - the attributes - the associated domains 143

144 Creating a table: hello, world! CREATE TABLE helloworldtable ( name text ); 144

145 Creating a table: hello, world! CREATE TABLE helloworldtable ( name text ); helloworldtable name text 145

146 Creating a table: more columns CREATE TABLE persons ( first_name varchar(30), middle_initial char(1), last_name text, birth_date date, gender boolean, passportscan bytea ); 146

147 Creating a table: more columns CREATE TABLE persons ( first_name varchar(30), middle_initial char(1), last_name text, birth_date date, gender boolean, passportscan bytea ); persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea 147

148 Table with no columns CREATE TABLE emptytable (); (because we can?) important for the theory 148

149 Table with no columns (yes) CREATE TABLE emptytable (); (because we can?) important for the theory emptytable 149

150 Dropping a table - We only specify: - the name 150

151 Dropping a table: hello, world! DROP TABLE helloworldtable; helloworldtable name text 151

152 Dropping a table: hello, world! DROP TABLE helloworldtable; helloworldtable name text 152

153 Dropping a non-existing table: error DROP TABLE tablethatdoesntexist; 153

154 Dropping a non-existing table: error DROP TABLE tablethatdoesntexist; 154

155 Silently avoiding errors upon dropping a table DROP TABLE tablethatmayormaynotexist IF EXISTS; 155

156 Populating tables Inserting and deleting tuples Vitaly Korovin / 123RF Stock Photo 156

157 DML on tuples Insert a tuple + 157

158 DML on tuples Insert a tuple + Update a tuple * 158

159 DML on tuples Insert a tuple + Update a tuple * Delete a tuple - 159

160 Inserting tuples helloworldtable name text INSERT INTO helloworldtable VALUES Einstein; 160

161 Inserting tuples helloworldtable name text INSERT INTO helloworldtable VALUES Einstein; helloworldtable name text Einstein 161

162 Inserting tuples: explicit version helloworldtable name text Einstein INSERT INTO helloworldtable (name) VALUES Gödel; 162

163 Inserting tuples: explicit version helloworldtable name text Einstein INSERT INTO helloworldtable (name) VALUES Gödel; helloworldtable name text Einstein Gödel 163

164 Inserting tuples: multiple rows persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea INSERT INTO persons VALUES ('James', 'T', 'Kirk', DATE ' ', TRUE, E'\\xAD10E7'), ('Beverly', 'C', 'Crusher', DATE ' ', FALSE, E'\\xAD234F7') ; 164

165 Inserting tuples: multiple rows persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea INSERT INTO persons VALUES ('James', 'T', 'Kirk', DATE ' ', TRUE, E'\\xAD10E7'), ('Beverly', 'C', 'Crusher', DATE ' ', FALSE, E'\\xAD234F7') ; persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 165

166 Inserting tuples: omitting columns and NULL persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 INSERT INTO persons (name, birth_date, gender, passport_scan) VALUES ('Spock', DATE ' ', TRUE, E'\\xAD234F7') ; 166

167 Inserting tuples: omitting columns and NULL persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 INSERT INTO persons (name, birth_date, gender, passport_scan) VALUES ('Spock', DATE ' ', TRUE, E'\\xAD234F7') ; persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 Spock NULL NULL TRUE AD234F7 167

168 NULL By default, domains all contain an additional value NULL 168

169 NULL: interpretations? Not known 169

170 NULL: interpretations? Not known Not applicable 170

171 NULL: interpretations? Not known Not applicable Secret 171

172 Allowing (or not) NULL in a domain CREATE TABLE persons ( first_name varchar(30), middle_initial char(1), last_name text, birth_date date, gender boolean, passportscan bytea ); 172

173 Allowing (or not) NULL in a domain not allowed CREATE TABLE persons ( first_name varchar(30) NOT NULL, middle_initial char(1), last_name text, birth_date date, gender boolean, passportscan bytea ); 173

174 Allowing (or not) NULL in a domain not allowed CREATE TABLE persons ( first_name varchar(30) NOT NULL, middle_initial char(1) NULL, last_name text, birth_date date, allowed (default) gender boolean, passportscan bytea ); 174

175 NULL: best practice CREATE TABLE persons ( first_name varchar(30) NOT NULL, middle_initial char(1) NULL, last_name text NULL, birth_date date NOT NULL, gender boolean NOT NULL, passportscan bytea NOT NULL ); Mark as many columns as possible as not null. 175

176 Updating tuples persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 Spock NULL NULL TRUE AD234F7 UPDATE persons SET last_name = 'Picard' WHERE last_name = 'Crusher'; 176

177 Updating tuples persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 Spock NULL NULL TRUE AD234F7 UPDATE persons SET last_name = 'Picard' WHERE last_name = 'Crusher'; persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Picard FALSE AD234F7 Spock NULL NULL TRUE AD234F7 177

178 Removing tuples persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Picard FALSE AD234F7 Spock NULL NULL TRUE AD234F7 DELETE FROM persons WHERE name = 'Spock'; 178

179 Removing tuples persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Picard FALSE AD234F7 Spock NULL NULL TRUE AD234F7 DELETE FROM persons WHERE name = 'Spock'; persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Picard FALSE AD234F7 179

180 Default values CREATE TABLE persons ( first_name varchar(30), middle_initial char(1), last_name text, birth_date date, gender boolean, passportscan bytea ); 180

181 Default values CREATE TABLE persons ( first_name varchar(30), middle_initial char(1) DEFAULT 'N', last_name text DEFAULT 'NONE', birth_date date, gender boolean, passportscan bytea ); 181

182 Default values: inserting tuples persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 INSERT INTO persons (name, birth_date, gender, passport_scan) VALUES ('Spock', DATE ' ', TRUE, E'\\xAD234F7') ; 182

183 Default values: inserting tuples persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 INSERT INTO persons (name, birth_date, gender, passport_scan) VALUES ('Spock', DATE ' ', TRUE, E'\\xAD234F7') ; persons name middle_initial last_name birth_date gender passport_scan varchar(30) char(1) text date boolean bytea James T Kirk TRUE AD10E7 Beverly C Crusher FALSE AD234F7 Spock N NONE TRUE AD234F7 183

184 "Default default values": NULL CREATE TABLE persons ( first_name varchar(30) DEFAULT NULL, middle_initial char(1) DEFAULT 'N', last_name text DEFAULT 'NONE', birth_date date DEFAULT NULL, gender boolean DEFAULT NULL, passportscan bytea DEFAULT NULL ); 184

185 Modify tables Milosh Kojadinovich / 123RF Stock Photo 185

186 DDL on tables + Create a table 186

187 DDL on tables + Create a table * Modify a table 187

188 DDL on tables + Create a table * Modify a table - Drop a table 188

189 Add a column ALTER TABLE helloworldtable ADD COLUMN flag boolean; helloworldtable name text 189

190 Add a column ALTER TABLE helloworldtable ADD COLUMN flag boolean; helloworldtable name text helloworldtable name flag text boolean 190

191 Add a column: default values, null ALTER TABLE helloworldtable ADD COLUMN flag2 boolean not null default true; helloworldtable name flag text boolean 191

192 Add a column: default values, null ALTER TABLE helloworldtable ADD COLUMN flag2 boolean not null default true; helloworldtable name flag text boolean helloworldtable name flag flag2 text boolean boolean 192

193 Rename a column ALTER TABLE helloworldtable RENAME COLUMN flag TO f; helloworldtable name flag text boolean 193

194 Rename a column ALTER TABLE helloworldtable RENAME COLUMN flag TO f; helloworldtable name flag text boolean helloworldtable name f text boolean 194

195 Remove a column ALTER TABLE helloworldtable DROP COLUMN f; helloworldtable name f text boolean 195

196 Remove a column ALTER TABLE helloworldtable DROP COLUMN f; helloworldtable name f text boolean helloworldtable name text 196

197 Rename a table ALTER TABLE helloworldtable RENAME TO table; helloworldtable name text 197

198 Rename a table ALTER TABLE helloworldtable RENAME TO table; helloworldtable name text table name text 198

199 Consistency constraints Milosh Kojadinovich / 123RF Stock Photo 199

200 Consistency constraints There are three fundamental consistency constraints: Not null Check Unique 200

201 Not null (already covered) CREATE TABLE persons ( name text NOT NULL, student boolean ); 201

202 Not null (already covered) not allowed CREATE TABLE persons ( name text NOT NULL, student boolean ); allowed (default) 202

203 Not null (already covered) not allowed CREATE TABLE persons ( name text NOT NULL, student boolean ); allowed (default) persons name text foobar NULL student boolean NULL TRUE 203

204 Check CREATE TABLE persons ( name text check (foo <> 'Spock'), student boolean ); 204

205 Check CREATE TABLE persons ( name text check (foo <> 'Spock'), student boolean ); persons name text foobar Spock student boolean NULL TRUE 205

206 Unique CREATE TABLE persons ( name text UNIQUE, student boolean, ahv varchar(13) UNIQUE, ); 206

207 Unique CREATE TABLE persons ( name text UNIQUE, student boolean, ahv varchar(13) UNIQUE, ); persons name student ahv text boolean varchar(13) foobar NULL Spock TRUE Spock TRUE

208 Primary keys Sergey Nivens / 123RF Stock Photo 208

209 Primary key persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing 209

210 Primary key persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing A primary key uniquely identifies a row 210

211 Primary key persons ahv varchar(13) name text Albert Einstein Kurt Gödel NULL Alan Turing Can't be NULL 211

212 Primary keys persons ahv varchar(13) name text Albert Einstein Kurt Gödel NULL Alan Turing Must be unique 212

213 Primary key: first idea CREATE TABLE persons ( ahv varchar(13) UNIQUE NOT NULL, name text ); 213

214 Primary key: first idea CREATE TABLE persons ( ahv varchar(13) UNIQUE NOT NULL, name text ); persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing 214

215 Primary key: there is more to it persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing Niklaus Wirth Isaac Newton Srinivasa Ramanujan Pythagoras Thales Alonso Church 215

216 Primary key: there is more to it persons ahv varchar(13) name text Albert Einstein Kurt Gödel We want to quickly retrieve a row with its key Alan Turing Niklaus Wirth Isaac Newton Srinivasa Ramanujan Pythagoras Thales Alonso Church (We won't say how just yet) 216

217 Primary key: syntax CREATE TABLE persons ( ahv varchar(13) PRIMARY KEY, name text ); persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing 217

218 Primary key: alternate syntax CREATE TABLE persons ( ahv varchar(13), name text, PRIMARY KEY(ahv) ); persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing 218

219 Primary key: compound keys CREATE TABLE persons ( first text, last text, city text, PRIMARY KEY(first, last) ); 219

220 Primary key: compound keys CREATE TABLE persons ( first text, last text, city text, PRIMARY KEY(first, last) ); persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Kurt Turing London 220

221 Foreign key taxes ahv varchar(13) fiscal residence char(2) CH AT GB 221

222 Foreign key taxes ahv varchar(13) fiscal residence char(2) CH AT GB persons ahv varchar(13) name text Albert Einstein Kurt Gödel Alan Turing 222

223 Foreign key taxes ahv varchar(13) fiscal residence char(2) CH AT GB CREATE TABLE taxes ( ahv varchar(13) REFERENCES persons (ahv), fiscal residence char(2) ); Can be any column (not necessary primary key, but must be UNIQUE) 223

224 Foreign key: no column specified means primary key taxes ahv varchar(13) fiscal residence char(2) CH AT GB CREATE TABLE persons ( ahv varchar(13) REFERENCES persons, fiscal residence char(2) ); 224

225 Foreign key: duplicate references allowed taxes ahv varchar(13) fiscal residence char(2) CH AT GB US CREATE TABLE persons ( ahv varchar(13) REFERENCES persons, fiscal residence char(2) ); 225

226 Foreign key: compound keys persons first last city text text text taxes first last course text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London Albert Einstein Relativity Kurt Gödel Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas 226

227 Foreign key: compound keys persons first last city text text text taxes first last course text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London Albert Einstein Relativity Kurt Gödel Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas CREATE TABLE persons ( first text, last text, course text, FOREIGN KEY (first, last) REFERENCES persons (first, last) ); 227

228 Foreign key: NULL references are allowed persons first last city text text text taxes first last course text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London Albert Einstein Relativity Kurt Gödel Completeness Srinivasa Ramanujan Taxi numbers NULL NULL Formulas CREATE TABLE persons ( first text, last text, course text, FOREIGN KEY (first, last) REFERENCES persons (first, last) ); 228

229 Deletion of referenced values persons first last city text text text DELETE Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London 229

230 Deletion of referenced values persons first last city text text text DELETE Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London taxes first last course text text text Albert Einstein Relativity Kurt Gödel Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas What do we do here? 230

231 Deletion: cascading FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE CASCADE persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London 231

232 Deletion: cascading FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE CASCADE persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London taxes first last course text text text Albert Einstein Relativity Kurt Gödel Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas 232

233 Deletion: restricting FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE RESTRICT persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London 233

234 Deletion: restricting FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE RESTRICT "I'm sorry, Dave. I'm afraid I can't do that." persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London taxes first last course text text text Albert Einstein Relativity Kurt Gödel Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas 234

235 Deletion: set to NULL FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE SET NULL persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London 235

236 Deletion: set to NULL FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE SET NULL persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London taxes first last course text text text Albert Einstein Relativity NULL NULL Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas 236

237 Deletion: set to default value FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE SET DEFAULT persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London 237

238 Deletion: set to default value FOREIGN KEY (first, last) REFERENCES persons (first, last) ON DELETE SET DEFAULT persons first last city text text text Albert Einstein Zurich Kurt Gödel Berlin Srinivasa Ramanujan London taxes first last course text text text Albert Einstein Relativity Albert Einstein Completeness Srinivasa Ramanujan Taxi numbers Srinivasa Ramanujan Formulas 238

Ghislain Fourny. Information Systems for Engineers Fall Outlook

Ghislain Fourny. Information Systems for Engineers Fall Outlook Ghislain Fourny Information Systems for Engineers Fall 2018 11. Outlook What we learned Database System Database Management System (DBMS) Database system (Database + Database Management System) Database

More information

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language Information Systems Engineering SQL Structured Query Language DDL Data Definition (sub)language 1 SQL Standard Language for the Definition, Querying and Manipulation of Relational Databases on DBMSs Its

More information

Ghislain Fourny. Big Data 2. Lessons learnt from the past

Ghislain Fourny. Big Data 2. Lessons learnt from the past Ghislain Fourny Big Data 2. Lessons learnt from the past Mr. Databases: Edgar Codd Wikipedia 2 Data Independence (Edgar Codd) Logical data model Lorem Ipsum Dolor sit amet Physical storage Consectetur

More information

Big Data for Engineers Spring Data Models

Big Data for Engineers Spring Data Models Ghislain Fourny Big Data for Engineers Spring 2018 11. Data Models pinkyone / 123RF Stock Photo CSV (Comma separated values) This is syntax ID,Last name,first name,theory, 1,Einstein,Albert,"General, Special

More information

Basic SQL. Basic SQL. Basic SQL

Basic SQL. Basic SQL. Basic SQL Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Structured

More information

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul 1 EGCI 321: Database Systems Dr. Tanasanee Phienthrakul 2 Chapter 10 Data Definition Language (DDL) 3 Basic SQL SQL language Considered one of the major reasons for the commercial success of relational

More information

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas SQL SQL Functionality stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original

More information

SQL Data Definition Language: Create and Change the Database Ray Lockwood

SQL Data Definition Language: Create and Change the Database Ray Lockwood Introductory SQL SQL Data Definition Language: Create and Change the Database Pg 1 SQL Data Definition Language: Create and Change the Database Ray Lockwood Points: DDL statements create and alter the

More information

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4 SQL OVERVIEW CS121: Relational Databases Fall 2017 Lecture 4 SQL 2 SQL = Structured Query Language Original language was SEQUEL IBM s System R project (early 1970 s) Structured English Query Language Caught

More information

Programming and Database Fundamentals for Data Scientists

Programming and Database Fundamentals for Data Scientists Programming and Database Fundamentals for Data Scientists Database Fundamentals Varun Chandola School of Engineering and Applied Sciences State University of New York at Buffalo Buffalo, NY, USA chandola@buffalo.edu

More information

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1 SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier

More information

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

SQL Data Definition and Data Manipulation Languages (DDL and DML)

SQL Data Definition and Data Manipulation Languages (DDL and DML) .. Cal Poly CPE/CSC 365: Introduction to Database Systems Alexander Dekhtyar.. SQL Data Definition and Data Manipulation Languages (DDL and DML) Note: This handout instroduces both the ANSI SQL synatax

More information

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries

More information

Full file at

Full file at ch2 True/False Indicate whether the statement is true or false. 1. The SQL command to create a database table is an example of DML. 2. A user schema contains all database objects created by a user. 3.

More information

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic

More information

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1 BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 2 CHAPTER 4 OUTLINE SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL Set Operations in SQL 3 BASIC SQL Structured

More information

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 1 BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL Set Operations in SQL 3 BASIC SQL Structured

More information

INFORMATION TECHNOLOGY NOTES

INFORMATION TECHNOLOGY NOTES Unit-6 SESSION 7: RESPOND TO A MEETING REQUEST Calendar software allows the user to respond to other users meeting requests. Open the email application to view the request. to respond, select Accept, Tentative,

More information

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints SQL KEREM GURBEY WHAT IS SQL Database query language, which can also: Define structure of data Modify data Specify security constraints DATA DEFINITION Data-definition language (DDL) provides commands

More information

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) SQL language Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) 2011-2016 SQL - Structured Query Language SQL is a computer language for communicating with DBSM Nonprocedural (declarative) language What

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

user specifies what is wanted, not how to find it

user specifies what is wanted, not how to find it SQL stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original ANSI SQL updated

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features

More information

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL HOW TO CREATE AND MAINTAIN DATABASES AND TABLES By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate

More information

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,

More information

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 B0B36DBS, BD6B36DBS: Database Systems h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 SQL: Data De ni on Mar n Svoboda mar n.svoboda@fel.cvut.cz 13. 3. 2018 Czech Technical University

More information

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2 CMPT 354 Constraints Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers John Edgar 2 firstname type balance city customerid lastname accnumber rate branchname phone

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

Database Management Systems,

Database Management Systems, Database Management Systems SQL Query Language (1) 1 Topics Introduction SQL History Domain Definition Elementary Domains User-defined Domains Creating Tables Constraint Definition INSERT Query SELECT

More information

SQL: Data Definition Language

SQL: Data Definition Language SQL: Data Definition Language CSC 343 Winter 2018 MICHAEL LIUT (MICHAEL.LIUT@UTORONTO.CA) DEPARTMENT OF MATHEMATICAL AND COMPUTATIONAL SCIENCES UNIVERSITY OF TORONTO MISSISSAUGA Database Schemas in SQL

More information

CSCC43H: Introduction to Databases. Lecture 4

CSCC43H: Introduction to Databases. Lecture 4 CSCC43H: Introduction to Databases Lecture 4 Wael Aboulsaadat Acknowledgment: these slides are partially based on Prof. Garcia-Molina & Prof. Ullman slides accompanying the course s textbook. CSCC43: Introduction

More information

Relational Model. CSE462 Database Concepts. Demian Lessa. Department of Computer Science and Engineering State University of New York, Buffalo

Relational Model. CSE462 Database Concepts. Demian Lessa. Department of Computer Science and Engineering State University of New York, Buffalo Relational Model CSE462 Database Concepts Demian Lessa Department of Computer Science and Engineering State University of New York, Buffalo January 21 24, 2011 Next... 1 Relational Model Lessa Relational

More information

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018 Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018 Background Information 2 Background Information What is a (Relational) Database 3 Dynamic collection of information. Organized into tables,

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE 9/27/16 DATABASE SCHEMAS IN SQL SQL DATA DEFINITION LANGUAGE SQL is primarily a query language, for getting information from a database. SFWR ENG 3DB3 FALL 2016 But SQL also includes a data-definition

More information

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017 SQL: Data Definition Language csc343, Introduction to Databases Diane Horton Fall 2017 Types Table attributes have types When creating a table, you must define the type of each attribute. Analogous to

More information

MTAT Introduction to Databases

MTAT Introduction to Databases MTAT.03.105 Introduction to Databases Lecture #3 Data Types, Default values, Constraints Ljubov Jaanuska (ljubov.jaanuska@ut.ee) Lecture 1. Summary SQL stands for Structured Query Language SQL is a standard

More information

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 2 Data Definition Language (DDL) Eng. Alaa O Shama October, 2015 Objective To be familiar

More information

Database Programming with PL/SQL

Database Programming with PL/SQL Database Programming with PL/SQL 2-3 Objectives This lesson covers the following objectives: Define data type and explain why it is needed List and describe categories of data types Give examples of scalar

More information

The Relational Model of Data (ii)

The Relational Model of Data (ii) ICS 321 Fall 2013 The Relational Model of Data (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1 Defining Relational Schema in SQL Two aspects: Data

More information

Principles of Data Management

Principles of Data Management Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what

More information

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity SQL language: basics Creating a table Modifying table structure Deleting a table The data dictionary Data integrity 2013 Politecnico di Torino 1 Creating a table Creating a table (1/3) The following SQL

More information

COMP 430 Intro. to Database Systems

COMP 430 Intro. to Database Systems SELECT name FROM sqlite_master WHERE type='table' COMP 430 Intro. to Database Systems Single-table SQL Get clickers today! Slides use ideas from Chris Ré and Chris Jermaine. Clicker test Have you used

More information

CS143: Relational Model

CS143: Relational Model CS143: Relational Model Book Chapters (4th) Chapters 1.3-5, 3.1, 4.11 (5th) Chapters 1.3-7, 2.1, 3.1-2, 4.1 (6th) Chapters 1.3-6, 2.105, 3.1-2, 4.5 Things to Learn Data model Relational model Database

More information

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture COGS 121 HCI Programming Studio Week 03 - Tech Lecture Housekeeping Assignment #1 extended to Monday night 11:59pm Assignment #2 to be released on Tuesday during lecture Database Management Systems and

More information

How to define a relational schema for a data base?

How to define a relational schema for a data base? How to define a relational schema for a data base? 1 Professors Students Lectures PersNr Name Level Room StudNr Name Semester Lecture Title 2125 Sokrates C4 226 24002 Xenokrates 18 Nr 2126 Russel C4 232

More information

From theory to practice. Designing Tables for a postgresql Database System. psql. Reminder. A few useful commands

From theory to practice. Designing Tables for a postgresql Database System. psql. Reminder. A few useful commands From theory to practice Designing Tables for a postgresql Database System The Entity- Relationship model: a convenient way of representing the world. The Relational model: a model for organizing data using

More information

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS 1 INTRODUCTION TO EASIK EASIK is a Java based development tool for database schemas based on EA sketches. EASIK allows graphical modeling of EA sketches and views. Sketches and their views can be converted

More information

1) Introduction to SQL

1) Introduction to SQL 1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform

More information

Private Institute of Aga NETWORK DATABASE LECTURER NIYAZ M. SALIH

Private Institute of Aga NETWORK DATABASE LECTURER NIYAZ M. SALIH Private Institute of Aga 2018 NETWORK DATABASE LECTURER NIYAZ M. SALIH Data Definition Language (DDL): String data Types: Data Types CHAR(size) NCHAR(size) VARCHAR2(size) Description A fixed-length character

More information

CS634 Architecture of Database Systems Spring Elizabeth (Betty) O Neil University of Massachusetts at Boston

CS634 Architecture of Database Systems Spring Elizabeth (Betty) O Neil University of Massachusetts at Boston CS634 Architecture of Database Systems Spring 2018 Elizabeth (Betty) O Neil University of Massachusetts at Boston People & Contact Information Instructor: Prof. Betty O Neil Email: eoneil AT cs.umb.edu

More information

Database Systems CSE 303. Lecture 02

Database Systems CSE 303. Lecture 02 Database Systems CSE 303 Lecture 02 2016 Structure Query Language (SQL) 1 Today s Outline (mainly from chapter 2) SQL introduction & Brief History Relational Model Data in SQL Basic Schema definition Keys

More information

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)

More information

Database Systems CSE 303. Lecture 02

Database Systems CSE 303. Lecture 02 Database Systems CSE 303 Lecture 02 2016 Structure Query Language (SQL) Today s Outline (mainly from chapter 2) SQL introduction & Brief History Relational Model Data in SQL Basic Schema definition Keys

More information

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases and Data Manipulation Lecture 5: SQL s Language CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T Herley Department of Computer Science University College Cork 2017-2018 So far we ve

More information

IBM DB2 UDB V7.1 Family Fundamentals.

IBM DB2 UDB V7.1 Family Fundamentals. IBM 000-512 DB2 UDB V7.1 Family Fundamentals http://killexams.com/exam-detail/000-512 Answer: E QUESTION: 98 Given the following: A table containing a list of all seats on an airplane. A seat consists

More information

Lecture 5: SQL s Data Definition Language

Lecture 5: SQL s Data Definition Language Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (29/09/17) Lecture

More information

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language

More information

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng.

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Ahmed Abumarasa Database Lab Lab 2 Database Table Introduction: The previous

More information

SQL Data Definition Language

SQL Data Definition Language SQL Data Definition Language André Restivo 1 / 56 Index Introduction Table Basics Data Types Defaults Constraints Check Not Null Primary Keys Unique Keys Foreign Keys Sequences 2 / 56 Introduction 3 /

More information

The Relational Model

The Relational Model The Relational Model What is the Relational Model Relations Domain Constraints SQL Integrity Constraints Translating an ER diagram to the Relational Model and SQL Views A relational database consists

More information

Introduction to SQL. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Introduction to SQL. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011 Introduction to SQL IT 5101 Introduction to Database Systems J.G. Zheng Fall 2011 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic syntax

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB

More information

Lecture 1: Relational Databases

Lecture 1: Relational Databases Lecture 1: Relational Databases CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/09/17) Lecture 1: Relational

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

Exam code: Exam name: Database Fundamentals. Version 16.0

Exam code: Exam name: Database Fundamentals. Version 16.0 98-364 Number: 98-364 Passing Score: 800 Time Limit: 120 min File Version: 16.0 Exam code: 98-364 Exam name: Database Fundamentals Version 16.0 98-364 QUESTION 1 You have a table that contains the following

More information

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1 COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE

More information

SQL (Structured Query Language)

SQL (Structured Query Language) Lecture Note #4 COSC4820/5820 Database Systems Department of Computer Science University of Wyoming Byunggu Yu, 02/13/2001 SQL (Structured Query Language) 1. Schema Creation/Modification: DDL (Data Definition

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Alexandra Roatiş David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2016 CS 348 SQL Winter

More information

The SQL data-definition language (DDL) allows defining :

The SQL data-definition language (DDL) allows defining : Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... ) 2.9 Table Creation CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... ) CREATE TABLE Addresses ( id INTEGER, name VARCHAR(20), zipcode CHAR(5), city VARCHAR(20), dob DATE ) A list of valid

More information

SQL Commands & Mongo DB New Syllabus

SQL Commands & Mongo DB New Syllabus Chapter 15 : Computer Science Class XI ( As per CBSE Board) SQL Commands & Mongo DB New Syllabus 2018-19 SQL SQL is an acronym of Structured Query Language.It is a standard language developed and used

More information

Applied Databases. Sebastian Maneth. Lecture 7 Simple SQL Queries. University of Edinburgh - February 1 st, 2016

Applied Databases. Sebastian Maneth. Lecture 7 Simple SQL Queries. University of Edinburgh - February 1 st, 2016 Applied Databases Lecture 7 Simple SQL Queries Sebastian Maneth University of Edinburgh - February 1 st, 2016 Outline 2 1. Structured Querying Language (SQL) 2. Creating Tables 3. Simple SQL queries SQL

More information

Lecture 04: SQL. Wednesday, October 4, 2006

Lecture 04: SQL. Wednesday, October 4, 2006 Lecture 04: SQL Wednesday, October 4, 2006 1 Outline The Project Nulls (6.1.6) Outer joins (6.3.8) Database Modifications (6.5) 2 The Project Application: Boutique online music and book store Project:

More information

Introduction to SQL Server 2005/2008 and Transact SQL

Introduction to SQL Server 2005/2008 and Transact SQL Introduction to SQL Server 2005/2008 and Transact SQL Week 4: Normalization, Creating Tables, and Constraints Some basics of creating tables and databases Steve Stedman - Instructor Steve@SteveStedman.com

More information

UFCEKG 20 2 : Data, Schemas and Applications

UFCEKG 20 2 : Data, Schemas and Applications Lecture 11 UFCEKG 20 2 : Data, Schemas and Applications Lecture 11 Database Theory & Practice (5) : Introduction to the Structured Query Language (SQL) Origins & history Early 1970 s IBM develops Sequel

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2017 CS 348 (Intro to DB Mgmt) SQL

More information

In This Lecture. SQL Data Definition SQL SQL. Non-Procedural Programming. Notes. Database Systems Lecture 5 Natasha Alechina

In This Lecture. SQL Data Definition SQL SQL. Non-Procedural Programming. Notes. Database Systems Lecture 5 Natasha Alechina This Lecture Database Systems Lecture 5 Natasha Alechina The language, the relational model, and E/R diagrams CREATE TABLE Columns Primary Keys Foreign Keys For more information Connolly and Begg chapter

More information

An Introduction to Structured Query Language

An Introduction to Structured Query Language An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2016 CS 348 (Intro to DB Mgmt) SQL

More information

Slides by: Ms. Shree Jaswal

Slides by: Ms. Shree Jaswal Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval

More information

CSC 453 Database Technologies. Tanu Malik DePaul University

CSC 453 Database Technologies. Tanu Malik DePaul University CSC 453 Database Technologies Tanu Malik DePaul University A Data Model A notation for describing data or information. Consists of mostly 3 parts: Structure of the data Data structures and relationships

More information

Lecture 04: SQL. Monday, April 2, 2007

Lecture 04: SQL. Monday, April 2, 2007 Lecture 04: SQL Monday, April 2, 2007 1 Outline The Project Nulls (6.1.6) Outer joins (6.3.8) Database Modifications (6.5) 2 NULLS in SQL Whenever we don t have a value, we can put a NULL Can mean many

More information

Content: How to transform the relational model into a database schema DDL: create table students(studentnr int, name varchar);

Content: How to transform the relational model into a database schema DDL: create table students(studentnr int, name varchar); Chapter 5: Relational Database Definition Content: How to transform the relational model into a database schema DDL: create table students(studentnr int, name varchar); Next: Query the database 1 How to

More information

From theory to practice. Designing Tables for an Oracle Database System. Sqlplus. Sqlplus. Technicalities. Add the following to your.

From theory to practice. Designing Tables for an Oracle Database System. Sqlplus. Sqlplus. Technicalities. Add the following to your. From theory to practice Designing Tables for an Oracle Database System The Entity-Relationship model: a convenient way of representing the world. The Relational model: a model for organizing data using

More information

Big Data 11. Data Models

Big Data 11. Data Models Ghislain Fourny Big Data 11. Data Models pinkyone / 123RF Stock Photo CSV (Comma separated values) This is syntax ID,Last name,first name,theory, 1,Einstein,Albert,"General, Special Relativity" 2,Gödel,Kurt,"""Incompleteness""

More information

Advanced Constraints SQL. by Joe Celko copyright 2007

Advanced Constraints SQL. by Joe Celko copyright 2007 Advanced Constraints SQL by Joe Celko copyright 2007 Abstract The talk is a short overview of the options a programmer to use DDL (Data Declaration Language) in SQL to enforce a wide range of business

More information

Databases. Jörg Endrullis. VU University Amsterdam

Databases. Jörg Endrullis. VU University Amsterdam Databases Jörg Endrullis VU University Amsterdam The Relational Model Overview 1. Relational Model Concepts: Schema, State 2. Null Values 3. Constraints: General Remarks 4. Key Constraints 5. Foreign Key

More information

CMPT 354: Database System I. Lecture 2. Relational Model

CMPT 354: Database System I. Lecture 2. Relational Model CMPT 354: Database System I Lecture 2. Relational Model 1 Outline An overview of data models Basics of the Relational Model Define a relational schema in SQL 2 Outline An overview of data models Basics

More information

GridDB Advanced Edition SQL reference

GridDB Advanced Edition SQL reference GMA022C1 GridDB Advanced Edition SQL reference Toshiba Solutions Corporation 2016 All Rights Reserved. Introduction This manual describes how to write a SQL command in the GridDB Advanced Edition. Please

More information

MySQL Creating a Database Lecture 3

MySQL Creating a Database Lecture 3 MySQL Creating a Database Lecture 3 Robb T Koether Hampden-Sydney College Mon, Jan 23, 2012 Robb T Koether (Hampden-Sydney College) MySQL Creating a DatabaseLecture 3 Mon, Jan 23, 2012 1 / 31 1 Multiple

More information

Basic SQL. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Basic SQL. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016 Basic SQL Dr Paolo Guagliardo University of Edinburgh Fall 2016 SQL: Structured Query Language Sometimes pronounced sequel Developed initially at IBM in the 70s Standards: SQL-86, SQL-89, SQL-92 (SQL2),

More information

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates Chapter 13 : Informatics Practices Class XI ( As per CBSE Board) SQL Commands New Syllabus 2018-19 SQL SQL is an acronym of Structured Query Language.It is a standard language developed and used for accessing

More information

QQ Group

QQ Group QQ Group: 617230453 1 Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join 2 Generalized Projection Extends the projection operation by allowing arithmetic functions

More information

DATABASE TECHNOLOGY - 1MB025

DATABASE TECHNOLOGY - 1MB025 1 DATABASE TECHNOLOGY - 1MB025 Fall 2004 An introductory course on database systems http://user.it.uu.se/~udbl/dbt-ht2004/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht04/ Kjell Orsborn Uppsala

More information

Applied Databases. Sebastian Maneth. Lecture 7 Simple SQL Queries. University of Edinburgh - February 6 st, 2017

Applied Databases. Sebastian Maneth. Lecture 7 Simple SQL Queries. University of Edinburgh - February 6 st, 2017 Applied Databases Lecture 7 Simple SQL Queries Sebastian Maneth University of Edinburgh - February 6 st, 2017 Outline 2 1. Structured Querying Language (SQL) 2. Creating Tables 3. Simple SQL queries SQL

More information

Lecture 2: Introduction to SQL

Lecture 2: Introduction to SQL Lecture 2: Introduction to SQL Lecture 2 Announcements! 1. If you still have Jupyter trouble, let us know! 2. Enroll to Piazza!!! 3. People are looking for groups. Team up! 4. Enrollment should be finalized

More information

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton Outline Data Types Creating and Altering Tables Constraints Primary and Foreign Key Constraints Row and Tuple Checks

More information

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL Textbook Chapter 6 CSIE30600/CSIEB0290

More information