今回は、SQLでテーブルを新規作成する方法について解説します。
-- create1-
create table DB1.PUBLIC.DATA1
(
"id1" VARCHAR(10),
"id2" VARCHAR(10)
);
![](https://how-to-business.com/wp-content/uploads/2023/10/create1_1.png)
![](https://how-to-business.com/wp-content/uploads/2023/10/create1_2.png)
![](https://how-to-business.com/wp-content/uploads/2023/10/create1_3.png)
![](https://how-to-business.com/wp-content/uploads/2023/10/create1_4.png)
- テーブルDATA1の新規作成
- create table文では、指定したDB>スキーマ内にテーブルを新規作成できる。
- 項目名や型、長さを定義している。
- 項目定義の記載の前後にはカッコが必要。
-- create2-
-- 1回目実行
create table DB1.PUBLIC.DATA1
(
"id1" VARCHAR(10),
"id2" VARCHAR(10)
);
-- 2回目実行
create table DB1.PUBLIC.DATA1
(
"id1" VARCHAR(10),
"id2" VARCHAR(10)
);
![](https://how-to-business.com/wp-content/uploads/2023/10/create2_1.png)
![](https://how-to-business.com/wp-content/uploads/2023/10/create2_2.png)
- テーブルDATA1の新規作成→上書き作成(今回は失敗)
- create table文では、指定したDB>スキーマ内にテーブルを新規作成できる。
- 指定した場所に同名のテーブルが既にある場合は、コンパイルエラーとなる。
- 項目名や型、長さを定義している。
- 項目定義の記載の前後にはカッコが必要。
UIからテーブルを作成する方法
![](https://how-to-business.com/wp-content/uploads/2024/05/create3_2-1024x258.png)
![](https://how-to-business.com/wp-content/uploads/2023/10/create1_2.png)
![](https://how-to-business.com/wp-content/uploads/2024/05/create3_3-1024x253.png)
![](https://how-to-business.com/wp-content/uploads/2023/10/create1_2.png)
![](https://how-to-business.com/wp-content/uploads/2024/05/create3_4-1024x254.png)
![](https://how-to-business.com/wp-content/uploads/2024/05/create3_5-1024x276.png)
![](https://how-to-business.com/wp-content/uploads/2024/05/create3_6-1-1024x276.png)
![](https://how-to-business.com/wp-content/uploads/2024/05/create3_7-1024x236.png)
【関連記事】