---
# System prepended metadata

title: '# Golang 筆記(2.5)-[補充]基本SQL語法'
tags: [Golang]

---

---
tags: Golang
---
# # Golang 筆記(2.5)-[補充]基本SQL語法

## CREATE/DROP/ALTER TABLE

* CREATE
```
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
```

* DROP
```
DROP TABLE table_name;
```

* ALTER

```
ALTER TABLE Customers
ADD Email varchar(255);
```

```
ALTER TABLE table_name
DROP COLUMN column_name;
```



## SELECT vs INSERT/UPDATE/DELETE table中的資料

* SELECT

```
SELECT * FROM table_name;
```

```
SELECT column1, column2, ...
FROM table_name;
```

* INSERT

```
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

```
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

```
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
```



* UPDATE

```
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
```


* DELETE
```
DELETE FROM table_name WHERE condition;
```



[參考資料 w3school](https://www.w3schools.com/sql/sql_intro.asp)