I uploaded the SQL Server Error Log file with .log extension while configuring custom log in the Log Analytics Workspace. After I uploaded the log file when I try to query with Custom Log name it is returning 0 results.
Log Analytics Custom Logs
SQL Server 2019/PolyBase with DB2
Hello,
I am aware that it is possible to use PolyBase with SQL Server 2019 and DB2 through an ODBC driver.
Does anyone have any experience they can share with me about how well that works? Any advocation on an ODBC driver to use with DB2? I know that IBM has its own, but I see that CData has one too. Perhaps one OBDC driver is better than the other in this setup.
Further, does anyone has any experience they can share configuring this scenario in a scale-out format?
Lastly -- Does anyone know if Microsoft intends to support native PolyBase connectivity to DB2 in a future release?
I much appreciate any information anyone can offer!
Thanks!
CHECKDB job failed
Hi All,
The checkdb job failed with below error:
Unspecified error occurred on SQL Server. Connection may have been terminated by the server. [SQLSTATE HY000] (Error 0) Cannot continue the execution because the session is in the kill state. [SQLSTATE HY000] (Error 596). The step failed.
On further checking the logs, got below OS related error:
//
D:\DATA\DB1_Data.mdf_MSSQL_DBCC16: Operating system error 665(The requested operation could not be completed due to a file system limitation) encountered.
The operating system returned error 665(The requested operation could not be completed due to a file system limitation) to SQL Server during a write at
offset 0x00006c4e40e000 in file 'D:\DATA\DB1_Data.mdf_MSSQL_DBCC16'. Additional messages in the SQL Server error log and system event log may provide more detail.
This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check
(DBCC CHECKDB).
This error can be caused by many factors; for more information, see SQL Server Books Online.
DBCC CHECKDB (DB1) WITH no_infomsgs executed by GEINDSYS-AMER\502765841 terminated abnormally due to error state 6. Elapsed time: 6 hours 5 minutes 51 seconds.
//
Could anyone help me understand whats the issue & help with the resolution steps.
i would like to abstract a database qualifier
hi we run 2014 std. we have 2 dbs (staging and warehouse) that are always on the same server and we often reference both in certain procs. the procs are always on staging.
in order to have multiple environments set up for development purposes, i'll often combine the tables from each (staging and warehouse) in one local db, call it x. and simulate real life by not qualifying queries targeted for staging but prefixing queries going to warehouse with x.dbo....
for my testing to be more valid i'd like a way for the x to be "mappable" by a parameter or something as i move thru the dev, qa and prod environments so that the x is "soft replaced" by the word warehouse.
is there a way to do this?
Access SQL Server from multiple Docker container
Hi,
on my Windows 10 Enterprise PC I have installed Docker Desktop for Windows and a SQL Server. In the computer management SQL Server configuration manager, protocol TCP/IP; I have the port 49172 configured for TCP/IP.
I want to start two containers, both of them try to open a connection to the SQL Server on the host. The first opens the connection (Port 49172), the second container can not open the port, because I is already in use from the first container. Can I configure
in SQL server that it is accessible from different ports? How do I solve this problem?
Thanks,
Christian
SQL Server update to version 18.5.1 from 18.5 seems to cause a write error for a query with 2 related tables.
Mary D
Deadlock analysis - what's AutoCreateQPStats?
I'm trying to analyze a deadlock that I can reproduce fairly consistently. I can tell what one session is doing (splitting an empty partition function range), but the other one is a bit of a mystery - it's somewhere in a lengthy stored procedure and the deadlock XML says
transactionname="AutoCreateQPStats"
I haven't found any explanation of what that means.
(I can't tell exactly where in the stored procedure this is occurring because the line number in the execution stack is inside an IF block that I have proved isn't getting executed in this test, so SQL Server and I are counting lines very differently. If anyone can explain that I'd also be interested, but this is probably the wrong forum for it.)
Exporting Query results as json in Azure
Hi All.
I have a SQL query, at the moment the output of the SQL query is saved as a json file, I will like to automate the process by writing the output of a query onto a storage account in Azure or any other resource temporarily.
An external process will then consume the json file and delete it afterwards, any ideas in terms of a solution ?
Thanks in advance.
query record with restricted result.
hi ,
table : dispalytable ( heavy transaction table)
a query gave result set . select top(1) * from dispalytable where id >10
user1 ran that query
user2 ran that query
but i want to restrict the first record not displayed to second user , the second user2 only can view nxt top first record of the result set.
( no user can view the same result set)
how to accomplish this ? ROWLOCK ?
SQL login error 18470
I always used Windows Authentication to login SSMS.
Today it shows error 18470, user 'SERVER\Administrator' account is disabled.
Although I still use the sa to login, but how does it comes? and how to enable it again?
Thanks.
Classify items based on Parent status
I have a table `Categories` and looks as below
CategoryID | Name | Status |
1 | Electronics | Active |
2 | Furnitures | InActive |
3 | Men's Clothing | Active |
4 | Women's Clothing | InActive |
5 | Jeans Pent | Active |
6 | T-Shirts | Active |
7 | Sarees | Active |
8 | Shirts | InActive |
9 | Mobiles | Active |
10 | TVs | Active |
11 | Smartphone | Active |
12 | Tables | InActive |
13 | Chairs | InActive |
14 | Stationaries | InActive |
And it's relationship table CategoryRelation as below
ParentCategoryID | ChildCategoryID |
Electronics | Mobiles |
Electronics | TVs |
Furnitures | Tables |
Furnitures | Chairs |
Men's Clothing | Jeans Pent |
Men's Clothing | T-Shirts |
Men's Clothing | Shirts |
Women's Clothing | T-Shirts |
Women's Clothing | Shirts |
Women's Clothing | Sarees |
Sarees | Silk |
Sarees | Cotton |
Mobiles | Smartphone |
Now i'm trying to add another column in `Categories` called `Decision` and the expected output looks like below.
CategoryID | Name | Status | Decision |
1 | Electronics | Active | IN-USE |
2 | Furnitures | InActive | NOT-IN-USE |
3 | Men's Clothing | Active | IN-USE |
4 | Women's Clothing | InActive | NOT-IN-USE |
5 | Jeans Pent | Active | IN-USE |
6 | T-Shirts | Active | IN-USE |
7 | Sarees | Active | IN-USE |
8 | Shirts | InActive | IN-USE |
9 | Mobiles | Active | IN-USE |
10 | TVs | Active | IN-USE |
11 | Smartphone | Active | IN-USE |
12 | Tables | InActive | NOT-IN-USE |
13 | Chairs | InActive | NOT-IN-USE |
14 | Stationaries | InActive | TO_BE_DECIDED |
Logic is as below.
1) Take all the categories with `Active` status and put `IN-USE` for all its children irrespective of its current status2) Take all the categories with `InActive` status and put `NOT-IN-USE` for all its children only when all the children comes under `InActive` Parent items. If any of its children corresponds to one or more Active items, that child should be `IN-USE`. For eg., Shirts in my sample data.
3) If any of the categories doesn't have any children, then it should be `TO_BE_DECIDED` irrespective of its current status. E.g `Stationaries`
I have almost done it with below query but i dont know if that is right way or not. Also I have issues with `Sarees` which should be `NOT-IN-USE` but it is coming other way. Also not sure how to check for no child (`Stationaries`)
with Cte As ( SELECT a.* FROM Categories a WHERE a.Status = 'Active' UNION ALL SELECT a.* FROM Categories a join CategoryRelation s on a.Name = s.ChildCategoryID JOIN cte c ON s.ParentCategoryID = c.Name ), Cte2 As ( SELECT a.* FROM Categories a WHERE a.Status = 'InActive' UNION ALL SELECT a.* FROM Categories a join CategoryRelation s on a.Name = s.ChildCategoryID JOIN cte2 c ON s.ParentCategoryID = c.Name ), cte3 as ( select *,'IN-USE' as Decision,1 as flag FROM Cte union select *,'NOT-IN-USE' as Decision,2 as flag FROM Cte2 ), cte4 as ( select *,row_number() over(partition by name order by flag) as rn from cte3 ) select * from cte4 where rn=1 order by 1
You can find the DB-Fiddle here --> https://dbfiddle.uk/?rdbms=sqlserver_2014&fiddle=252610a5802d5c2bc6cf82d87b8f3b6f
SQL to Classify items based on Parent status
I have a table `Categories` and looks as below
CategoryID | Name | Status |
1 | Electronics | Active |
2 | Furnitures | InActive |
3 | Men's Clothing | Active |
4 | Women's Clothing | InActive |
5 | Jeans Pent | Active |
6 | T-Shirts | Active |
7 | Sarees | Active |
8 | Shirts | InActive |
9 | Mobiles | Active |
10 | TVs | Active |
11 | Smartphone | Active |
12 | Tables | InActive |
13 | Chairs | InActive |
14 | Stationaries | InActive |
And it's relationship table CategoryRelation as below
ParentCategoryID | ChildCategoryID |
Electronics | Mobiles |
Electronics | TVs |
Furnitures | Tables |
Furnitures | Chairs |
Men's Clothing | Jeans Pent |
Men's Clothing | T-Shirts |
Men's Clothing | Shirts |
Women's Clothing | T-Shirts |
Women's Clothing | Shirts |
Women's Clothing | Sarees |
Sarees | Silk |
Sarees | Cotton |
Mobiles | Smartphone |
Now i'm trying to add another column in `Categories` called `Decision` and the expected output looks like below.
CategoryID | Name | Status | Decision |
1 | Electronics | Active | IN-USE |
2 | Furnitures | InActive | NOT-IN-USE |
3 | Men's Clothing | Active | IN-USE |
4 | Women's Clothing | InActive | NOT-IN-USE |
5 | Jeans Pent | Active | IN-USE |
6 | T-Shirts | Active | IN-USE |
7 | Sarees | Active | IN-USE |
8 | Shirts | InActive | IN-USE |
9 | Mobiles | Active | IN-USE |
10 | TVs | Active | IN-USE |
11 | Smartphone | Active | IN-USE |
12 | Tables | InActive | NOT-IN-USE |
13 | Chairs | InActive | NOT-IN-USE |
14 | Stationaries | InActive | TO_BE_DECIDED |
Logic is as below.
1) Take all the categories with `Active` status and put `IN-USE` for all its children irrespective of its current status2) Take all the categories with `InActive` status and put `NOT-IN-USE` for all its children only when all the children comes under `InActive` Parent items. If any of its children corresponds to one or more Active items, that child should be `IN-USE`. For eg., Shirts in my sample data.
3) If any of the categories doesn't have any children, then it should be `TO_BE_DECIDED` irrespective of its current status. E.g `Stationaries`
I have almost done it with below query but i dont know if that is right way or not. Also I have issues with `Sarees` which should be `NOT-IN-USE` but it is coming other way. Also not sure how to check for no child (`Stationaries`)
with Cte As ( SELECT a.* FROM Categories a WHERE a.Status = 'Active' UNION ALL SELECT a.* FROM Categories a join CategoryRelation s on a.Name = s.ChildCategoryID JOIN cte c ON s.ParentCategoryID = c.Name ), Cte2 As ( SELECT a.* FROM Categories a WHERE a.Status = 'InActive' UNION ALL SELECT a.* FROM Categories a join CategoryRelation s on a.Name = s.ChildCategoryID JOIN cte2 c ON s.ParentCategoryID = c.Name ), cte3 as ( select *,'IN-USE' as Decision,1 as flag FROM Cte union select *,'NOT-IN-USE' as Decision,2 as flag FROM Cte2 ), cte4 as ( select *,row_number() over(partition by name order by flag) as rn from cte3 ) select * from cte4 where rn=1 order by 1
You can find the DB-Fiddle here --> https://dbfiddle.uk/?rdbms=sqlserver_2014&fiddle=252610a5802d5c2bc6cf82d87b8f3b6f
Error: 9019, Severity: 21, State: 1 Error
Has anyone experienced an error 9019 on SQL Server 2019? This error occurred on the forwarder in a distributed availability group configuration. Nothing was connected or executing anything against this instance, but index maintenance was executing against the primary node of the primary availability group.
There are no indications that the replication of data got behind and the health of all of the AGs is good.
I can see that the 9019 error was an issue corrected in SQL2012, but this one seems to be different.
SQL Server 2019 CU3 (15.0.4023.6) Enterprise Edition
Error: 9019, Severity: 21, State: 1
The virtual log file sequence 0x000539c6 at offset 0x0000000037f92000 bytes in file 'L:\MSSQL\XXXXXXX' is active and cannot be overwritten with sequence 0x000539f6 for database 'XXXXXXX'.
Ed Mlynar
Database performance
Hi Experts,
Is there a way to assign resources , memory/cpu to individual database so if an instance is assigned 32 gb , out of 10 databases on that instance , assign 4 gb and 1 vcore to one of the databases.
Thanks
SQL Server 2017 is rapidly filling up the storage automatically
Please help if anyone knows what is this behavior or is it a known issue?
DTEXEC
I inherited a server. It has Integration Services 2014 installed on it but never used. I consider running dtexec for some packages (in package mode not project mode) . There is no SSIS catalog deployed, nor any other SQL server component (db, RS, AS, etc..) on this server.
I have the SSIS instance stopped and disabled, but need to check if my configuration is supported, since we do not need to purchase SQL license.
Regards
Need help on SQL Server Licensing?
Hi All,
Would like to understand SQL Server Licensing.
When I run SELECT @@VERSION I get this:
Microsoft SQL Server 2016 (SP2-CU13) (KB4549825) - 13.0.5820.21 (X64) May 22 2020 07:24:35 Copyright (c) Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2012 Standard 6.2 <X64> (Build 9200: ) (Hypervisor)
Above says I have Enterprise Edition: Core-based Licensing.
My questions are:
- In Core-based Licensing, What is max number of cores per License..? I can see minimum is 4 core.
- Suppose I have a SQL Server Enterprise Edition: Core-based Licensing with 16 Cores. Can SQL Server be installed on four different VMs (basically 4 different SQL Server Instances) and each has 4 cores..? Will this pass Microsoft audit?
- Or If I have one license with 16 Cores means it must be installed on a single machine with 16 cores?
Please guide.
Appreciate your time and help in advance.
Aslo I did some research and found that there are 2 type of Licensing Model:
https://www.mssqltips.com/sqlservertutorial/9219/sql-server-licensing-model-and-costs/
https://www.vscope.net/blog/microsofts-sql-licensing-guide/
https://www.techsoup.org/support/articles-and-how-tos/guide-to-sql-server-editions-and-licensing
Editions
Microsoft offers SQL Server through TechSoup in the Standard and Enterprise editions. Standard Edition is most suitable for medium-size charities and organizations. Enterprise Edition is most suitable for large organizations.
- Standard Edition offers basic database, reporting, and analytics capabilities. Microsoft offers this edition under the server/CAL and core-based licensing models.
- Enterprise Edition contains all of the basic features of Standard Edition plus tools for analyzing business and financial data, mission-critical applications, and data warehousing features. Microsoft offers this edition only under the core-based licensing model.
For more information on SQL Server editions, see the basic summary, full comparison, and new feature comparison.
Licensing
Below are some of the major licensing requirements for SQL Server.
- The core-based licensing products offered by TechSoup provide licenses for two cores. SQL Server with core-based licensing requires a minimum of four core licenses to function. In order to use these products, you will need to obtain enough copies to cover the cores in the processors you plan to use with SQL Server.
Modifying sp_help_revlogin to replicate Logins
Hi,
We have modified sp_help_revlogin to exclude logins which are created on that server. Although such logins are scripted out but can not be created on other server.
Machine Name: DBServer1
Login : DBServer1\login1
We can not create DBServer1\login1 on DBServer2,
Also if machine name has some small latter in it's name, same is converted into ALL Capital letters while adding logins.
If you create login2 on DBserver2, you would found that DBSERVER2\login2, and not DBserver2\login2, has been created. we handled that case also. Will copy the modified code below if that helps someone.
In latest versions of SSMS, completion time is inserted in the query output and I couldn't find a way to turn it off using TSQL or power shell. We are unable to automate the login creation process on other machine by consuming the output of modified sp_help_revlogin.
-- Login: test4IF NOT EXISTS (SELECT name from master.sys.syslogins WHERE name = 'test4') CREATE LOGIN [test4] WITH PASSWORD = 0x0200B3F29E427D5BAD24E3E59296991F1AC949A56FA01A3D5838F4CC96F53076EF0653AC967C7D9500B7CCAFEF2E5D42D2BCC3205123336A2ECB1107B063C3ABE11F2DEF24E5 HASHED, SID = 0x61335A88737D6D429C817738CF7534E7, DEFAULT_DATABASE = [master], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
Completion time: 2020-06-23T22:36:14.0419382-07:00
Appreciate your insightful response - Thank you!!
Modified sp_help_revlogin
IF OBJECT_ID ('sp_help_revlogin') IS NOT NULLDROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @type varchar (1)
DECLARE @hasaccess int
DECLARE @denylogin int
DECLARE @is_disabled int
DECLARE @PWD_varbinary varbinary (256)
DECLARE @PWD_string varchar (514)
DECLARE @SID_varbinary varbinary (85)
DECLARE @SID_string varchar (514)
DECLARE @tmpstr varchar (1024)
DECLARE @is_policy_checked varchar (3)
DECLARE @is_expiration_checked varchar (3)
DECLARE @defaultdb sysname
IF (@login_name IS NULL)
DECLARE login_curs CURSOR FOR
SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa' AND p.name <> '##MS_PolicyTsqlExecutionLogin##' AND p.name <> '##MS_PolicyEventProcessingLogin##'
AND CHARINDEX(UPPER (CONVERT (VARCHAR(128), SERVERPROPERTY('MachineName'))) + '\',p.name)=0
AND p.name NOT LIKE 'NT SERVICE\%' AND p.name NOT LIKE 'NT AUTHORITY\%'
ELSE
DECLARE login_curs CURSOR FOR
SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
OPEN login_curs
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
IF (@@fetch_status = -1)
BEGIN
PRINT 'No login(s) found.'
CLOSE login_curs
DEALLOCATE login_curs
END
SET @tmpstr = '/* Logins creations script '
PRINT @tmpstr
SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT ''
SET @tmpstr = '-- Login: ' + @name
PRINT @tmpstr
IF (@type IN ( 'G', 'U'))
BEGIN -- NT authenticated account/group
SET @tmpstr = 'IF NOT EXISTS (SELECT name from master.sys.syslogins WHERE name = ''' + @name + ''')' + ' CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
END
ELSE BEGIN -- SQL Server authentication
-- obtain password and sid
SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
-- obtain password policy state
SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SET @tmpstr = 'IF NOT EXISTS (SELECT name from master.sys.syslogins WHERE name = ''' + @name + ''')' + ' CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'
IF ( @is_policy_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
END
IF ( @is_expiration_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
END
END
IF (@denylogin = 1)
BEGIN -- login is denied access
SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
END
ELSE IF (@hasaccess = 0)
BEGIN -- login exists but does not have access
SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
END
IF (@is_disabled = 1)
BEGIN -- login is disabled
SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
END
PRINT @tmpstr
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO
Bulk Insert error for exponential values during import in sqlserver
We got the following error during bulk insert in SQL server
Microsoft SQL Server 2014 (SP1-GDR) (KB4019091) - 12.0.4237.0 (X64)Web Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
BULK INSERT ABC
FROM ‘D:\Dump001.csv’
WITH (FIELDTERMINATOR = '|',ROWTERMINATOR = '\n', FIRSTROW=2)
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 552612, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 635686, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 657871, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 675625, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 675628, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 699484, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 898948, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 997300, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1214311, column 148 (column_amt).
Msg 4864, Level 16, State 1, Line 3
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1494400, column 148 (column_amt).
We found the exponential values in those columns like 1.0001666E7.
Please help us to resolve this issue or any way for this.
rajesh
Sample Database in SQL Server 2019 format
Hi,
I want to find a sample database in SQL Server 2019 format. The database can as simple as just contain one table with one record. Where can I find such a sample database file online?
Thanks