Skip to content

Commit 57edcce

Browse files
added SQL database
1 parent fb75fc1 commit 57edcce

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

docs/Cheat-Sheets/SQL.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ ALTER TABLE table_name DROP INDEX constraint_name; -- MySQL (for UNIQUE constrai
101101

102102
```sql
103103
DROP TABLE table_name;
104+
105+
-- Drop table only if it exists (avoids error if it doesn't)
106+
DROP TABLE IF EXISTS table_name;
104107
```
105108

106109
### TRUNCATE TABLE
@@ -145,6 +148,24 @@ FROM employees;
145148
DROP VIEW view_name;
146149
```
147150

151+
### DATABASE Operations
152+
153+
```sql
154+
-- Create a new database
155+
CREATE DATABASE database_name;
156+
157+
-- Delete an existing database
158+
DROP DATABASE database_name;
159+
160+
-- Delete an existing database only if it exists (avoids error if it doesn't)
161+
DROP DATABASE IF EXISTS database_name;
162+
163+
-- Select a database to use (syntax varies, common in MySQL)
164+
USE database_name;
165+
```
166+
167+
168+
148169
## Data Manipulation Language (DML)
149170

150171
### INSERT
@@ -232,7 +253,8 @@ SELECT * FROM table_name ORDER BY column1 ASC, column2 DESC;
232253

233254
```sql
234255
SELECT * FROM table_name LIMIT 10; -- Get the first 10 rows
235-
SELECT * FROM table_name LIMIT 10 OFFSET 5; -- Get 10 rows starting from row 6```
256+
SELECT * FROM table_name LIMIT 10 OFFSET 5; -- Get 10 rows starting from row 6
257+
```
236258

237259
### Aggregate Functions
238260

0 commit comments

Comments
 (0)