Home Database Mysql Tutorial [SQLServer大对象]FileTable从文件系统迁移文件

[SQLServer大对象]FileTable从文件系统迁移文件

Jun 07, 2016 pm 03:19 PM
sqlserver object document system

阅读导航 从文件系统中迁移文件到FileTable 批量加载文件到FileTable 如何批量加载文件到FileTable 通过博文 [SQLServer大对象]FileTable初体验 ,已经可以将文件加载到数据库中,并查看和访问这些文件。 将文件加载到 FileTable,可以使用工具xcopy或roboco

阅读导航

从文件系统中迁移文件到FileTable

批量加载文件到FileTable

如何批量加载文件到FileTable

 

通过博文[SQLServer大对象]——FileTable初体验,已经可以将文件加载到数据库中,并查看和访问这些文件。

将文件加载到 FileTable,可以使用工具xcopy或robocopy,也可以自己编写脚本(如PowerShell)或者应用程序,复制文件到FileTable中。

现在说一说文件的迁移。

 

从文件系统中迁移文件到FileTable

迁移文件条件

    文件存储在文件系统中

    在 SQL Server 中元数据的表包含一个指向文件的指针

执行前提

要将文件迁入到 FileTable,需要将每一个文件的原始UNC路径用FileTable的UNC路径代替。

现在我们假定现有 FileTable PhotoMetadata 包含图片数据,。这个表有一个varchar(512)类型的UNC路径列,其中包含执行.jpg文件的实际路径。

将.jpg及其目录结构一起复制到FileT的根目录下。

执行

使用代码修改 PhotoMetadata 的元数据:

<span>   1:  </span><span>--  添加一个路径定位器到 PhotoMetadata。</span>
Copy after login
<span>   2:  </span><span>ALTER</span> <span>TABLE</span> PhotoMetadata <span>ADD</span> pathlocator hierarchyid;
Copy after login
<span>   3:  </span> 
Copy after login
<span>   4:  </span><span>-- 获得在文件系统中图片的根路径。</span>
Copy after login
<span>   5:  </span><span>DECLARE</span> @UNCPathRoot <span>varchar</span>(100) = <span>'\\RemoteShare\Photographs'</span>;
Copy after login
<span>   6:  </span> 
Copy after login
<span>   7:  </span><span>-- 获得FileTable的根路径。</span>
Copy after login
<span>   8:  </span><span>DECLARE</span> @FileTableRoot <span>varchar</span>(1000);
Copy after login
<span>   9:  </span><span>SELECT</span> @FileTableRoot = FileTableRootPath(<span>'dbo.PhotoTable'</span>);
Copy after login
<span>  10:  </span> 
Copy after login
<span>  11:  </span><span>-- 更新PhotoMetadata。</span>
Copy after login
<span>  12:  </span> 
Copy after login
<span>  13:  </span><span>-- 使用 FileTable 路径代替文件系统 UNC 路径。</span>
Copy after login
<span>  14:  </span><span>UPDATE</span> PhotoMetadata
Copy after login
<span>  15:  </span>    <span>SET</span> UNCPath = REPLACE(UNCPath, @UNCPathRoot, @FileTableRoot);
Copy after login
<span>  16:  </span> 
Copy after login
<span>  17:  </span><span>-- 更新 FileTable 的 pathlocator 列。 </span>
Copy after login
<span>  18:  </span><span>UPDATE</span> PhotoMetadata
Copy after login
<span>  19:  </span>    <span>SET</span> pathlocator = GetPathLocator(UNCPath);
Copy after login

批量加载文件到FileTable

对于批量操作,FileTable和其他表基本一样,但是有些需要注意的地方。

FileTable有系统定义的约束,这些约束是为了确保文件的完整性和目录空间具有可维护性。这些约束验证数据批量加载到FileTable中。由于一些大量插入操作允许忽略表约束,所以接下来的是被强制要求的。

    强制约束的批量加载操作可以像在任何其他表一样在 FileTable使用,具体操作如下:

        bcp 带 CHECK_CONSTRAINTS 子句。

        BULK INSERT 带 CHECK_CONSTRAINTS 子句。

        INSERT INTO … SELECT * FROM OPENROWSET(BULK …) 不带 IGNORE_CONSTRAINTS 子句。

    非强制约束的批量加载操作会失败,除非 FileTable 系统定义的约束已禁用,具体操作如下:

        bcp 不带 CHECK_CONSTRAINTS 子句。

        BULK INSERT 不带 CHECK_CONSTRAINTS 子句。

        INSERT INTO … SELECT * FROM OPENROWSET(BULK …) 带 IGNORE_CONSTRAINTS 子句。

 

如何批量加载文件到FileTable

可以使用多种方法批量加载文件到FileTable:

    bcp

        使用 CHECK_CONSTRAINTS 子句。

        禁用FileTable命名空间,并且不使用 CHECK_CONSTRAINTS 子句。然后重新启用FileTable命名空间。

    BULK INSERT

        使用 CHECK_CONSTRAINTS 子句。

        禁用FileTable命名空间,并且不使用 CHECK_CONSTRAINTS 子句。然后重新启用FileTable命名空间

    INSERT INTO … SELECT * FROM OPENROWSET(BULK …)

        使用 CHECK_CONSTRAINTS 子句。

        禁用FileTable命名空间,并且不使用 CHECK_CONSTRAINTS 子句。然后重新启用FileTable命名空间

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that the object named already exists in the sqlserver database How to solve the problem that the object named already exists in the sqlserver database Apr 05, 2024 pm 09:42 PM

For objects with the same name that already exist in the SQL Server database, the following steps need to be taken: Confirm the object type (table, view, stored procedure). IF NOT EXISTS can be used to skip creation if the object is empty. If the object has data, use a different name or modify the structure. Use DROP to delete existing objects (use caution, backup recommended). Check for schema changes to make sure there are no references to deleted or renamed objects.

How to import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

What to do if the sqlserver service cannot be started What to do if the sqlserver service cannot be started Apr 05, 2024 pm 10:00 PM

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

How to check sqlserver port number How to check sqlserver port number Apr 05, 2024 pm 09:57 PM

To view the SQL Server port number: Open SSMS and connect to the server. Find the server name in Object Explorer, right-click it and select Properties. In the Connection tab, view the TCP Port field.

How to recover accidentally deleted database in sqlserver How to recover accidentally deleted database in sqlserver Apr 05, 2024 pm 10:39 PM

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

Where is the sqlserver database? Where is the sqlserver database? Apr 05, 2024 pm 08:21 PM

SQL Server database files are usually stored in the following default location: Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data The database file location can be customized by modifying the database file path setting.

How to delete sqlserver if the installation fails? How to delete sqlserver if the installation fails? Apr 05, 2024 pm 11:27 PM

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

See all articles