|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Checking the Check Constraint | |
What happens when I run this code?
CREATE TABLE MyTest ( myid INT , myval INT CHECK myval < 10 ); GO DROP TABLE MyTest; | |
Think you know the answer? Click here, and find out if you are right. |
Yesterday's Question of the Day (by BTylerWhite) |
Enumerate the Python List I have the following code in Python: animals = ["cat", "dog", "elephant", "fox", "horse"] for index, animal in enumerate(animals, start=1): print(animal) print(index) What will be the result of printing the index variable after the loop completes? Answer: 5 Explanation: In Python, we can use the built-in enumerate function to return an enumerable object from a sequence. Enumerate will return a tuple result including the count of the values of iterating over the sequence. In the example provided in the question, the start argument was provided with 1, indicating to not start at 0 by default. The "animals" list variable was provided as the iterable sequence. This function is particularly useful to avoid the requirement of specifying a "counter" variable and adding to it throughout a traditional loop. This could be achieved in a similar way using a counter variable, like so: animals = ["cat", "dog", "elephant", "fox", "horse"] index = 0 for animal in animals: print(animal) index += 1 print(index) References: https://docs.python.org/3/library/functions.html#enumerate |
Database Pros Who Need Your Help |
Here's a few of the new posts today on the forums. To see more, visit the forums. |
SQL Server 2017 - Administration |
Distributed Availability Group Failover test without affecting Primary site - Hi I have created a test environment with Distributed Availability Group (SQL 2016) for DR Testing and I can fail over to DR. Now I need to test the DR site databases with application. To avoid the test data sync back to Production site, i have to drop the Distributed AG. Is there any way […] |
Locking issue - All, I would appreciate some advice on identifying an issue. The error I received is: "The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time" I was monitoring sys.dm_tran_locks and I saw the query is taking a lot of page locks. I'm therefore thinking that the issue is either: […] |
SQL Server 2017 - Development |
Visual Studio Database Project Reference to a Non-Project Database - I have a database solution in Visual Studio Enterprise 2019 which consists of four database projects. My databases live on a shared SQL Server instance that hosts multiple solutions. My database projects take advantage of objects on that instance in another database that I do not control, and is not managed in a VS solution […] |
SQL Server 2016 - Administration |
Availability Group Latency Check - How can I check if there is latency between primary and secondary on SQL Server 2016. Are there any scripts available?. What in specific you look for in the availability dashboard. For example, I see all the db's in green ( healthy) however found out that we still had 40 secs latency. Do you […] |
Recovering SQL databases - Hi I'm looking into recovery plan for individual SQL databases. The scenario I'm planning for, is if a single SQL database on an instance with multiple databases, for multiple applications, becomes unavailable. My thought is to have a cold standby server we can restore the database to, then use CLIconfig on the application servers to […] |
SQL Server 2016 - Development and T-SQL |
Ugly code fix - CASE WHEN Phone IS NOT NULL OR MobilPhone IS NOT NULL THEN CONCAT(CONCAT(LEFT(COALESCE(Phone,MobilPhone),3),'-'), CONCAT(CONCT(RIGHT(LEFT(COALESCE(Phone,MobilPhone),7),3),'-'), RIGHT(LEFT(COALESCE(Phone,MobilPhone),12),4))) ELSE '' END As PhoneNumber I inherited this god awful code. I comment this variable out and the query executes in < 30 seconds against a sizable number of records. (~ 1MM). I add this little tidbit of insanity back […] |
Administration - SQL Server 2014 |
How to find all Linked Servers pointing to our instance? - Hi all. We are preparing for migration, and scripting all our Linked Servers. But how to find all other Linked Servers, that originate on different instances but leading to ours? Thanks |
Development - SQL Server 2014 |
TRY_CONVERT missing? - Hi gurus! I am trying to use the try_convert function on a SQL Server 2014 Standard Edition and a SQL Server 2016 Developer Edition (my staging) and I am getting this: Msg 195, Level 15, State 10, Line 11 'TRY_CONVERT' is not a recognized built-in function name. Am I missing something? As usual, any help […] |
location address without file name - If my column contains these values. C:\AABCD\EDFG\RFG\MyDB123.bak D:\RFG\MyDB1123.bak E:\AABCD\EDFG\MyDB1223.bak How do I select only these in my output C:\AABCD\EDFG\RFG D:\RFG E:\AABCD\EDFG Thanks |
string selection - If my column contains these values. A:\AABCD\EDFG\RFG\MyDB123.bak A:\RFG\MyDB1123.bak A:\AABCD\EDFG\MyDB1223.bak How do I select only these in my output A:\AABCD\EDFG\RFG A:\RFG A:\AABCD\EDFG Thanks |
SQL Server 2019 - Administration |
A read operation on a large object failed - I got an alert every day recently at different time on SQL server box DESCRIPTION: A read operation on a large object failed while sending data to the client. A common cause for this is if the application is running in READ UNCOMMITTED isolation level. This connection will be terminated. This is hard for me […] |
Numerous IF and Else clauses & its execution time in sys.dm_exec_procedure_stat - Hey SSC, Please if we have a stored procedure in which at a time only a single code segment of IF is executed out of many IFs in the procedure. Every IF code segment has a different query and execution time. So on cumulative what info would be sys.dm_exec_procedure_stat will bring to us? and how […] |
SQL Server 2019 - Development |
Hello I need help to improove the following query with many joins - Hello I have this query SELECT ISNULL(sta5.AttributeValue, rdd5.Value) as 'Manufacturer Code', ( SELECT TOP 1 ID2.Content FROM ItemMaster IM join ItemMasterDetail ID1 on IM.Id = ID1.ItemMasterId and ID1.ItemMasterAttributeId = 14 join ItemMasterDetail ID2 on IM.Id = ID2.ItemMasterId and ID2.ItemMasterAttributeId = 15 WHERE ID1.content = ISNULL(sta5.AttributeValue, rdd5.Value) and ID1.Sequence = ID2.Sequence order by ID2.[Sequence] desc […] |
SQL Server 2008 - General |
Select query is slow for Non clustered index - I am using SQL Server 2008 R2. Select query is slow when non cluster index is used in the table compared to table without index. Query used: select * from table order by customer_name It is too slow (more than 1 minute for 40000 rows) Error was due to non-clustered index , without index query […] |
SQLServerCentral.com Website Issues |
Can post please be stored in nvarchar? - It actually surprises me this should even be a request. Post data, however, appears to be stored as a varchar, not an nvarchar which is causing malformed post, including today's QOTD. Obviously this data has not been lost, but this should be fixed, as it can't be assumed that post will only contain characters from […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |