Author’s Archive: ЈЦЅГЇП €ΘΘΚ

Home / ЈЦЅГЇП €ΘΘΚ
48 Posts

Adapted from “Unique Indexes Are Code; Non-Unique Indexes Are Data” By Daniel White, 2014/06/26

In any Excel cell that needs line-breaks, instead of using ALT-ENTER, put a placeholder {NL} in the Excel cell’s text.

Example: 123 Maple St{NL}Apt 2{NL}Sacramento,CA{NL}95818

Paste the Excel data into the SQL table as normal.

Execute this SQL statement to change the placeholders to SQL line-break characters:

update [tablename] set [fieldname] = replace([fieldname],'{NL}',CHAR(13))

Generates a unique namespace that conforms to DNS name format from the input.

Releated: Validate Format of a Domain Name post

Input formats:
If email address, the host part is used.
If URI, the primary domain name is used.
If neither of the above formats then uses the input as is.
Looks in the [Subscription] table of the specified database table for the [Namespace] column to determine uniqueness.

 

Using setvar in T-SQL

This example changes the value of the [Namespace] field for all records of all tables where the column is found.

 

SQLServerVersionQueryOutput

Working with a product that uses floats as database keys :^o
This has two solutions to generate float keys.

A typical SQL Server backup uses one “DISK =” statement in the backup SQL, which creates a single-part backup. It’s possible to split backups into multiple parts, ostensibly to spread the data over multiple disks or tapes, or to create multiple smaller files that may be more manageable than a single large one. This is done by using multiple device statements in the backup TSQL like, “… DISK = ‘c:\backups\foo1.bak, DISK = c:\backups\foo2.bak, …”.

This example creates an out-of-band, overwriting backup that is split into nine parts.

This next query gets the number of parts of a given SQL Server backup. If you wish to create a new backup that overwrites the existing one, the number of parts (devices) used to create the latest backup must be the same as the existing backup. This TSQL gets the backup’s label data, which contains the number of parts into which the backup was originally split in the [FamilyCount] field. This query would return 9 for the above backup. If a backup was created with the 64 devices (the maximum), then the [FamilyCount] field will contain 64.