{"id":2257,"date":"2016-09-18T17:09:24","date_gmt":"2016-09-18T08:09:24","guid":{"rendered":"http:\/\/1bed.allright.life\/?p=2257"},"modified":"2020-04-18T21:14:21","modified_gmt":"2020-04-18T12:14:21","slug":"post-2257","status":"publish","type":"post","link":"https:\/\/1bed.allright.life\/?p=2257","title":{"rendered":"MicrosoftSQL Server 2016 Express LocalDB \u3067\u6c17\u8efd\u306b DB \u3092\u8a66\u3059"},"content":{"rendered":"<p>PowerShell \u3092\u4f7f\u3063\u3066 DB \u306b\u3042\u3093\u306a\u3053\u3068\u3084\u3053\u3093\u306a\u3053\u3068\u3092\u8a66\u3057\u3066\u307f\u305f\u304b\u3063\u305f\u3002\u3061\u3087\u3063\u3068\u3060\u3051\u3060\u3088\u3002<\/p>\n<p>Visual Studio 2015 \u3092\u8a66\u3057\u3066\u3044\u308b\u6642\u306b\u300cLocalDB\u300d\u3068\u304b\u3044\u3046\u6587\u5b57\u5217\u3092\u898b\u305f\u899a\u3048\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u8abf\u3079\u3066\u5b9f\u969b\u306b\u8a66\u3057\u3066\u307f\u305f\u5099\u5fd8\u9332\u3002<\/p>\n<h2>MicrosoftSQL Server 2016 Express LocalDB \u3068\u306f<\/h2>\n<p>\u516c\u5f0f\u3088\u308a\u5f15\u7528<\/p>\n<blockquote>\n<p>Microsoft SQL Server 2016 Express LocalDB \u306e\u5b9f\u884c\u30e2\u30fc\u30c9\u306f\u3001\u958b\u767a\u8005\u3092\u5bfe\u8c61\u3068\u3057\u305f SQL Server Express \u306e\u5b9f\u884c\u30e2\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>LocalDB \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306b\u3088\u3063\u3066\u3001 SQL Server \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 \u30a8\u30f3\u30b8\u30f3\u306e\u958b\u59cb\u306b\u6700\u4f4e\u9650\u5fc5\u8981\u306a\u30d5\u30a1\u30a4\u30eb\u304c\u30b3\u30d4\u30fc\u3055\u308c\u307e\u3059\u3002 LocalDB \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8c\u306b\u3001\u7279\u6b8a\u306a\u63a5\u7d9a\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3057\u3066\u63a5\u7d9a\u3092\u958b\u59cb\u3067\u304d\u307e\u3059\u3002 \u63a5\u7d9a\u6642\u306b\u3001\u5fc5\u8981\u306a SQL Server \u30a4\u30f3\u30d5\u30e9\u30b9\u30c8\u30e9\u30af\u30c1\u30e3\u304c\u81ea\u52d5\u7684\u306b\u4f5c\u6210\u304a\u3088\u3073\u958b\u59cb\u3055\u308c\u308b\u305f\u3081\u3001\u8907\u96d1\u306a\u69cb\u6210\u30bf\u30b9\u30af\u3092\u884c\u308f\u306a\u304f\u3066\u3082\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002 \u958b\u767a\u8005\u30c4\u30fc\u30eb\u306b\u3088\u3063\u3066\u3001\u958b\u767a\u8005\u306f SQL Server \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 \u30a8\u30f3\u30b8\u30f3\u3092\u4f7f\u7528\u3057\u3066 Transact-SQL \u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3057\u3066\u30c6\u30b9\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001SQL Server \u306e\u5b8c\u5168\u306a\u30b5\u30fc\u30d0\u30fc \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u7ba1\u7406\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<\/blockquote>\n<p>\u4e71\u66b4\u306b\u8981\u7d04\u3059\u308b\u3068\u3001\u958b\u767a\u8005\u5411\u3051\u3067\u5fc5\u8981\u6700\u5c0f\u9650\u306e SQL Server \u3068\u3044\u3046\u3053\u3068\u304b\u306a\u3002<br \/>\n\u4fbf\u5229\u3063\u307d\u3044\u6c17\u304c\u3059\u308b\u3002<\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u7b49\u306f\u53c2\u8003\u30b5\u30a4\u30c8\u306b\u8f09\u3063\u3066\u3044\u308b\u306e\u3067\u5272\u611b\u3002Visual Studio \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u308b\u4eba\u306f\u6c17\u304c\u3064\u3044\u305f\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u305f\u308a\u3057\u306a\u3044\u304b\u306a\uff1f \u81ea\u5206\u304c\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u3059 \uff3e\uff3e\uff1b<\/p>\n<p>SqlLocalDB \u3092\u6271\u3046\u306b\u306f\u3001SqlLocalDB \u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3 (SqlLocalDB.exe) \u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<h2>SqlLocalDB \u3068\u306f<\/h2>\n<blockquote>\n<p>MicrosoftSQL Server 2016 Express LocalDB \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\u3001SqlLocalDB \u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 SqlLocalDB \u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3 (SqlLocalDB.exe) \u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304a\u3088\u3073\u958b\u767a\u8005\u304c SQL Server Express LocalDB \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u304a\u3088\u3073\u7ba1\u7406\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u30b7\u30f3\u30d7\u30eb\u306a\u30b3\u30de\u30f3\u30c9 \u30e9\u30a4\u30f3 \u30c4\u30fc\u30eb\u3067\u3059\u3002<\/p>\n<\/blockquote>\n<h2>SqlLocalDB \u3092\u4f7f\u7528\u3057\u3066 LocalDB \u3092\u5229\u7528\u3059\u308b<\/h2>\n<p>SqlLocalDB \u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3092\u4f7f\u7528\u3057\u3066\u3001LocalDB \u3092\u64cd\u4f5c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<h3>PowerShell \u3092\u8d77\u52d5<\/h3>\n<p>\u307e\u305a\u306f PowerShell \u3092\u7ba1\u7406\u8005\u30e2\u30fc\u30c9\u3067\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>\u65b0\u3057\u3044\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 <code>misono<\/code> \u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; SqlLocalDB.exe create &quot;misono&quot;\nLocalDB \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 &quot;misono&quot; \u306f\u30d0\u30fc\u30b8\u30e7\u30f3 13.0.1100.286 \u3067\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3002<\/code><\/pre>\n<h3>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b<\/h3>\n<p>\u30e6\u30fc\u30b6\u30fc\u6240\u6709\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u60c5\u5831\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; SqlLocalDB.exe info\nmisono\nMSSQLLocalDB<\/code><\/pre>\n<p>\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u3060\u3051\u3067\u5b09\u3057\u304f\u306a\u308b\u540d\u524d\u306b\u3057\u3066\u826f\u304b\u3063\u305f\u3067\u3059\u3002<\/p>\n<p>\u8a73\u7d30\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u3068\u304d\u306b\u306f\u3001\u5f15\u6570\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; SqlLocalDB.exe info misono\n\u540d\u524d:               misono\n\u30d0\u30fc\u30b8\u30e7\u30f3:         13.0.1100.286\n\u5171\u6709\u540d:\n\u6240\u6709\u8005:             \u30de\u30b7\u30f3\u540d\\\u30e6\u30fc\u30b6\u30fc\u540d\n\u81ea\u52d5\u4f5c\u6210:        \u3044\u3044\u3048\n\u72b6\u614b:              \u505c\u6b62\n\u524d\u56de\u306e\u958b\u59cb\u6642\u523b:    2016\/09\/18 0:48:42\n\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 \u30d1\u30a4\u30d7\u540d:<\/code><\/pre>\n<h3>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u8d77\u52d5\u3059\u308b<\/h3>\n<p>\u72b6\u614b\u304c\u505c\u6b62\u3057\u3066\u3044\u308b\u306e\u3067\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; SqlLocalDB.exe start misono\nLocalDB \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 &quot;misono&quot; \u304c\u958b\u59cb\u3055\u308c\u307e\u3057\u305f\u3002<\/code><\/pre>\n<p>\u72b6\u614b\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; SqlLocalDB.exe info misono\n\u540d\u524d:               misono\n\u30d0\u30fc\u30b8\u30e7\u30f3:         13.0.1100.286\n\u5171\u6709\u540d:\n\u6240\u6709\u8005:             \u30de\u30b7\u30f3\u540d\\\u30e6\u30fc\u30b6\u30fc\u540d\n\u81ea\u52d5\u4f5c\u6210:        \u3044\u3044\u3048\n\u72b6\u614b:              \u5b9f\u884c\u4e2d\n\u524d\u56de\u306e\u958b\u59cb\u6642\u523b:    2016\/09\/18 1:03:18\n\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 \u30d1\u30a4\u30d7\u540d: np:\\\\.\\pipe\\LOCALDB#\u30d1\u30a4\u30d7\u540d\\tsql\\query<\/code><\/pre>\n<p>\u72b6\u614b\u304c\u5b9f\u884c\u4e2d\u306b\u5909\u308f\u308a\u307e\u3057\u305f\u3002<\/p>\n<h3>sqlcmd \u3067\u63a5\u7d9a\u3057\u3066\u307f\u308b<\/h3>\n<p>\u79c1\u306e\u74b0\u5883\u3067\u306f <code>sqlcmd<\/code> \u3078\u30d1\u30b9\u304c\u901a\u3063\u3066\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u306e\u3067\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3068\u308a\u3042\u3048\u305a\u30d1\u30b9\u3092\u901a\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; $Env:Path += &quot;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn;&quot;<\/code><\/pre>\n<p>sqlcmd \u3067 LocalDB \u3078\u63a5\u7d9a\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PS&gt; sqlcmd -S np:\\\\.\\pipe\\LOCALDB#\u30d1\u30a4\u30d7\u540d\\tsql\\query\n1&gt;<\/code><\/pre>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3092\u6d41\u3057\u3066\u307f\u307e\u3059<\/p>\n<pre><code class=\"language-sql\">1&gt; select name, create_date from sys.databases\n2&gt; GO\nname\n         create_date\n--------------------------------\n-------- -----------------------\nmaster\n         2003-04-08 09:13:36.390\ntempdb\n         2016-09-18 01:43:38.743\nmodel\n         2003-04-08 09:13:36.390\nmsdb\n         2016-02-27 13:31:02.847\n\n(4 \u884c\u51e6\u7406\u3055\u308c\u307e\u3057\u305f)<\/code><\/pre>\n<h3>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u3084\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u305b\u305a\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 miyamiya \u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-sql\">1&gt; CREATE DATABASE miyamiya\n2&gt; GO<\/code><\/pre>\n<p>\u518d\u5ea6\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e00\u89a7\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3092\u6d41\u3057\u3066\u307f\u307e\u3059<\/p>\n<pre><code class=\"language-sql\">1&gt; select name, create_date from sys.databases\n2&gt; GO\nname\n         create_date\n--------------------------------\n-------- -----------------------\nmaster\n         2003-04-08 09:13:36.390\ntempdb\n         2016-09-18 01:43:38.743\nmodel\n         2003-04-08 09:13:36.390\nmsdb\n         2016-02-27 13:31:02.847\nmiyamiya\n         2016-09-18 02:03:18.887\n\n(5 \u884c\u51e6\u7406\u3055\u308c\u307e\u3057\u305f)<\/code><\/pre>\n<h3>sqlcmd \u304b\u3089\u629c\u3051\u308b<\/h3>\n<pre><code class=\"language-sql\">1&gt; quit<\/code><\/pre>\n<h3>PowerShell \u3067 Create Table \u3092\u6d41\u3057\u3066\u307f\u308b<\/h3>\n<p>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 misono \u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 miyamiya \u306b PowerShell \u304b\u3089\u63a5\u7d9a\u3059\u308b<\/p>\n<pre><code class=\"language-powershell\">$con = New-Object -TypeName System.Data.SqlClient.SqlConnection\n$con.ConnectionString = &quot;Server=(localdb)\\misono;Initial Catalog=miyamiya;Integrated Security=true&quot;\n\n$con.Open()\n$cmd = $con.CreateCommand()\n$cmd.CommandText = &quot;CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR(MAX))&quot;\n$cmd.ExecuteNonQuery()\n\n$con.Close()\n$cmd.Dispose()\n$con.Dispose()<\/code><\/pre>\n<h3>PowerShell \u3067 Insert \u3092\u6d41\u3057\u3066\u307f\u308b<\/h3>\n<pre><code class=\"language-powershell\">$con = New-Object -TypeName System.Data.SqlClient.SqlConnection\n$con.ConnectionString = &quot;Server=(localdb)\\misono;Initial Catalog=miyamiya;Integrated Security=true&quot;\n\n$con.Open()\n$cmd = $con.CreateCommand()\n$cmd.CommandText = &quot;INSERT INTO test(id, name) VALUES(1, &#039;hoge&#039;)&quot;\n$cmd.ExecuteNonQuery()\n$cmd.CommandText = &quot;INSERT INTO test(id, name) VALUES(2, &#039;fuga&#039;)&quot;\n$cmd.ExecuteNonQuery()\n\n$con.Close()\n$cmd.Dispose()\n$con.Dispose()<\/code><\/pre>\n<h3>PowerShell \u3067 select \u3092\u6d41\u3057\u3066\u307f\u308b<\/h3>\n<pre><code class=\"language-powershell\">$con = New-Object -TypeName System.Data.SqlClient.SqlConnection\n$con.ConnectionString = &quot;Server=(localdb)\\misono;Initial Catalog=miyamiya;Integrated Security=true&quot;\n\n$con.Open()\n$cmd = $con.CreateCommand()\n$command.CommandText = &quot;SELECT * FROM test&quot;\n$adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command\n$dataset = New-Object -TypeName System.Data.DataSet\n$adapter.Fill($dataset)\n$dataset.Tables[0]\n\n$dataset.Dispose()\n$adapter.Dispose()\n$con.Close()\n$cmd.Dispose()\n$con.Dispose()<\/code><\/pre>\n<h2>\u8003\u5bdf<\/h2>\n<p>\u5c11\u3057\u8a66\u3057\u305f\u3044\u6642\u306b\u624b\u8efd\u3067\u826f\u3055\u305d\u3046\u306a\u611f\u3058\u304c\u3059\u308b<\/p>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li><a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/hh510202.aspx\">Developer Network: SQL Server 2016 Express LocalDB<\/a><\/li>\n<li><a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/hh212961.aspx?f=255&amp;MSPPError=-2147217396\">Developer Network: SqlLocalDB \u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3<\/a><\/li>\n<li><a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/ms176061.aspx?f=255&amp;mspperror=-2147217396#Anchor_9\">Developer Network: CREATE DATABASE (SQL Server Transact-SQL) &#8211; \u4f7f\u7528\u4f8b<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell \u3092\u4f7f\u3063\u3066 DB \u306b\u3042\u3093\u306a\u3053\u3068\u3084\u3053\u3093\u306a\u3053\u3068\u3092\u8a66\u3057\u3066\u307f\u305f\u304b\u3063\u305f\u3002\u3061\u3087\u3063\u3068\u3060\u3051\u3060\u3088\u3002 Visual Studio 2015 \u3092\u8a66\u3057\u3066\u3044\u308b\u6642\u306b\u300cLocalDB\u300d\u3068\u304b\u3044\u3046\u6587\u5b57\u5217\u3092\u898b\u305f\u899a\u3048\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u8abf\u3079\u3066\u5b9f [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,6],"tags":[99,62],"class_list":["post-2257","post","type-post","status-publish","format-standard","hentry","category-database","category-program","tag-localdb","tag-powershell"],"_links":{"self":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2257"}],"version-history":[{"count":4,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2257\/revisions"}],"predecessor-version":[{"id":3145,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2257\/revisions\/3145"}],"wp:attachment":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}