SQL Server Express

维基百科,自由的百科全书

这是SQL Server Express当前版本,由imported>Raymon090编辑于2025年12月6日 (六) 08:05。这个网址是本页该版本的固定链接。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
跳转到导航 跳转到搜索
Microsoft SQL Server Express
在一台Windows Server 2019VM上安裝SQL Server 2017 Express的畫面縮圖。
在一台Windows Server 2019VM上安裝SQL Server 2017 Express的畫面縮圖。
開發者微软
当前版本
    Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value)
    源代码库
    • {{URL|example.com|可选的显示文本}}
    Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value)
    编程语言C语言C++
    引擎
      Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value)
      操作系统Microsoft WindowsLinux
      平台IA-32IA-64
      > 512 MB RAM
      .NET Framework 4.0英语.NET Framework 4.0[1]
      语言英文、中文、法文、德文、意大利文、日文、韓文、巴西葡文、俄文及西班牙文
      类型关系数据库管理系統
      许可协议专有软件[2]
      网站www.microsoft.com/en-us/sql-server/sql-server-editions-express

      Microsoft SQL Server Express微软公司所開發的关系数据库產品SQL Server的免費下載版本,可自由下載、分發(需經註冊)及使用。這個版本的設計是專門為嵌入式系统或較小型的程式而設計。本產品可遡源至過往隨同SQL Server 2000軟件分發的Microsoft Database Engine (MSDE),用以讓程式開發者在其測試其程式時建立一個系統需求較低的測試環境。自SQL Server 2005開始,本產品改用現時的名稱。

      它繼承了多數的SQL Server功能與特性,像是Transact-SQLSQL CLR等,相當適合使用在小型的網站,或者是小型的桌面型應用程式,它也可以和 SQL Server 整合,作為資料庫複製英语Replication (computing)#DATABASE(Replication)的訂閱端。

      功能与限制[编辑]

      SQL Server Express提供了付費的完整版本的多項功能[3],然而其技術限制使之無法適用於大規模的部署。這兩個版本的差異在於:

      • 資料庫的大小限制:对SQL Server 2008 R2 Express、SQL Server 2012 Express、SQL Server 2014 Express、SQL Server 2016 Express、SQL Server 2019 Express单个資料庫的大小限制最大為 10 GB[4];而在較早期的SQL Server 2005 Express 和SQL Server 2008 Express 上,单个資料庫的大小限制最大為4 GB。即使如此,亦已比最初MSDE版本的2 GB要多。而且這個大小的限制只有在資料檔案上,交易記錄檔則不受此限。
      • 沒有SQL Agent服务[5][6]:若要做排程服務必須自己寫程式。
      • 硬體方面的人為限制:
        • 允許在多核心的電腦上使用,但只會使用一個CPU核心來運算[7]。這在具有多核心CPU的電腦上會造成浪費。MSDE 最高可以支援二顆 CPU核心。
        • 可使用的記憶體量最高只有 1GB。而全功能标准版至少使用4GB内存。

      MSDE有一个并发工作负债监控器并限制在少量用户并发访问,SQL Server Express没有这个并发限制[8]

      SQL Server Express包括了几个数据库管理的图形用户界面工具:

      • SQL Server Management Studio - 2012 SP1開始;[9] 在此之前,僅提供「SQL Server Management Studio Express」的精簡版本
      • SQL Server Configuration Manager
      • SQL Server Surface Area Configuration tool
      • SQL Server Business Intelligence Development Studio

      MSDE則沒有管理介面

      SQL Server Express不包括全功能标准版的几个工具:

      SQL Server Express的各版本是可以远程连接的,但需要用户做一定的配置。

      過往版本[编辑]

      Microsoft SQL Server Express Version History
      版本號碼 發行日期 主流支援完結日期 延伸支援完結日期 支援作業系統
      SQL Server 2005 Express Edition 2005-11-07[10] 2011-04-12[11] 2016-04-12[11] Windows 2000 Service Pack 4, Windows XP Service Pack 2, Windows Server 2003 Service Pack, Windows 7 Service Pack 1 (only SQL Server 2005 Express Edition SP4)[12]
      SQL Server 2008 Express 2009-02-08[13] 2014-07-08[14] 2019-07-09[14] Windows XP Service Pack 2, Windows XP Service Pack 3, Windows Vista, Windows Vista Service Pack 1, Windows Server 2003 Service Pack 2, Windows Server 2008[15]
      SQL Server 2008 R2 Express 2010-04-16[16] 2014-07-08[17] 2019-07-09[17] Windows XP, Windows Vista, Windows 7, Windows 8, Windows Server 2003, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2[18]
      SQL Server 2012 Express 2012-05-14[19] 2017-07-11[20] 2022-07-12[20] Windows Vista Service Pack 2, Windows 7, Windows 7 Service Pack 1, Windows 8, Windows 8.1, Windows Server 2008,[21] Windows Server 2008 R2, Windows Server 2008 R2 SP1, Windows Server 2012, Windows Server 2012 R2[22]
      SQL Server 2014 Express 2014-04-01[23] 2019-07-09[24] 2024-07-09[24] Windows 7 Service Pack 1, Windows 8, Windows 8.1, Windows 10, Windows Server 2008 SP2,[25] Windows Server 2008 R2 SP1, Windows Server 2012, Windows Server 2012 R2[26]
      SQL Server 2016 Express 2016-06-01[27] 2021-07-13[28] 2026-07-14[28] Windows 8, Windows 8.1, Windows 10, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016
      SQL Server 2017 Express 2017-09-29[29] 2022-10-11[30] 2027-10-12[30] Windows 8, Windows 8.1, Windows 10, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016*,
      Red Hat Enterprise Linux 7.3 or 7.4, SUSE Enterprise Linux Server v12 SP2, Ubuntu 16.04LTS,
      Docker Engine 1.8+ (on Windows, Mac, or Linux)
      • 並不包括 Windows Server 2016 "Essentials" Edition

      安裝版本[编辑]

      SQL Server Express 2017 或 2019,SQL Server Express有三款安裝版本:

      • 標準的SQL Server Express,或称Express Core: SQL Server Engine only
      • 高級版本(with Advanced Services),或称Express Advanced:还包括有Reporting services及全文檢索(Full Text Service),在舊版本均包括在標準安裝版本內。
      • LocalDB:比標準版本更輕便的數據庫。具有全部的编程特性,但在用户模式下运行。只能在本地连接数据库。从SQL Server 2012版开始有了LocalDB。在Visual Studio 2019安装中,带有SQL Server Express 2016 LocalDB

      資料庫管理工具[编辑]

      • Navicat for SQL Server是一套付費軟體,專為Microsoft SQL Server設計的強大資料庫管理及開發工具。它可以用於任何版本的SQL Server資料庫(包括SQL Server Express[31]),並支援大部份SQL Server的功能,包括觸發器、索引、檢視等。
      • SQL Server Management Studio微軟團隊開發的免費GUI連線工具,強大且優秀的管理介面,容易上手。

      到服务器的连接[编辑]

      SQL Server包括Express版本,有3种到数据库服务器的连接(connection)方式:

      • 共享内存:仅限于本地访问
      • 命名管道:
      • TCP/IP通信:

      其中后两种需要在SQL Server Configuration Manager软件中,SQL Server Network Configuration下的“Protocols for SQLEXPRESS”,把Nameed Pipes与TCP/IP手工置为Enable。对于第三种,还需要在上述的配置时,在TCP/IP Properties的IP Addresses中把IPALL的“TCP Port”设为1433.

      工具[编辑]

      • SQL Server Management Studio Express,可用來管理 SQL Server Express 實體。
      • SQL Server Reporting Service Express,簡易版的 SQL Server Reporting Service。
      • SQL Server Configuration Manager,可用來管理 SQL Server Express 的連線組態與服務。
      • Business Intelligence Development Studio Express,可用來開發 Reporting Service Express 的報表。
      • 命令行工具sqlcmd,如下:
      $sqlcmd -S thisisaserver.com -U username
      Password:
      1> SELECT name FROM SYSOBJECTS WHERE xtype = 'U'
      2> GO
      name
      --------
      EquitySecMstr
      (1 rows affected)
      1>
      

      LocalDB[编辑]

      LocalDB的全称是Microsoft SQL Server Express LocalDB。

      安装[编辑]

      从Microsoft下载的SqlLocalDB.msi约54MB。也可以使用Microsoft SQL Server Express的安装程序,在第一页选择第3项“Download Media”,随后在下一页选择第3项“localDB(54MB)”即可下载。

      使用[编辑]

      命令行工具SqlLocalDB,用于创建和管理LocalDB的实例[32]

      C:\> SqlLocalDb info	
      #输出默认实例名字:MSSQLLocalDB			
      
      #创建一个实例(相当于一个server):
      C:\> SqlLocalDb create "MyInstance"	
      #输出:LocalDB instance "MyInstance" created with version 15.0.2000.5.
      
      C:\> sqllocaldb info "MyInstance"
      #输出:
      #Name:               MyInstance
      #Version:            15.0.2000.5
      #Shared name:
      #Owner:              MyDomainName\MyUserName
      #Auto-create:        No
      #State:              Stopped
      #Last start time:    2022/3/9 19:04:41
      #Instance pipe name:
      
      C:\> sqllocaldb start "MyInstance"
      #输出: LocalDB instance "MyInstance" started.
      #类似的,可以有:
      #C:\> SqlLocalDb stop "MyInstance"
      #C:\> SqlLocalDb delete "MyInstance"
      

      系统数据库文件存储于本地AppData路径下,通常为C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\

      LocalDB 是在Windows当前用户的用户进程中运行。而SQL Server Express是作为Windows Service运行。所以,LocalDB的数据存储是Windows用户私有的。在Visual Studio启动IIS Express也是当前用户的用户进程执行,所以可以访问LocalDB。[33]

      把私有的数据存储变为共享实例。例如,原存储为“(localdb)\v11.0”:

      sqllocaldb share v11.0 IIS_DB
      

      现在为公共名字IIS_DB。该电脑所有用户均可以用“(localdb)\.\IIS_DB”访问该实例。注意,名字中的前缀“\.”表示这是共享实例名字。即其保存的文件的路径不会放在特定用户的documents目录中。连接字符串可为:

      Data Source=(localdb)\.\IIS_DB;Initial Catalog=OldFashionedDB;Integrated Security=True
      

      在Visual Studio中通过 SQL Server Object Explorer 连接上述localDB实例,在query窗口执行下述脚本可以授予“”账号数据实例的管理员权限:

      create login [IIS APPPOOL\ASP.NET v4.0] from windows;
      exec sp_addsrvrolemember N'IIS APPPOOL\ASP.NET v4.0', sysadmin
      

      SQLCMD使用的连接字符串[编辑]

      C:\>sqlcmd -S "(localdb)\MyInstance" 就可以在交互环境下执行查询:

      SELECT @@VERSION;
      GO
      CREATE DATABASE blat;
      GO
      USE blat;
      GO
      CREATE TABLE dbo.splunge(Mort int);
      GO
      INSERT dbo.Splune(Mort) VALUES(1);
      SELECT * FROM dbo.splunge;
      GO
      

      Microsoft SQL Server Management Studio连接LocalDB[编辑]

      Server Name使用(localdb)\MyInstance

      编程接口[编辑]

      ADO.Net[编辑]

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Data;
      using System.Data.SqlClient;
      
      namespace Connection
      {
          class Program
          {
              static void Main(string[] args)
              {
                  //构造连接字符串
                  SqlConnectionStringBuilder connStr = new SqlConnectionStringBuilder();
                  connStr.DataSource = @".\SQLEXPRESS";
                  connStr.InitialCatalog = "master";
                  connStr.IntegratedSecurity = true;
      
                  SqlConnection conn = new SqlConnection();//创建连接对象
                  conn.ConnectionString = connStr.ConnectionString;//设置连接字符串
      
                  conn.Open();//打开连接
      
                  if(conn.State == ConnectionState.Open)
                  {
                      Console.WriteLine("Database is linked.");
                      Console.WriteLine("\nDataSource:{0}",conn.DataSource);
                      Console.WriteLine("Database:{0}",conn.Database);
                      Console.WriteLine("ConnectionTimeOut:{0}",conn.ConnectionTimeout);
                  }
      
                  conn.Close();//关闭连接
                  conn.Dispose();//释放资源
      
                  if(conn.State == ConnectionState.Closed)
                  {
                      Console.WriteLine("\nDatabase is closed.");
                  }
      
                  Console.Read();
              }
          }
      }
      

      对于较高版本,如SQL Server Express大于版本2010的,可以通过在Visual Studio,依次点击“视图”(菜单栏)->“服务器资源管理器(Server Explorer)”,进入“服务器资源管理器”窗口。右键点击“数据连接(Data Connection)”,在弹出的上下文菜单中选择“添加连接(Add Connection)”,在弹出的窗口中将Data Source选择为Microsoft SQL Server,“服务器名”设置为(LocalDb)\MSSQLLocalDB,附加服务器文件为具体的mdf文件并点击确定。此时,通过Microsoft SQL Server(SQL Client)方式访问指定的mdf文件。

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Data;
      using System.Data.SqlClient;
      
      namespace ConsoleApp
      {
          class Program
          {
              static void Main(string[] args)
              {
                  System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
                  connection.ConnectionString =
                      @"Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=D:\apps\Documents\NORTHWND.mdf;Integrated Security = True;Connect Timeout = 30;";
                    //@"Data Source=(localdb)\MyInstance;InitialCatalog =blat;Integrated Security = True;Connect Timeout = 30;";
                  connection.Open();
                  if (connection.State == ConnectionState.Open)
                  {
                      Console.WriteLine("Database is linked.");
                      Console.WriteLine("DataSource:{0}", connection.DataSource);
                      Console.WriteLine("Database:{0}", connection.Database);
                      Console.WriteLine("ConnectionTimeOut:{0}", connection.ConnectionTimeout);
                  }
                  SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Employees", connection);
                  DataTable table = new DataTable();
                  adapter.Fill(table);
                  var result = (from row
                                in table.Rows.Cast<DataRow>()
                                select
                                new { ID = (int)row[0], LastName = (string)row[1], FirstName = (string)row[2] });
                  result.ToList().ForEach(x => Console.WriteLine($"{x.ID},{x.LastName},{x.FirstName}"));
              }
          }
      }
      

      对于较低版本,如SQL Server Express 2005的mdf文件,可以直接用如下connection string打开访问(可能需要administrator权限):

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Data;
      using System.Data.SqlClient;
      
      namespace ConsoleApp
      {
          class Program
          {
              static void Main(string[] args)
              {
                  System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
                  connection.ConnectionString =
                      @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\apps\Documents\NORTHWND.mdf;Integrated Security = True;Connect Timeout = 30;";                
                  connection.Open();
                  if (connection.State == ConnectionState.Open)
                  {
                      Console.WriteLine("Database is linked.");
                      Console.WriteLine("DataSource:{0}", connection.DataSource);
                      Console.WriteLine("Database:{0}", connection.Database);
                      Console.WriteLine("ConnectionTimeOut:{0}", connection.ConnectionTimeout);
                  }
              }
          }
      }
      

      Python[编辑]

      需要安装pymssql包

      from sqlalchemy import create_engine
      import pandas as pd
       
      user = 'username'
      pwd = 'password'
      url = 'thisisaserver.com'
      port = 1433
      db = 'database'
      engine = create_engine(f'mssql+pymssql://{user}:{pwd}@{url}:{port}/{db}')
      
      sql_stmt = "SELECT name FROM SYSOBJECTS WHERE xtype = 'U'"
      pd.read_sql_query(sql_stmt, engine)
      

      參考資料[编辑]

      1. ^ Hardware and Software Requirements for Installing SQL Server 2014 - SQL Server | Microsoft Docs. Msdn.microsoft.com. [2019-04-03]. (原始内容存档于2017-05-27). 
      2. ^ About the SQL Server License Terms - SQL Server | Microsoft Docs. Msdn.microsoft.com. 2017-05-24 [2019-04-03]. (原始内容存档于2017-12-11). 
      3. ^ Disable SQL Server VSS Writer service. [2019-06-06]. (原始内容存档于2017-09-28) (English). 
      4. ^ Features Supported by the Editions of SQL Server 2008 R2. [2010-06-22]. (原始内容存档于2010-09-27). 
      5. ^ Compare Edition Features. [2019-06-06]. (原始内容存档于2011-07-17). 
      6. ^ SQL Server Express with Advanced Services Features. Microsoft. [28 March 2012]. (原始内容存档于2016-03-17). 
      7. ^ How SQL Server 2005 Express Edition determines the CPU count and uses the CPUs during processing. MSDN. November 2008 [2008-11-25]. (原始内容存档于2008-12-11). 
      8. ^ The SQL Server 2000 Workload Governor. MSDN. 2004-01 [2007-01-15]. (原始内容存档于2007-04-23) (English). 
      9. ^ Download Microsoft® SQL Server® 2012 Service Pack 1 (SP1) Express from Official Microsoft Download Center. Microsoft.com. 2012-11-09 [2019-04-03]. (原始内容存档于2019-04-03). 
      10. ^ Download Microsoft SQL Server 2005 Express Edition from Official Microsoft Download Center. [26 December 2012]. (原始内容存档于2013-03-07). 
      11. ^ 11.0 11.1 Microsoft Support Lifecycle (SQL Server 2005). [26 December 2012]. (原始内容存档于2013-04-04). 
      12. ^ Microsoft SQL Server 2005 Express Edition. Microsoft Download Center. [2017-04-07]. (原始内容存档于2017-04-08). 
      13. ^ Download Microsoft SQL Server 2008 Express from Official Microsoft Download Center. [26 December 2012]. (原始内容存档于2013-03-06). 
      14. ^ 14.0 14.1 Microsoft Support Lifecycle (SQL Server 2008). [26 December 2012]. (原始内容存档于2013-04-03). 
      15. ^ Download Microsoft® SQL Server® 2008 Express from Official Microsoft Download Center. Microsoft.com. 2009-02-08 [2019-04-03]. (原始内容存档于2019-04-03). 
      16. ^ Download Microsoft SQL Server 2008 R2 - Express from Official Microsoft Download Center. [26 December 2012]. (原始内容存档于2013-03-05). 
      17. ^ 17.0 17.1 Microsoft Support Lifecycle (SQL Server 2008 R2). [26 December 2012]. (原始内容存档于2013-04-04). 
      18. ^ Hardware and Software Requirements for Installing SQL Server 2008 R2. msdn.microsoft.com. [2017-10-16]. (原始内容存档于2017-10-16) (English). 
      19. ^ Download Microsoft® SQL Server® 2012 Express from Official Microsoft Download Center. [26 December 2012]. (原始内容存档于2013-03-07). 
      20. ^ 20.0 20.1 Microsoft Support Lifecycle (SQL Server 2012). [26 December 2012]. (原始内容存档于2013-04-04). 
      21. ^ Hardware and Software Requirements for Installing SQL Server 2012. [6 June 2017]. (原始内容存档于2017-11-11). 
      22. ^ Microsoft® SQL Server® 2012 SP2 Express. Microsoft Download Center. [2017-04-07]. (原始内容存档于2017-04-08). 
      23. ^ Download Microsoft SQL Server 2014 Express. [11 April 2014]. (原始内容存档于2014-04-13). 
      24. ^ 24.0 24.1 Microsoft Support Lifecycle (SQL Server 2014). [11 April 2014]. (原始内容存档于2014-07-23). 
      25. ^ Hardware and Software Requirements for Installing SQL Server 2014. [30 June 2017]. (原始内容存档于2017-05-27). 
      26. ^ Microsoft® SQL Server® 2014 Express. Microsoft Download Center. [2017-04-08]. (原始内容存档于2017-05-04). 
      27. ^ Download Microsoft SQL Server 2016 Express. [2016-07-02]. (原始内容存档于2016-08-09). 
      28. ^ 28.0 28.1 Microsoft Support Lifecycle (SQL Server 2016). [2014-10-29]. (原始内容存档于2014-07-23). 
      29. ^ Download Microsoft SQL Server 2017 Express. [2019-06-06]. (原始内容存档于2019-06-17). 
      30. ^ 30.0 30.1 Microsoft Support Lifecycle (SQL Server 2017). [2019-06-06]. (原始内容存档于2019-01-19). 
      31. ^ Navicat Premium for OSX + SQL Server Express. Navicat Community. 2014-01-08 [2019-07-09]. (原始内容存档于2019-07-09) (English). 
      32. ^ SqlLocalDB Utility in Microsoft Docs. [2022-03-10]. (原始内容存档于2021-12-14). 
      33. ^ Using LocalDB with Full IIS, Part 2: Instance Ownership, source from MSDN. [2022-07-29]. (原始内容存档于2022-07-29). 

      參看[编辑]

      外部連結[编辑]