SQL Server constraint is “not trusted”

I recently heard the term “not trusted”: SQL Server will mark the constraint as “not trusted”. Does anyone can explain a bit what is the meaning of that? I know the question is a bit vague but I was wondering if this is a Microsoft specific “term” or is also used by other relational databases?

Concatenate a single row with multiple string validations?

In the query below, if both conditions are true then the last entry is updated in ErrorMessage. If one record has country more than 3 characters and length of HR_DOMAIN_Code is not equal to 3, then ErrorMessage should look like ‘Invalid Country’ & ‘Invalid HR_DOMAIN_CODE’: update A set ErrorMessage = ( case when len(Country) > […]

Perform same SQL query on multiple databases

I’m trying to adapt an SQL query to check the value present in a certain field that is present in every database on my server. There are 100 individual databases, and I would like to check a specific record of each one. The answer is probably to use a command like the one below, but […]

Update table with 2 join

I need to update table which refers to two more tables. Here’s my select code to validate which rows will be updated. SELECT * FROM txsh AS t1 INNER JOIN div AS t2 ON t2.store = t1.ro_no INNER JOIN temp_db AS t3 ON t3.bpn = t1.sku_id AND (t3.div IS NULL OR t3.div = t2.div) AND […]

freetds.log file is HUGE in pymssql. How to disable?

I am using pymssql in Ubuntu 15.10 connect to a SQL Server 2014 database in Windows Server 2012. When using pymssql, a freetds.log file in created in ~/Work/tsql/freetds.log. I have no idea how that was specified. Note that I am running my script from ~/Work/dir1/bin/runScript.py, so somehow that log file is getting creative at the […]

DATE TIME Conversions

I am very new to SQL, well not so new any longer. I’m just curious… I just would like to know why I have seen inconsistencies in Date conversions. Why do some developers use: SELECT CONVERT(CHAR(10), GETDATE(), 101) == > this makes sense to me: 05/24/1987 10 chars Some use: SELECT CONVERT(CHAR(12), GETDATE(), 101) Can […]

Split column data into multiple rows

I have data currently in my table like below under currently section. I need the selected column data which is comma delimited to be converted into the format marked in green (Read and write of a category together) Any ways to do it in SQL Server? Please do look at the proposal data carefully…. Maybe […]

SQL Server Between Time

I am looking for an elegant way to select records that fall between a start and end time. I have a datetime field that hold the date and time of the record. I can get the time by CAST(fieldname as time). A BETWEEN does not work if you are looking for records that occurred between […]

Group by with getting only max value

I have three tables machine (list of machines), event (list of machine events eg. event id, machine name, start and stop timetamp) and eventdetails (more information about every event specified by event id and machine name). I want to execute a query, which joins the data of max event id for every machine, but I […]

Why do I need to quote columns and tables using Npgsql for C# and PostgreSQL?

So I’m switching from SQL Server 2008 R2 (on Windows Server 2012) to PostgreSQL 9.5 (again on Windows) and all of my existing SQL statements are written in this format: INSERT INTO Address (Address1, Address4, Address5, Postcode, IsoCountryCode) VALUES(@P0, @P1, @P2, @P3, @P4) I’m using Ngpsql v3.1.3 as my .NET library to talk to PostgreSQL […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.