html-flip-book-react 0.0.0-alpha.1 → 0.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FlipBook.d.ts +26 -0
- package/dist/FlipBook.d.ts.map +1 -0
- package/dist/assets/html-flip-book.css +1 -0
- package/dist/flip-book.js +47 -1405
- package/dist/flip-book.js.map +1 -1
- package/dist/toolbar/FirstPageButton.d.ts +9 -0
- package/dist/toolbar/FirstPageButton.d.ts.map +1 -0
- package/dist/toolbar/FullscreenButton.d.ts +11 -0
- package/dist/toolbar/FullscreenButton.d.ts.map +1 -0
- package/dist/toolbar/LastPageButton.d.ts +9 -0
- package/dist/toolbar/LastPageButton.d.ts.map +1 -0
- package/dist/toolbar/NextButton.d.ts +9 -0
- package/dist/toolbar/NextButton.d.ts.map +1 -0
- package/dist/toolbar/PageIndicator.d.ts +9 -0
- package/dist/toolbar/PageIndicator.d.ts.map +1 -0
- package/dist/toolbar/PrevButton.d.ts +9 -0
- package/dist/toolbar/PrevButton.d.ts.map +1 -0
- package/dist/toolbar/Toolbar.d.ts +13 -0
- package/dist/toolbar/Toolbar.d.ts.map +1 -0
- package/dist/toolbar/ToolbarButton.d.ts +13 -0
- package/dist/toolbar/ToolbarButton.d.ts.map +1 -0
- package/dist/toolbar/ToolbarContext.d.ts +15 -0
- package/dist/toolbar/ToolbarContext.d.ts.map +1 -0
- package/dist/toolbar/index.d.ts +19 -0
- package/dist/toolbar/index.d.ts.map +1 -0
- package/dist/toolbar/index.js +174 -0
- package/dist/toolbar/index.js.map +1 -0
- package/package.json +45 -43
- package/dist/flip-book.d.ts +0 -14
- package/dist/flip-book.d.ts.map +0 -1
- package/example/.vscode/settings.json +0 -3
- package/example/README.md +0 -47
- package/example/assets/pages_data/en/assets/cover.jpg +0 -0
- package/example/assets/pages_data/en/assets/sql-command.png +0 -0
- package/example/assets/pages_data/en/content/000-introduction.md +0 -85
- package/example/assets/pages_data/en/content/001-databases.md +0 -39
- package/example/assets/pages_data/en/content/002-install-mysql.md +0 -162
- package/example/assets/pages_data/en/content/003-creating-tables.md +0 -304
- package/example/assets/pages_data/en/content/004-basic-syntax.md +0 -145
- package/example/assets/pages_data/en/content/005-select.md +0 -359
- package/example/assets/pages_data/en/content/006-where.md +0 -225
- package/example/assets/pages_data/en/content/007-order-and-group-by.md +0 -142
- package/example/assets/pages_data/en/content/008-insert.md +0 -86
- package/example/assets/pages_data/en/content/009-update.md +0 -92
- package/example/assets/pages_data/en/content/010-delete.md +0 -28
- package/example/assets/pages_data/en/content/011-join.md +0 -297
- package/example/assets/pages_data/en/content/012-sql-command-categories.md +0 -121
- package/example/assets/pages_data/en/content/013-sub-queries.md +0 -112
- package/example/assets/pages_data/en/content/014-unions.md +0 -124
- package/example/assets/pages_data/en/content/015-Keys-in-a-Relational Database.md +0 -51
- package/example/assets/pages_data/en/content/016-Logical-operator-keywords.md +0 -17
- package/example/assets/pages_data/en/content/017-having-clause_aggregate-functions.md +0 -184
- package/example/assets/pages_data/en/content/018-essential-mysql-functions.md +0 -190
- package/example/assets/pages_data/en/content/019-triggers-in-sql.md +0 -133
- package/example/assets/pages_data/en/content/020-TCL-commands.md +0 -154
- package/example/assets/pages_data/en/content/021-DCL-commands.md +0 -126
- package/example/assets/pages_data/en/content/100-mysqldump.md +0 -109
- package/example/assets/pages_data/en/content/101-learn-materialize.md +0 -267
- package/example/assets/pages_data/en/content/999-conclusion.md +0 -24
- package/example/assets/pages_data/he/4.txt +0 -2
- package/example/assets/pages_data/he/5.txt +0 -4
- package/example/assets/pages_data/he/6.txt +0 -4
- package/example/index.html +0 -21
- package/example/package-lock.json +0 -5324
- package/example/package.json +0 -39
- package/example/src/App.css +0 -52
- package/example/src/App.tsx +0 -25
- package/example/src/EnBook.tsx +0 -55
- package/example/src/HeBook.tsx +0 -44
- package/example/src/index.tsx +0 -12
- package/example/vite-env.d.ts +0 -1
- package/example/vite.config.js +0 -84
- package/src/FlipBook.tsx +0 -45
- package/vite.config.js +0 -66
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
# Tables
|
|
2
|
-
|
|
3
|
-
Before we get started with SQL, let's learn how to create tables and columns.
|
|
4
|
-
|
|
5
|
-
As an example, we are going to create a `users` table with the following columns:
|
|
6
|
-
|
|
7
|
-
* `id` - this is going to be the primary key of the table and would be the unique identifier of each user.
|
|
8
|
-
* `username` - this column would hold the username of our users.
|
|
9
|
-
* `name` - here, we will store the full name of users.
|
|
10
|
-
* `status` - here, we will store the status of a user, which would indicate if a user is active or not.
|
|
11
|
-
|
|
12
|
-
You need to specify the data type of each column.
|
|
13
|
-
|
|
14
|
-
In our case it would be like this:
|
|
15
|
-
|
|
16
|
-
* `id` - Integer
|
|
17
|
-
* `username` - Varchar
|
|
18
|
-
* `name` - Varchar
|
|
19
|
-
* `status` - Number
|
|
20
|
-
|
|
21
|
-
## Data types
|
|
22
|
-
|
|
23
|
-
The most common data types that you would come across are:
|
|
24
|
-
|
|
25
|
-
* `CHAR`(size): Fixed-length character string with a maximum length of 255 bytes.
|
|
26
|
-
* `VARCHAR`(size): Variable-length character string. Max size is specified in parenthesis.
|
|
27
|
-
* `TEXT`(size): A string with a maximum length of 65,535 bytes.
|
|
28
|
-
* `INTEGER`(size) or `INT`(size): A medium integer.
|
|
29
|
-
* `BOOLEAN` or `BOOL`: Holds a true or false value.
|
|
30
|
-
* `DATE`: Holds a date.
|
|
31
|
-
|
|
32
|
-
Let's have the following users table as an example:
|
|
33
|
-
|
|
34
|
-
* `id`: We would want to set the ID to `INT`.
|
|
35
|
-
* `name`: The name should fit in a `VARCHAR` column.
|
|
36
|
-
* `about`: As the about section could be longer, we could set the column data type to `TEXT`.
|
|
37
|
-
* `birthday`: For the birthday column of the user, we could use `DATE`.
|
|
38
|
-
|
|
39
|
-
For more information on all data types available, make sure to check out the official documentation [here](https://dev.mysql.com/doc/refman/8.0/en/data-types.html).
|
|
40
|
-
|
|
41
|
-
## Creating a database
|
|
42
|
-
|
|
43
|
-
As we briefly covered in the previous chapter, before you could create tables, you would need to create a database by running the following:
|
|
44
|
-
|
|
45
|
-
* First access MySQL:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
mysql -u root -p
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
* Then create a database called `demo_db`:
|
|
52
|
-
|
|
53
|
-
```sql
|
|
54
|
-
CREATE DATABASE demo_db;
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
> Note: the database name needs to be unique, if you already have a database named `demo_db` you would receive an error that the database already exists.
|
|
58
|
-
|
|
59
|
-
You can consider this database as the container where we would create all of the tables in.
|
|
60
|
-
|
|
61
|
-
Once you've created the database, you need to switch to that database:
|
|
62
|
-
|
|
63
|
-
```sql
|
|
64
|
-
USE demo_db;
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
You can think of this as accessing a directory in Linux with the `cd` command. With `USE`, we switch to a specific database.
|
|
68
|
-
|
|
69
|
-
Alternatively, if you do not want to 'switch' to the specific database, you would need to specify the so-called fully qualified table name. For example, if you had a `users` table in the `demo_db`, and you wanted to select all of the entries from that table, you could use one of the following two approaches:
|
|
70
|
-
|
|
71
|
-
* Switch to the `demo_db` first and then run a select statement:
|
|
72
|
-
|
|
73
|
-
```sql
|
|
74
|
-
USE demo_db;
|
|
75
|
-
SELECT username FROM users;
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
* Alternatively, rather than using the `USE` command first, specify the database name followed by the table name separated with a dot: `db_name.table_name`:
|
|
79
|
-
|
|
80
|
-
```sql
|
|
81
|
-
SELECT username FROM demo_db.users;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
We are going to cover the `SELECT` statement more in-depth in the following chapters.
|
|
85
|
-
|
|
86
|
-
## Creating tables
|
|
87
|
-
|
|
88
|
-
In order to create a table, you need to use the `CREATE TABLE` statement followed by the columns that you want to have in that table and their data type.
|
|
89
|
-
|
|
90
|
-
Let's say that we wanted to create a `users` table with the following columns:
|
|
91
|
-
|
|
92
|
-
* `id`: An integer value
|
|
93
|
-
* `username`: A varchar value
|
|
94
|
-
* `about`: A text type
|
|
95
|
-
* `birthday`: Date
|
|
96
|
-
* `active`: True or false
|
|
97
|
-
|
|
98
|
-
The query that we would need to run to create that table would be:
|
|
99
|
-
|
|
100
|
-
```sql
|
|
101
|
-
CREATE TABLE users
|
|
102
|
-
(
|
|
103
|
-
id INT,
|
|
104
|
-
username VARCHAR(255),
|
|
105
|
-
about TEXT,
|
|
106
|
-
birthday DATE,
|
|
107
|
-
active BOOL
|
|
108
|
-
);
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
> Note: You need to select a database first with the `USE` command as mentioned above. Otherwise you will get the following error: `ERROR 1046 (3D000): No database selected.
|
|
112
|
-
|
|
113
|
-
To list the available tables, you could run the following command:
|
|
114
|
-
|
|
115
|
-
```sql
|
|
116
|
-
SHOW TABLES;
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Output:
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
+-------------------+
|
|
123
|
-
| Tables_in_demo_db |
|
|
124
|
-
+-------------------+
|
|
125
|
-
| users |
|
|
126
|
-
+-------------------+
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### Creating a new table from an existing table
|
|
130
|
-
|
|
131
|
-
You can create a new table from an existing table by using the `CREATE TABLE AS` statement.
|
|
132
|
-
|
|
133
|
-
Let's test that by creating a new table from the table `users` which we created earlier.
|
|
134
|
-
|
|
135
|
-
```sql
|
|
136
|
-
CREATE TABLE users2 AS
|
|
137
|
-
(
|
|
138
|
-
SELECT * FROM users
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
The output that you would get would be:
|
|
144
|
-
```
|
|
145
|
-
Query OK, 0 rows affected (0.07 sec)
|
|
146
|
-
Records: 0 Duplicates: 0 Warnings: 0
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
>Note: When creating a table in this way, the new table will be populated with the records from the existing table (based on the SELECT Statement)
|
|
150
|
-
|
|
151
|
-
## Rename tables
|
|
152
|
-
|
|
153
|
-
You can rename a table by using `ALTER TABLE` statement.
|
|
154
|
-
|
|
155
|
-
Let's change name of user2 table to user3
|
|
156
|
-
```sql
|
|
157
|
-
ALTER TABLE user2 RENAME TO user3
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Dropping tables
|
|
161
|
-
|
|
162
|
-
You can drop or delete tables by using the `DROP TABLE` statement.
|
|
163
|
-
|
|
164
|
-
Let's test that and drop the table that we've just created:
|
|
165
|
-
|
|
166
|
-
```sql
|
|
167
|
-
DROP TABLE users;
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
The output that you would get would be:
|
|
171
|
-
|
|
172
|
-
```
|
|
173
|
-
Query OK, 0 rows affected (0.03 sec)
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
And now, if you were to run the `SHOW TABLES;` query again, you would get the following output:
|
|
177
|
-
|
|
178
|
-
```
|
|
179
|
-
Empty set (0.00 sec)
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## Allowing NULL values
|
|
183
|
-
|
|
184
|
-
By default, each column in your table can hold NULL values. In case that you don't wanted to allow NULL values for some of the columns in a specific table, you need to specify this during the table creation or later on change the table to allow that.
|
|
185
|
-
|
|
186
|
-
For example, let's say that we want the `username` column to be a required one, we would need to alter the table create statement and include `NOT NULL` right next to the `username` column like this:
|
|
187
|
-
|
|
188
|
-
```sql
|
|
189
|
-
CREATE TABLE users
|
|
190
|
-
(
|
|
191
|
-
id INT,
|
|
192
|
-
username VARCHAR(255) NOT NULL,
|
|
193
|
-
about TEXT,
|
|
194
|
-
birthday DATE,
|
|
195
|
-
active BOOL
|
|
196
|
-
);
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
That way, when you try to add a new user, MySQL will let you know that the `username` column is required.
|
|
200
|
-
|
|
201
|
-
## Specifying a primary key
|
|
202
|
-
|
|
203
|
-
The primary key column, which in our case is the `id` column, is a unique identifier for our users.
|
|
204
|
-
|
|
205
|
-
We want the `id` column to be unique, and also, whenever we add new users, we want the ID of the user to autoincrement for each new user.
|
|
206
|
-
|
|
207
|
-
This can be achieved with a primary key and `AUTO_INCREMENT`. The primary key column needs to be `NOT NULL` as well.
|
|
208
|
-
|
|
209
|
-
If we were to alter the table creation statement, it would look like this:
|
|
210
|
-
|
|
211
|
-
```sql
|
|
212
|
-
CREATE TABLE users
|
|
213
|
-
(
|
|
214
|
-
id INT PRIMARY KEY AUTO_INCREMENT,
|
|
215
|
-
username VARCHAR(255) NOT NULL,
|
|
216
|
-
about TEXT,
|
|
217
|
-
birthday DATE,
|
|
218
|
-
active BOOL
|
|
219
|
-
);
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Updating tables
|
|
223
|
-
|
|
224
|
-
In the above example, we created a new table and then dropped it as it was empty. However, in a real-life scenario, this would really be the case.
|
|
225
|
-
|
|
226
|
-
So whenever you need to add or remove a new column from a specific table, you would need to use the `ALTER TABLE` statement.
|
|
227
|
-
|
|
228
|
-
Let's say that we wanted to add an `email` column with type varchar to our `users` table.
|
|
229
|
-
|
|
230
|
-
The syntax would be:
|
|
231
|
-
|
|
232
|
-
```sql
|
|
233
|
-
ALTER TABLE users ADD email VARCHAR(255);
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
After that, if you were to describe the table, you would see the new column:
|
|
237
|
-
|
|
238
|
-
```sql
|
|
239
|
-
DESCRIBE users;
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Output:
|
|
243
|
-
|
|
244
|
-
```
|
|
245
|
-
+----------+--------------+------+-----+---------+
|
|
246
|
-
| Field | Type | Null | Key | Default |
|
|
247
|
-
+----------+--------------+------+-----+---------+
|
|
248
|
-
| id | int | NO | PRI | NULL |
|
|
249
|
-
| username | varchar(255) | NO | | NULL |
|
|
250
|
-
| about | text | YES | | NULL |
|
|
251
|
-
| birthday | date | YES | | NULL |
|
|
252
|
-
| active | tinyint(1) | YES | | NULL |
|
|
253
|
-
| email | varchar(255) | YES | | NULL |
|
|
254
|
-
+----------+--------------+------+-----+---------+
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
If you wanted to drop a specific column, the syntax would be:
|
|
258
|
-
|
|
259
|
-
```sql
|
|
260
|
-
ALTER TABLE table_name DROP COLUMN column_name;
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
> Note: Keep in mind that this is a permanent change, and if you have any critical data in the specific column, it would be deleted instantly.
|
|
264
|
-
|
|
265
|
-
You can use the `ALTER TABLE` statement to also change the data type of a specific column. For example, you could change the `about` column from `TEXT` to `LONGTEXT` type, which could hold longer strings.
|
|
266
|
-
|
|
267
|
-
> Note: Important thing to keep in mind is that if a specific table already holds a particular type of data value like an integer, you can't alter it to varchar, for example. Only if the column does not contain any values, then you could make the change.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
## Truncate table
|
|
271
|
-
|
|
272
|
-
The `TRUNCATE TABLE` command is used to **delete all of the data** from an existing table, but not the table itself.
|
|
273
|
-
|
|
274
|
-
* Syntax of Truncate table:
|
|
275
|
-
|
|
276
|
-
```sql
|
|
277
|
-
TRUNCATE TABLE table_name;
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
* Example:
|
|
281
|
-
|
|
282
|
-
Consider a Sellers table having the following records:
|
|
283
|
-
|
|
284
|
-
```
|
|
285
|
-
+----+----------+-----+-----------+----------+
|
|
286
|
-
| ID | NAME |Items| CITY | SALARY |
|
|
287
|
-
+----+----------+-----+-----------+----------+
|
|
288
|
-
| 1 | Shivam | 34 | Ahmedabad | 2000.00 |
|
|
289
|
-
| 2 | Ajay | 22 | Delhi | 4400.00 |
|
|
290
|
-
| 3 | Kaushik | 28 | Kota | 2000.00 |
|
|
291
|
-
| 4 | Chaitali | 25 | Mumbai | 6600.00 |
|
|
292
|
-
| 5 | Hardik | 26 | Bhopal | 8100.00 |
|
|
293
|
-
| 6 | Maria | 23 | MP | 4200.00 |
|
|
294
|
-
| 7 | Muffy | 29 | Indore | 9000.00 |
|
|
295
|
-
+----+----------+-----+-----------+----------+
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
Following is the example of a Truncate command:
|
|
299
|
-
|
|
300
|
-
```sql
|
|
301
|
-
TRUNCATE TABLE Sellers;
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
After that if you do a `COUNT(*)` on that table you would see that the table is completely empty.
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
# Basic Syntax
|
|
2
|
-
|
|
3
|
-
In this chapter, we will go over the basic SQL syntax.
|
|
4
|
-
|
|
5
|
-
SQL statements are basically the 'commands' that you run against a specific database. Through the SQL statements, you are telling MySQL what you want it to do, for example, if you wanted to get the `username` of all of your users stored in the `users` table, you would run the following SQL statement:
|
|
6
|
-
|
|
7
|
-
```sql
|
|
8
|
-
SELECT username FROM users;
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Rundown of the statement:
|
|
12
|
-
|
|
13
|
-
* `SELECT`: First, we specify the `SELECT` keyword, which indicates that we want to select some data from the database. Other popular keywords are: `INSERT`, `UPDATE` and `DELETE`.
|
|
14
|
-
* `username`: Then we specify which column we want to select.
|
|
15
|
-
* `FROM users`: After that, we specify the table that we want to select the data from using the `FROM` keyword.
|
|
16
|
-
* The semicolon `;` is highly recommended to put at the end. Standard SQL syntax requires it, but some "Database Management Systems' (DBMS)" are tolerant about it, but it's not worth the risk.
|
|
17
|
-
|
|
18
|
-
If you run the above statement, you will get no results as the new `users` table that we've just created is empty.
|
|
19
|
-
|
|
20
|
-
> As a good practice, all SQL keywords should be with uppercase, however, it would work just fine if you use lower case as well.
|
|
21
|
-
|
|
22
|
-
Let's go ahead and cover the basic operations next.
|
|
23
|
-
|
|
24
|
-
## INSERT
|
|
25
|
-
|
|
26
|
-
To add data to your database, you would use the `INSERT` statement.
|
|
27
|
-
|
|
28
|
-
Let's use the table that we created in the last chapter and insert 1 user into our `users` table:
|
|
29
|
-
|
|
30
|
-
```sql
|
|
31
|
-
INSERT INTO users (username, email, active)
|
|
32
|
-
VALUES ('bobby', 'bobby@bobbyiliev.com', true);
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Rundown of the insert statement:
|
|
36
|
-
|
|
37
|
-
* `INSERT INTO`: first, we specify the `INSERT INTO` keyword, which tells MySQL that we want to insert data a table.
|
|
38
|
-
* `users (username, email, active)`: then, we specify the table name `users` and the columns that we want to insert data into.
|
|
39
|
-
* `VALUES`: then, we specify the values that we want to insert in. The order of attributes is the same as in `users (...)`.
|
|
40
|
-
|
|
41
|
-
## SELECT
|
|
42
|
-
|
|
43
|
-
Once we've inserted that user, let's go ahead and retrieve the information.
|
|
44
|
-
|
|
45
|
-
To retrieve information from your database, you could use the `SELECT` statement:
|
|
46
|
-
|
|
47
|
-
```sql
|
|
48
|
-
SELECT * FROM users;
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Output:
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
+----+----------+-------+----------+--------+---------------+
|
|
55
|
-
| id | username | about | birthday | active | email |
|
|
56
|
-
+----+----------+-------+----------+--------+---------------+
|
|
57
|
-
| 1 | bobby | NULL | NULL | 1 | bobby@b...com |
|
|
58
|
-
+----+----------+-------+----------+--------+---------------+
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
We specify `*` right after the `SELECT` keyword, this means that we want to get all of the columns from the `users` table.
|
|
62
|
-
|
|
63
|
-
If we wanted to the only the `username` and the `email` columns instead, we would change the statement to:
|
|
64
|
-
|
|
65
|
-
```sql
|
|
66
|
-
SELECT username, email FROM users;
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
This will return all of the users, but as of the time being we have only 1:
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
+----------+----------------------+
|
|
73
|
-
| username | email |
|
|
74
|
-
+----------+----------------------+
|
|
75
|
-
| bobby | bobby@bobbyiliev.com |
|
|
76
|
-
+----------+----------------------+
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## UPDATE
|
|
80
|
-
|
|
81
|
-
In order to modify data in your database, you could use the `UPDATE` statement.
|
|
82
|
-
|
|
83
|
-
The syntax would look like this:
|
|
84
|
-
|
|
85
|
-
```sql
|
|
86
|
-
UPDATE users SET username='bobbyiliev' WHERE id=1;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Rundown of the statement:
|
|
90
|
-
|
|
91
|
-
* `UPDATE users`: First, we specify the `UPDATE` keyword followed by the table that we want to update.
|
|
92
|
-
* `SET username='bobbyiliev'`: Then we specify the columns that we want to update and the new value that we want to set.
|
|
93
|
-
* `WHERE id=1`: Finally, by using the `WHERE` clause, we specify which user should be updated. In our case it is the user with ID 1.
|
|
94
|
-
|
|
95
|
-
> NOTE: If we don't specify a `WHERE` clause, all of the entries inside the `users` table would be updated, and all users would have the `username` set to `bobbyiliev`. You need to be careful when you use the `UPDATE` statement without a `WHERE` clause, as every single row will be updated.
|
|
96
|
-
|
|
97
|
-
We are going to cover `WHERE` more in-depth in the next few chapters.
|
|
98
|
-
|
|
99
|
-
## DELETE
|
|
100
|
-
|
|
101
|
-
As the name suggests, the `DELETE` statement would remove data from your database.
|
|
102
|
-
|
|
103
|
-
The syntax is as follows:
|
|
104
|
-
|
|
105
|
-
```sql
|
|
106
|
-
DELETE FROM users WHERE id=1;
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Similar to the `UPDATE` statement, if you don't specify a `WHERE` clause, all of the entries from the table will be affected, meaning that all of your users will be deleted.
|
|
110
|
-
|
|
111
|
-
## Comments
|
|
112
|
-
|
|
113
|
-
In case that you are writing a larger SQL script, it might be helpful to add some comments so that later on, when you come back to the script, you would know what each line does.
|
|
114
|
-
|
|
115
|
-
As with all programming languages, you can add comments in SQL as well.
|
|
116
|
-
|
|
117
|
-
There are two types of comments:
|
|
118
|
-
|
|
119
|
-
* Inline comments:
|
|
120
|
-
|
|
121
|
-
To do so, you just need to add `--` before the text that you want to comment out:
|
|
122
|
-
|
|
123
|
-
```sql
|
|
124
|
-
SELECT * FROM users; -- Get all users
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
* Multiple-line comments:
|
|
128
|
-
|
|
129
|
-
Similar to some other programming languages in order to comment multiple lines, you could wrap the text in `/*` `*/` as follows:
|
|
130
|
-
|
|
131
|
-
```sql
|
|
132
|
-
/*
|
|
133
|
-
Get all of the users
|
|
134
|
-
from your database
|
|
135
|
-
*/
|
|
136
|
-
SELECT * FROM users;
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
You could write that in a `.sql` file and then run it later on, or execute the few lines directly.
|
|
140
|
-
|
|
141
|
-
## Conclusion
|
|
142
|
-
|
|
143
|
-
Those were some of the most common basic SQL statements.
|
|
144
|
-
|
|
145
|
-
In the next chapters, we are going to go over each of the above statements more in-depth.
|