隐藏

mssql localdb初识及使用

发布:2023/12/8 16:48:38作者:管理员 来源:本站 浏览次数:807

今天看一个.net开发大拿杨旭的EF .net Core 的视频,惊奇的发现其实自己机器上是有 sql server database的,一开始特别不能相信,当试着打开cmd命令行窗口 输入 sqllocaldb 这个命令,本来不抱希望能正常反应的,但没想到居然这个命令是work的!!!开心到飞起~~ 😄


   什么时候装上去的?

   不知道,我猜是安装visual studio 时候就安装上去了的。


   怎样使用?


   数据库实例名:

   (localdb)\MSSQLLocalDB


   一些命令:


   sqllocaldb c mylocaldb #创建

   sqllocaldb i mylocaldb #查看

   sqllocaldb s mylocaldb #开启

   sqllocaldb d mylocaldb #删除实例

   sqllocaldb p mylocaldb #停止实例

  


   localdb 是没有默认实例的 需要创建:


C:\Users\lifal>sqllocaldb c mylocaldb

LocalDB instance "mylocaldb" created with version 13.1.4001.0.


 


   启动数据库实例:


C:\Users\lifal>sqllocaldb s MyLocaldb

LocalDB instance "mylocaldb" started.


 


   查询数据库 实例的信息:


C:\Users\lifal>sqllocaldb

Microsoft (R) SQL Server Express LocalDB Command Line Tool

Version 13.0.1601.5

Copyright (c) Microsoft Corporation.  All rights reserved.


Usage: SqlLocalDB operation [parameters...]


Operations:


 -?

   Prints this information


 create|c ["instance name" [version-number] [-s]]

   Creates a new LocalDB instance with a specified name and version

   If the [version-number] parameter is omitted, it defaults to the

   latest LocalDB version installed in the system.

   -s starts the new LocalDB instance after it's created


 delete|d ["instance name"]

   Deletes the LocalDB instance with the specified name


 start|s ["instance name"]

   Starts the LocalDB instance with the specified name


 stop|p ["instance name" [-i|-k]]

   Stops the LocalDB instance with the specified name,

   after current queries finish

   -i request LocalDB instance shutdown with NOWAIT option

   -k kills LocalDB instance process without contacting it


 share|h ["owner SID or account"] "private name" "shared name"

   Shares the specified private instance using the specified shared name.

   If the user SID or account name is omitted, it defaults to current user.


 unshare|u ["shared name"]

   Stops the sharing of the specified shared LocalDB instance.


 info|i

   Lists all existing LocalDB instances owned by the current user

   and all shared LocalDB instances.


 info|i "instance name"

   Prints the information about the specified LocalDB instance.


 versions|v

   Lists all LocalDB versions installed on the computer.


 trace|t on|off

   Turns tracing on and off


SqlLocalDB treats spaces as delimiters. It is necessary to surround

instance names that contain spaces and special characters with quotes.

For example:

  SqlLocalDB create "My LocalDB Instance"


The instance name can sometimes be omitted, as indicated above, or

specified as "". In this case, the reference is to the default LocalDB

instance "MSSQLLocalDB".


C:\Users\lifal>sqllocaldb i

MSSQLLocalDB


C:\Users\lifal>sqllocaldb c mylocaldb

LocalDB instance "mylocaldb" created with version 13.1.4001.0.


C:\Users\lifal>

C:\Users\lifal>sqllocald0 i mylocaldb

'sqllocald0' is not recognized as an internal or external command,

operable program or batch file.


C:\Users\lifal>sqllocaldb i mylocaldb

Name:               mylocaldb

Version:            13.1.4001.0

Shared name:

Owner:              DESKTOP-052GI91\lifal

Auto-create:        No

State:              Stopped

Last start time:    5/2/2020 6:09:47 PM

Instance pipe name:


C:\Users\lifal>sqllocaldb s MyLocaldb

LocalDB instance "mylocaldb" started.


C:\Users\lifal>sqllocaldb info

MSSQLLocalDB

mylocaldb