The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,513 other followers

Archive for the ‘SQL’ Category

SQL Server, [] brackets, keywords and special characters

Posted by jpluimers on 2021/07/06

A few links for my archive:

  • [WayBack] sql server – What is the use of the square brackets [] in sql statements? – Stack Overflow answer by Michael Haren:

    The brackets are required if you use keywords or special chars in the column names or identifiers. You could name a column [First Name] (with a space)–but then you’d need to use brackets every time you referred to that column.

    The newer tools add them everywhere just in case or for consistency.

     

  • [WayBack] tsql – What characters are valid in an SQL Server database name? – Stack Overflow answer by Scott Munro:

    Delimited names – surrounded by square brackets or double quotes (if QUOTED_IDENTIFIER is set to ON) – can contain basically anything other than the delimiters themselves. It is even possible to use the delimiters within the name with some escape logic. Note though that it is only the closing escape character that must be escaped. In the first example below, the single instance of the opening escape character in the name does not need to be escaped whereas the closing escape character does have to be escaped (by replacing the single instance with two). I guess the logic here is that whatever code that is parsing these statements is looking for a closing escape character and has is not interested in nested opening escape characters.

    • [Test[Test] -> Test[Test
    • [Test]]Test] -> Test]Test

    The following is a description of the rules surrounding non delimited (nonquoted) identifier names in SQL Server 2012. It is an extract from the document Guide to Migrating from MySQL to SQL Server 2012.

    Schema Object Names

    In SQL Server 2012, an object name can be up to 128 characters long.

    Nonquoted identifier names must follow these rules:

    • The first character must be alphanumeric, an underscore (_), an at sign (@), or a number sign (#).
    • Subsequent characters can include alphanumeric characters, an underscore, an at (@) sign, a number sign, or a dollar sign.
    • The identifier must not be a Transact-SQL reserved word. Guide to Migrating from MySQL to SQL Server 2012 8
    • Embedded spaces or special characters are not allowed.

    Identifiers that start with @ or a number sign have special meanings. Identifiers starting with @ are local variable names. Those that start with a number sign are temporary table names.

    To quote an identifier name in Transact-SQL, you must use square brackets ([]).

  • [WayBack] Database Identifiers – SQL Server | Microsoft Docs:
    1. Classes of Identifiers
    2. Rules for Regular Identifiers
    3. See Also

–jeroen

 

 

Posted in Database Development, Development, SQL, SQL Server | Leave a Comment »

(nullable) rowversion (Transact-SQL) – SQL Server | Microsoft Docs

Posted by jpluimers on 2021/06/09

I was not aware there could be a nullable [WayBack] rowversion (Transact-SQL) – SQL Server | Microsoft Docs, but it is possible:

Duplicate rowversion values can be generated by using the SELECT INTO statement in which a rowversioncolumn is in the SELECT list. We do not recommend using rowversion in this manner.

A nonnullable rowversion column is semantically equivalent to a binary(8) column. A nullable rowversion column is semantically equivalent to a varbinary(8) column.

You can use the rowversion column of a row to easily determine whether the row has had an update statement ran against it since the last time it was read. If an update statement is ran against the row, the rowversion value is updated. If no update statements are ran against the row, the rowversion value is the same as when it was previously read. To return the current rowversion value for a database, use @@DBTS.

You can add a rowversion column to a table to help maintain the integrity of the database when multiple users are updating rows at the same time. You may also want to know how many rows and which rows were updated without re-querying the table.

For example, assume that you create a table named MyTest. You populate some data in the table by running the following Transact-SQL statements.

–jeroen

Posted in Database Development, Development, Software Development, SQL, SQL Server | Leave a Comment »

MSSQL – searching in DDL metadata comments

Posted by jpluimers on 2021/04/14

Some interesting queries at [WayBack] www.nlaak.com • Просмотр темы – Полезные скрипты (English translation by Google)

I have put them in the [WayBack] gist below, and expect that they should be solvable without depending on deprecated sys.sysobjects.

Related: [WayBack] sql server – Making sense of sys.objects, sys.system_objects, and sys.sysobjects? – Database Administrators Stack Exchange

–jeroen

Read the rest of this entry »

Posted in Database Development, Development, Software Development, SQL, SQL Server | Leave a Comment »

ApexSQL Refactor – Free SQL formatter | ApexSQL

Posted by jpluimers on 2021/02/09

The below configuration file haves [WayBack] ApexSQL Refactor – Free SQL formatter | ApexSQL produce quite OK formatted SQL, even for complex queries, not just for SQL Server.

So this is the second free tool I use from ApexSQL. The first one was ApexSQL, a free tool (SSMS add-in) for analyzing the execution plan of a SQL server query…

–jeroen

Read the rest of this entry »

Posted in Database Development, Development, Software Development, SQL, SQL Server | Leave a Comment »

Configure IntelliSense (SQL Server Management Studio) | Microsoft Docs

Posted by jpluimers on 2020/10/08

Not sure why, but all of a sudden, SSMS did not code-complete any table or column names any more.

This shows where that setting is [WayBack] Configure IntelliSense (SQL Server Management Studio) | Microsoft Docs.

The odd thing: updating to a more fresh 17.x version solved the problem all by itself.

Anyway, you can change the settings under the section “All Languages”, “Transact-SQL” or “XML”, each in the “General” sub-section:

–jeroen

Posted in Database Development, Development, SQL, SQL Server, SSMS SQL Server Management Studio | Leave a Comment »

 
%d bloggers like this: