SQL Server Express

本页使用了标题或全文手工转换,现处于中国大陆简体模式
求闻百科,共笔求闻
Microsoft SQL Server Express
在一台Windows Server 2019VM上安装SQL Server 2017 Express的画面缩图。
在一台Windows Server 2019VM上安装SQL Server 2017 Express的画面缩图。
开发者微软
稳定版本
SQL Server 2017 Express
(2017年11月6日,​6年前​(2017-11-06
编程语言C语言C++
操作系统Microsoft WindowsLinux
系统平台IA-32IA-64
> 512 MB RAM
.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)的订阅端。

功能与限制

SQL Server Express提供了付费的完整版本的多项功能[3],然而其技术限制使之无法适用于大规模的部署。这两个版本的差异在于:

  • 资料库的大小限制:对SQL Server 2008 R2 Express、SQL Server 2012 Express、SQL Server 2014 Express、SQL Server 2016 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包括了几个数据库管理的图形用户界面工具:

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:比标准版本更轻便的数据库。lightweight version of Express Edition with all of its programmability features, but runs in user mode。从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包括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>

编程接口

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;";                
            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]. 
  2. About the SQL Server License Terms - SQL Server | Microsoft Docs. Msdn.microsoft.com. 2017-05-24 [2019-04-03]. 
  3. Disable SQL Server VSS Writer service. [2019-06-06] (英语). 
  4. Features Supported by the Editions of SQL Server 2008 R2. [2010-06-22]. 
  5. Compare Edition Features. [2019-06-06]. 
  6. SQL Server Express with Advanced Services Features. Microsoft. [2012-03-28]. 
  7. How SQL Server 2005 Express Edition determines the CPU count and uses the CPUs during processing. MSDN. 2008-11 [2008-11-25]. 
  8. The SQL Server 2000 Workload Governor. MSDN. 2004-01 [2007-01-15] (英语). 
  9. Download Microsoft® SQL Server® 2012 Service Pack 1 (SP1) Express from Official Microsoft Download Center. Microsoft.com. 2012-11-09 [2019-04-03]. 
  10. Download Microsoft SQL Server 2005 Express Edition from Official Microsoft Download Center. [2012-12-26]. 
  11. 11.0 11.1 Microsoft Support Lifecycle (SQL Server 2005). [2012-12-26]. 
  12. Microsoft SQL Server 2005 Express Edition. Microsoft Download Center. [2017-04-07]. 
  13. Download Microsoft SQL Server 2008 Express from Official Microsoft Download Center. [2012-12-26]. 
  14. 14.0 14.1 Microsoft Support Lifecycle (SQL Server 2008). [2012-12-26]. 
  15. Download Microsoft® SQL Server® 2008 Express from Official Microsoft Download Center. Microsoft.com. 2009-02-08 [2019-04-03]. 
  16. Download Microsoft SQL Server 2008 R2 - Express from Official Microsoft Download Center. [2012-12-26]. 
  17. 17.0 17.1 Microsoft Support Lifecycle (SQL Server 2008 R2). [2012-12-26]. 
  18. Hardware and Software Requirements for Installing SQL Server 2008 R2. msdn.microsoft.com. [2017-10-16] (英语). 
  19. Download Microsoft® SQL Server® 2012 Express from Official Microsoft Download Center. [2012-12-26]. 
  20. 20.0 20.1 Microsoft Support Lifecycle (SQL Server 2012). [2012-12-26]. 
  21. Hardware and Software Requirements for Installing SQL Server 2012. [2017-06-06]. 
  22. Microsoft® SQL Server® 2012 SP2 Express. Microsoft Download Center. [2017-04-07]. 
  23. Download Microsoft SQL Server 2014 Express. [2014-04-11]. 
  24. 24.0 24.1 Microsoft Support Lifecycle (SQL Server 2014). [2014-04-11]. 
  25. Hardware and Software Requirements for Installing SQL Server 2014. [2017-06-30]. 
  26. Microsoft® SQL Server® 2014 Express. Microsoft Download Center. [2017-04-08]. 
  27. Download Microsoft SQL Server 2016 Express. [2016-07-02]. 
  28. 28.0 28.1 Microsoft Support Lifecycle (SQL Server 2016). [2014-10-29]. 
  29. Download Microsoft SQL Server 2017 Express. [2019-06-06]. 
  30. 30.0 30.1 Microsoft Support Lifecycle (SQL Server 2017). [2019-06-06]. 
  31. Navicat Premium for OSX + SQL Server Express. Navicat Community. 2014-01-08 [2019-07-09] (英语). 

参看

外部链接

Template:MS DevTools