Forbid delete if the record is referred from other tables

In SQL Server 2008, how can I forbid the delete (or throw an exception) if the involved record is used from others tables in some foreign keys? I have set, in the relationship, “on delete -> nothing”, but it isn’t what I need… I need to stop the delete… Let’s say, if I have the […]

How to write bash & sql files to setup users for postgres?

I am trying to create bash and sql files to create a user and a database.. Here is what I have done so far.. Setup_postgres.sql Create USER dummbyuser; ALTER USER dummbyuser with superuser; ALTER USER dummbyuser with LOGIN; /q Setup_postgres.sh sudo su – postgress psql -f setup_postgres.sql; sh setup_postgres.sql logout My problem [SOLVED] I tell […]

No rows fetching but need a value

This question already has an answer here: How to return a default value when no rows are returned from the select statement 7 answers

SQL XML column – update child node value based on other nodes

I am not used to use xml in an sql column and have a question about updating the content of that column. I have a table (TableXML) with a column (ColumnXML) containing the following xml hierarchy : Xml/Content/Queues/list/Item/ Each Item have a /Name, a list of PluginsProperties/Item and each of these other item have a […]

Compare when one field is empty but concatenation is to be compared

I have two tables. Tbl1_Students Name Class Section Joe 8 A Pin 8 B Tea 8 C Mia 9 A Ton 9 B Mon 10 Tim 7 A Tbl_Exclusion Class Section 7 A 8 B 9 The query should exclude all records where class= 7 and Section =A and Class= 8 and Section =B and […]

PHP pagination using SQL SERVER 2008

I still trying to create pagination with PHP but SQL SERVER (2008) not support offset and limit. Below you can see SQL query but I don’t know what is wrong: declare @offset int declare @limit int set @offset = 2; set @limit = 20; SELECT *, ROW_NUMBER() OVER (ORDER BY use_by_date desc ) AS RowNum […]

Should I use NTILE to get a distribution of data by datalength?

Using SQL Server 2014. I have a table with millions of rows which has a varchar(max) column called [Description]. The MAX(DATALENGTH(Description)) is 30000. I want to show a results set showing the distribution of the data by datalength in groups of 1000. So the first row would show a count of rows that have a […]

Get column value where boolean is true, otherwise get the column value where boolean false

I have a table with data similar to the following. I’ve been using a large table with numerous rows with varying flags, and keys. I’ve managed to group them down so that I have the lowest where the flag is true, and the lowest where the flag is false. ╔══════════════════╦══════╦═══════╗ ║ Email ║ Flag ║ […]

Showing Comma separated values from database in a textarea?

I have really searched and searched and not found an answer. Given that one article can have multiple tags, I want to show the tags as comma separated values so that it looks like Egypt, Sinai, Muslim Brotherhoodin a textarea when the article is edited. I’ll post whatever code is needed if that will help […]

Sync single table between MSSQL and MySQL

i need to synchronize a table between our MSSQL Database to our MySQL Database. The MSSQL Datbase is the master, MySQL the clone. I can not link the tables(thats the solution when you google it), i have to do it with Queries and a Cronjob. I first thought of SELECT COUNT(*) FROM table; And compare […]

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