使用Transact-SQL在SQL Server中创建数据库对象
Adventure Works Cycles 的数据仓库中有几个非常大的表。为改善此数据的存储,您决定对几个跨文件组的表进行分区。这样您就可以控制基础磁盘存储。 先决条件 在开始此实验之前,您必须: 使用 Transact-SQL 在 Microsoft SQL Server 数据库中创建数据库对象
Adventure Works Cycles 的数据仓库中有几个非常大的表。为改善此数据的存储,您决定对几个跨文件组的表进行分区。这样您就可以控制基础磁盘存储。
先决条件
在开始此实验之前,您必须:
使用 Transact-SQL 在 Microsoft® SQL Server® 中创建对象的经验。
实验设置
实验场景
Adventure Works Cycles 的数据仓库中有几个非常大的表。为改善此数据的存储,您决定对几个跨文件组的表进行分区。这样您就可以控制基础磁盘存储。
对几个跨文件组的表进行分区时,您希望增添功能并改善您的解决方案的性能。您决定基于订单日期分配数据,而不是随意地跨文件组分割数据。因为您只修改包含最新数据的文件组,所以这样会提高备份和还原的速度。此外,您还可以定期对文件组进行存档,以将历史数据移动到另一个表中,使活动表的大小保持在可管理的范围内。
一. 创建已分区表
在本练习中,您将创建一个分区数据仓库事实数据表。非常大的表经常需要跨几个磁盘卷存储数据。SQL Server 表无法放置在特定文件中。但是,文件组可以放置在文件中,而表可以分配给文件组。这样您就可以控制 SQL Server 中非常大的表中的数据的存储。而且,如果表跨几个文件组,定义哪些数据放置在哪个文件组中会非常有用。分区函数通过基于特定列中的值沿水平方向拆分表提供了此功能。
注意: 您可以复制此练习中所用的脚本,这些脚本位于 C:\SQLHOLS\Partitioning\Solution\Partition Processing 文件夹中的 Partition Processing.ssmssln 解决方案中。
新建 SQL Server 脚本项目
1. 从开始->所有程序菜单中的 Microsoft SQL Server 2008 程序组中启动
SQL Server Management Studio。
2. 在连接到对话框中,验证下列设置无误后单击连接:
服务器类型:数据库引擎
服务器名称:(local)
身份验证:Windows 身份验证
3. 在文件菜单上,指向新建,然后单击项目。
4. 确保选中 SQL Server 脚本,然后输入下列设置:
名称:Partition Processing
位置:C:\SQLHOLs\Partitioning\Starter
解决方案名称:Partition Processing
5. 确保选中创建解决方案的目录,然后单击确定。
6. 在解决方案资源管理器中,右键单击连接,然后单击新建连接。
7. 在连接到服务器对话框中,验证下列设置无误后单击确定:
服务器名称:(local)
身份验证:Windows 身份验证
创建文件组和文件
1. 在解决方案资源管理器中,右键单击在前面步骤中添加的连接,然后单击新建查询。
2. 右键单击 SQLQuery1.sql,然后单击重命名。
3. 键入 Files and Filegroups.sql,然后按 Enter。
4. 键入下面的代码(每个 FILENAME 参数都应单占一行)。
ALTER DATABASE [AdventureWorksDW] ADD FILEGROUP [fg2001]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILEGROUP [fg2002]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILEGROUP [fg2003]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILEGROUP [fg2004]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILE
(NAME = N'AdventureWorksDW_Data2001',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorksDW_Data2001.ndf',
SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [fg2001]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILE
(NAME = N'AdventureWorksDW_Data2002',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorksDW_Data2002.ndf',
SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [fg2002]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILE
(NAME = N'AdventureWorksDW_Data2003',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorksDW_Data2003.ndf',
SIZE = 2048KB , FILEGROWTH = 1024KB) TO FILEGROUP [fg2003]
GO
ALTER DATABASE [AdventureWorksDW] ADD FILE
(NAME = N'AdventureWorksDW_Data2004',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorksDW_Data2004.ndf',
SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [fg2004]
GO

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

What is Identity in SQL? Specific code examples are needed. In SQL, Identity is a special data type used to generate auto-incrementing numbers. It is often used to uniquely identify each row of data in a table. The Identity column is often used in conjunction with the primary key column to ensure that each record has a unique identifier. This article will detail how to use Identity and some practical code examples. The basic way to use Identity is to use Identit when creating a table.

This article will interest you if you are interested in using GIMP for pixel art creation on Windows. GIMP is a well-known graphics editing software that is not only free and open source, but also helps users create beautiful images and designs easily. In addition to being suitable for beginners and professional designers alike, GIMP can also be used to create pixel art, a form of digital art that utilizes pixels as the only building blocks for drawing and creating. How to Create Pixel Art in GIMP Here are the main steps to create pixel pictures using GIMP on a Windows PC: Download and install GIMP, then launch the application. Create a new image. Resize width and height. Select the pencil tool. Set the brush type to pixels. set up

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows
