You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Binary data types of either fixed length or variable length.
30
30
31
31
## Arguments
32
-
**binary**[ ( *n* ) ]
33
-
Fixed-length binary data with a length of *n* bytes, where *n* is a value from 1 through 8,000. The storage size is *n* bytes.
32
+
**binary**[ ( _n_ ) ]
33
+
Fixed-length binary data with a length of _n_ bytes, where _n_ is a value from 1 through 8,000. The storage size is _n_ bytes.
34
34
35
-
**varbinary**[ ( *n* | **max**) ]
36
-
Variable-length binary data. *n* can be a value from 1 through 8,000. **max** indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for **varbinary** is **binary varying**.
35
+
**varbinary**[ ( _n_ | **max**) ]
36
+
Variable-length binary data. _n_ can be a value from 1 through 8,000. **max** indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for **varbinary** is **binary varying**.
37
37
38
38
## Remarks
39
-
When *n*is not specified in a data definition or variable declaration statement, the default length is 1. When *n* is not specified with the CAST function, the default length is 30.
39
+
The default length is 1 when _n_ isn't specified in a data definition or variable declaration statement. When _n_ isn't specified with the CAST function, the default length is 30.
40
40
41
41
| Data type | Use when ... |
42
42
| --- | --- |
@@ -46,11 +46,23 @@ When *n* is not specified in a data definition or variable declaration statement
46
46
47
47
48
48
## Converting binary and varbinary data
49
-
When data is converted from a string data type (**char**, **varchar**, **nchar**, **nvarchar**, **binary**, **varbinary**, **text**, **ntext**, or **image**) to a **binary** or **varbinary** data type of unequal length, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] pads or truncates the data on the right. When other data types are converted to **binary** or **varbinary**, the data is padded or truncated on the left. Padding is achieved by using hexadecimal zeros.
49
+
When converting data from a string data type to a **binary** or **varbinary** data type of unequal length, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] pads or truncates the data on the right. These string data types are:
50
+
51
+
***char**
52
+
***varchar**
53
+
***nchar**
54
+
***nvarchar**
55
+
***binary**
56
+
***varbinary**
57
+
***text**
58
+
***ntext**
59
+
***image**
60
+
61
+
When other data types are converted to **binary** or **varbinary**, the data is padded or truncated on the left. Padding is achieved by using hexadecimal zeros.
50
62
51
-
Converting data to the **binary** and **varbinary** data types is useful if **binary** data is the easiest way to move around data. Converting any value of any type to a binary value of large enough size and then back to the type, always results in the same value if both conversions are taking place on the same version of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. The binary representation of a value might change from version to version of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].
63
+
Converting data to the **binary** and **varbinary** data types is useful if **binary** data is the easiest way to move around data. At some point, you might convert a value type to a binary value of large enough size and then convert it back. This conversion always results in the same value if both conversions are taking place on the same version of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. The binary representation of a value might change from version to version of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].
52
64
53
-
You can convert **int**, **smallint**, and **tinyint** to **binary** or **varbinary**, but if you convert the **binary** value back to an integer value, this value will be different from the original integer value if truncation has occurred. For example, the following SELECT statement shows that the integer value `123456` is usually stored as a binary `0x0001e240`:
65
+
You can convert **int**, **smallint**, and **tinyint** to **binary** or **varbinary**. If you convert the **binary** value back to an integer value, this value will be different from the original integer value if truncation has occurred. For example, the following SELECT statement shows that the integer value `123456` is stored as a binary `0x0001e240`:
A **hierarchyid** that is the node that represents the level of the hierarchy that is to be modified.
42
42
43
-
*newRoot*
44
-
A **hierarchyid** that represents the node that will replace the *oldRoot* section of the current node in order to move the node.
43
+
_newRoot_
44
+
A **hierarchyid** that represents the node. Replace the _oldRoot_ section of the current node to move the node.
45
45
46
46
## Return Types
47
47
**SQL Server return type:hierarchyid**
48
48
49
49
**CLR return type:SqlHierarchyId**
50
50
51
51
## Remarks
52
-
Can be used to modify the tree by moving nodes from *oldRoot* to *newRoot*. GetReparentedValue can be used to move a node of a hierarchy to a new location in the hierarchy. The **hierarchyid** data type represents but does not enforce the hierarchical structure. Users must ensure that the hierarchyid is appropriately structured for the new location. A unique index on the **hierarchyid** data type can help prevent duplicate entries. For an example of moving an entire subtree, see [Hierarchical Data (SQL Server)](../../relational-databases/hierarchical-data-sql-server.md).
52
+
Used to modify the tree by moving nodes from _oldRoot_ to _newRoot_. GetReparentedValue is used to move a hierarchy node to a new location in the hierarchy. The **hierarchyid** data type represents but doesn't enforce the hierarchical structure. Users must ensure that the hierarchyid is appropriately structured for the new location. A unique index on the **hierarchyid** data type can help prevent duplicate entries. For an example of moving an entire subtree, see [Hierarchical Data (SQL Server)](../../relational-databases/hierarchical-data-sql-server.md).
53
53
54
54
## Examples
55
55
56
56
### A. Comparing two node locations
57
-
The following example shows the current hierarchyid of a node. It also shows what the **hierarchyid** of the node would be if the node were moved to become a descendant of the **@NewParent** node. It uses the `ToString()` method to show the hierarchical relationships.
57
+
The following example shows the current hierarchyid of a node. It also shows what the **hierarchyid** of the node would be if you move the node to become a descendant of the **@NewParent** node. It uses the `ToString()` method to show the hierarchical relationships.
0 commit comments