Category "sql"

Rounding off to two decimal places in SQL

I need to convert minutes to hours, rounded off to two decimal places. I also need to display only up to two numbers after the decimal point. So if I have minut

Error Code: 1822. Failed to add the foreign key constaint. Missing index for constraint

I found some threads about the error. But all the solutions doesn't work for me. I created 2 tables a user table and one for articles. Now I want to store the

sqlsrv_num_rows() expects parameter 1 to be resource, boolean given

Having an issue with sqlsrv_query. This is the error I get: PHP Warning: sqlsrv_num_rows() expects parameter 1 to be resource, boolean given Here is the relev

mysqldump with --where clause is not working

mysqldump -t -u root -p mytestdb mytable --where=datetime LIKE '2014-09%' This is what I am doing and it returns: mysqldump: Couldn't find table: "LIKE"

SQL query to determine that values in a column are unique

How to write a query to just determine that the values in a column are unique?

Update a column value, replacing part of a string

I have a table with the following columns in a MySQL database [id, url] And the urls are like: http://domain1.com/images/img1.jpg I want to update all

Correct use of transactions in SQL Server

I have 2 commands and need both of them executed correctly or none of them executed. So I think I need a transaction, but I don't know how to use it correctly.

How to insert into a table that specifies a DEFAULT value for every column?

I have a table where all columns are auto-populated whenever an insertion happens: CREATE TABLE … ( ItemID INT NOT NULL IDENTITY(…

In SQL how to count the number of result?

I'm having the following SQL DB: DB name: films DB fields: id, title, release_year, country, duration, language, certification, gross, budget I'm trying to

Auto increment table column

Using Postgres, I'm trying to use AUTO_INCREMENT to number my primary key automatically in SQL. However, it gives me an error. CREATE TABLE Staff ( ID

Run xp_create_subdir without admin privilidges

The Point: I want to be able to create a directory on the filesystem through a non-sysadmin SQL user. I'm creating a web front-end for a deployment script whi

PostgreSQL asking for 'group by' clause in where, when sending parameters

I have a simple query in PostgreSQL which is ok when I run it without any query parameters : select date_trunc('week', action_time),count(*) from event

Could not drop object 'dbo.Table1' because it is referenced by a FOREIGN KEY constraint

Even though I am removing and trying to drop table, I get error, ALTER TABLE [dbo].[Table1] DROP CONSTRAINT [FK_Table1_Table2] GO DROP TABLE [dbo].[Table1] GO

Get full tree of parent/child relationships in mysql of any node in the tree with all parents

Example data: +----+-------+----------+ | org_id | Name | ParentID | +----+-------+----------+ | 1 | Org1 | 2 | | 2 | Org2 | NULL | | 3 | Org3

How to parse the following JSON to retrieve the name of the item in snowflake sql?

[ { "itemId": "HWKDVCXKU5", "name": "A", "quantity": 1.000000000000000e+00, "storeId": 1.150192000000000e+06, "type": "structure" },

How does Multiple Active Result Set (MARS) work in SQL Server?

Just wondering if someone could explain how Multiple Active Result Set (MARS) works in SQL Server as it is not very clear on the MSDN site. (A) On a MARS conn

JPA (Hibernate) Native Query for Prepared Statement SLOW

Having strange performance issue using Hibernate 3.3.2GA behind JPA (and the rest of the Hibernate packages included in JBoss 5.) I'm using Native Query, and a

SQL Server unpivot multiple columns

I'm trying to pivot a table around it's many columns to get to 3 columns (pivot, column name, value) so for example: name | age | gender ------+-------+--

Best way to select random rows PostgreSQL

I want a random selection of rows in PostgreSQL, I tried this: select * from table where random() < 0.01; But some other recommend this: select * from table

How To Set Server Output On in DataGrip

How Can I "set server output" on in Jetbrains DataGrip IDE? I am able to do this in SQL Developer and run the SQL script successfully. The same script I try to