The following problem arose, in the case of the absence of data in the table, the result of the maximum value query in the field will output a value of null, of course, you can handle the result in the program, but it is significantly easier to assign this functionality to a script.
Adding Records to a Table Ignoring IDENTITY: -- Enable SET IDENTITY_INSERT tableA ON -- You must specify the full list of columns for INSERT: INSERT Into tableA ([id], [c2], [c3], [c4], [c5] ) SELECT [id], [c2], [c3], [c4], [c5] FROM tableB...
Команды манипулирования данными SELECT , UPDATE , DELETE работают сразу с группами строк. Эти группы, вплоть до отдельных строк, можно выбрать с помощью опции WHERE. А если надо перебрать строки некоторой таблицы последовательно, одну за др…
A useful example of changing the encoding (COLLATION) on an already created database. In this example, the Russian encoding is set: Cyrillic_General_CI_AS USE master; GO -- Switching the DB to single-user mode ALTER DATABASE [database_name] SET…
Here is an example of how you can make a script in MSSQL work correctly with dates regardless of regional settings and date format. I personally implemented it in the following way: In the script, write the date as follows: Where data is a string of the following type: - This is the format of the date indicated by the number 120. Therefore, the server will not confuse the month with the day, etc.
Example of creating a SEQUENCE in MSSQL: CREATE SEQUENCE [dbo].[CardNum] AS [bigint] START WITH 1 INCREMENT BY 1 MINVALUE -9223372036854775808 MAXVALUE 9223372036854775807 CACHE GO This script will create a SEQUENCE…
To enable xp_cmdshell usage in MSSQL, you need to: -- Allow changing advanced options. EXEC sp_configure '\show advanced options\', 1 GO -- Update the current configured value for advanced options...
Restarting MSSQL Server on Linux (Ubuntu). Microsoft recommends restarting the server as follows: -- Get service status sudo systemctl status mssql-server -- Stop service sudo systemctl stop mssql-server -- Start service...