<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>insert文 &#8211; スグブログ</title>
	<atom:link href="https://sugublog.org/tag/insert%e6%96%87/feed/" rel="self" type="application/rss+xml" />
	<link>https://sugublog.org</link>
	<description>ブログ運営について発信中</description>
	<lastBuildDate>Thu, 07 Sep 2023 16:26:17 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://sugublog.org/wp-content/uploads/2021/07/icon_20210703-min-150x150.png</url>
	<title>insert文 &#8211; スグブログ</title>
	<link>https://sugublog.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【SQL基礎】insert文でDB（データベース）にデータを挿入する</title>
		<link>https://sugublog.org/sql-base-insert/</link>
					<comments>https://sugublog.org/sql-base-insert/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Wed, 11 Aug 2021 11:53:03 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[insert文]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=3927</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/08/script_0809-3-1024x683.jpg" class="webfeedsFeaturedVisual" /></p>MySQLの4大命令文の中の1つ、insert文について見ていきます。 insert文はデータベースにデータを挿入する事が可能です。 insert文の基礎を学んで、データベースにデータを挿入できるようになりましょう。 S [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/08/script_0809-3-1024x683.jpg" class="webfeedsFeaturedVisual" /></p>
<p><span class="swl-marker mark_orange"><strong>MySQL</strong>の4大命令文の中の1つ、<strong><span class="swl-inline-color has-swl-deep-01-color">insert文</span></strong>について見ていきます。</span></p>



<p>insert文はデータベースにデータを挿入する事が可能です。</p>



<p>insert文の基礎を学んで、データベースにデータを挿入できるようになりましょう。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>この記事を読んで、理解出来る事</span></div><div class="cap_box_content">
<p><strong>MySQL</strong>で<strong><span class="swl-inline-color has-swl-deep-01-color">insert文</span></strong>を理解し、DB（データベース）に<strong>値を挿入</strong>できるようになる。</p>
</div></div>


<div class="p-blogParts post_content" data-partsID="5030">
<p>windowsのプロンプトで使用できるbatやpythonやphpを使用して、業務効率化やWebサイトを作成しております。javaやシェルスクリプトなど、様々なプログラミングを行った実績ありの筆者です。</p>
</div>


<h2 class="wp-block-heading">SQLのinsert文でDB（データベース）にデータを挿入する</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="512" src="https://sugublog.org/wp-content/uploads/2021/07/code-007-01-1024x512.jpg" alt="code" class="wp-image-3584" srcset="https://sugublog.org/wp-content/uploads/2021/07/code-007-01-1024x512.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/07/code-007-01-300x150.jpg 300w, https://sugublog.org/wp-content/uploads/2021/07/code-007-01-768x384.jpg 768w, https://sugublog.org/wp-content/uploads/2021/07/code-007-01-1536x768.jpg 1536w, https://sugublog.org/wp-content/uploads/2021/07/code-007-01-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<h3 class="wp-block-heading">MySQLのinsert文の基礎</h3>



<p>結論：DBに値を挿入するinsert文の基礎は下記です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into テーブル名 (カラム名,カラム名,カラム名,,,) value (値,値,値,,,);</code></pre></div>



<h3 class="wp-block-heading">insert文で挿入する為のデータベース参照</h3>



<p>今回下記のテーブルを作成したとします。</p>



<p class="is-style-balloon_box">テーブル名：users</p>



<figure class="wp-block-table is-style-regular"><table class="has-fixed-layout"><thead><tr><th> id </th><th> name </th><th> score </th></tr></thead><tbody><tr><td>1</td><td>user_1</td><td>47</td></tr><tr><td>2</td><td>user_2</td><td>24</td></tr></tbody></table><figcaption class="wp-element-caption">DBのusersテーブル</figcaption></figure>



<h3 class="wp-block-heading">実際データベースにinsert文でデータを追記してみる</h3>



<p>下記のデータをusersテーブルに追記してみましょう。</p>



<ul class="wp-block-list">
<li>id = 3</li>



<li>name = user_3</li>



<li>score = 33</li>
</ul>



<p>実際に使用した<strong>insert文</strong>は下記になりました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into users (id,name,score) value (3,&#39;user_3&#39;,33);</code></pre></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9330904718533231"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-9330904718533231"
     data-ad-slot="8455594968"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<p>データベースにクエリを送信してみましょう。</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="422" height="184" src="https://sugublog.org/wp-content/uploads/2021/08/image-14.png" alt="テーブルにユーザーが追加された" class="wp-image-3936" srcset="https://sugublog.org/wp-content/uploads/2021/08/image-14.png 422w, https://sugublog.org/wp-content/uploads/2021/08/image-14-300x131.png 300w" sizes="(max-width: 422px) 100vw, 422px" /></figure>
</div>


<p>SQLのinsert文でDBにデータが追加された事を確認できました。</p>



<h2 class="wp-block-heading"> 省略系:SQLのinsert文でDB（データベース）にデータを挿入する </h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="535" src="https://sugublog.org/wp-content/uploads/2021/07/programing007-1024x535.jpg" alt="programing" class="wp-image-3636" srcset="https://sugublog.org/wp-content/uploads/2021/07/programing007-1024x535.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/07/programing007-300x157.jpg 300w, https://sugublog.org/wp-content/uploads/2021/07/programing007-768x401.jpg 768w, https://sugublog.org/wp-content/uploads/2021/07/programing007-1536x802.jpg 1536w, https://sugublog.org/wp-content/uploads/2021/07/programing007-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>テーブルのカラム数があっていれば、カラムは省略可能です。</p>



<p>insert文の基礎は下記でした。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into テーブル名 (カラム名,カラム名,カラム名,,,) value (値,値,値,,,);</code></pre></div>



<p>今回作成したテーブルは下記でした。</p>



<p class="is-style-balloon_box">テーブル名：users</p>



<figure class="wp-block-table is-style-regular"><table class="has-fixed-layout"><thead><tr><th> id </th><th> name </th><th> score </th></tr></thead><tbody><tr><td>1</td><td>user_1</td><td>47</td></tr><tr><td>2</td><td>user_2</td><td>24</td></tr></tbody></table><figcaption class="wp-element-caption">DBのusersテーブル</figcaption></figure>



<h3 class="wp-block-heading">省略形insert文</h3>



<p>カラムは3つになります。この場合カラムを省略すると、コードは下記になります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into users value (値,値,値);</code></pre></div>



<p>カラムを指定していた項目を省略しています。</p>



<p class="is-style-icon_announce">値の数は、テーブルのカラムの数に合わせます。</p>



<h3 class="wp-block-heading">実際にSQLで省略形insert文を使用してデータを挿入してみる</h3>



<p>今度は先程のように、下記を追加して見ましょう。</p>



<ul class="wp-block-list">
<li>id = 4</li>



<li>name = user_4</li>



<li>score = 44</li>
</ul>



<p>実際のSQLのinsert文は下記になりました。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into users value (4,&#39;user_4&#39;,44);</code></pre></div>



<p>クエリを送信すると、</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="583" height="145" src="https://sugublog.org/wp-content/uploads/2021/08/image-15.png" alt="更にテーブルにユーザーが追加された" class="wp-image-3939" srcset="https://sugublog.org/wp-content/uploads/2021/08/image-15.png 583w, https://sugublog.org/wp-content/uploads/2021/08/image-15-300x75.png 300w" sizes="(max-width: 583px) 100vw, 583px" /></figure>
</div>


<p>SQLの省略形insert文で更にユーザーが追加された事を、確認出来ました。</p>



<h2 class="wp-block-heading"> SQLのinsert文でDB（データベース）にデータを挿入する！まとめ</h2>



<p>SQLのinsert文でDBにデータを挿入できます。構文は下記です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into テーブル名 (カラム名,カラム名,カラム名,,,) value (値,値,値,,,);</code></pre></div>



<p>カラム数があっていれば、カラム名は省略可能です。省略形inset文は下記です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-sql" data-lang="SQL"><code>insert into users value (値,値,値);</code></pre></div>



<p>今回はMySQL4大命令文の内、挿入するinsert文について説明し、実際にDBにデータを挿入しました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/sql-base-insert/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
