sql

Identifying graphs in heap of connected nodes -- how is this called?

I have a SQL table with three columns X, Y, Z. I need to split it in groups in such a way that all records with same value of X or Y or Z are assigned to the same group. I need to make sure that the records with same value X or Y or Z are never split across multiple groups. If you think of records as nodes and values of X, Y, Z as edges...

How to trace row level dependency?

In case I need to change the PK of a single row from 1 to 10, for example, is there any way to trace every proc, view and function that might reference the old value? I mean, a simple select in a proc like: select * from table where FK = 1 would break, and I'd had to look for every reference for ones in every proc and view and change th...

T-SQL Case statement utilizing substring and isnumeric

I have a T-SQL stored proc that supplies a good amount of data to a grid on a .NET page....so much so that I put choices at the top of the page for "0-9" and each letter in the alphabet so that when the user clicks the letter I want to filter my results based on results that begin with that first letter. Let's say we're using product na...

This SQL query is not working for me please help

I have a poorly normalized set of tables and am trying to correct this issue. The DB is MS SQL 2005. Table1 has an id field (record ID), a mainID field (person ID) and a sequence field (and int that determines the sort order) Table2 has its own id field and a copy of the id for the first record by a person (sequence = 1). I've added ...

How do I use ESCAPE in SQLite?

Trying this answer and not having any luck: I am using the SQLite Database browser (built with 3.3.5 of the SQLite engine) to execute this query: SELECT columnX FROM MyTable WHERE columnX LIKE '%\%16' ESCAPE '\' In column XI have a row with the data: sampledata%167 I execute the statement and get no data returned but no err...

php variable in regex?

I have a variable $word and I'd like to match it in my select statement somethig like this: "select * from table where column regex '[0-9]$word'" but this doesnt work, so how can i put a variable in a regular exprssion? Thank you ...

How to find people who bought one product but NOT another?

Hi, I have a table linking customers to previous purchases: RecID CustID ProdID 1 20 105 2 20 300 3 31 105 4 45 105 5 45 300 6 45 312 I'd like to get a list of CustIDs that bought Item 105, but did NOT but Item 300. In this case, CustID 31. I can't se...

Oracle SQL Issue with Insert Statements

So I am a beginner to this, and trying to follow my professors instructions on how to complete this. They are as follows: Consider the relational database described in Tables 1-3. The underlined attribute(s) is the primary key for a table. Use your Oracle account to create this database and to insert the tuples listed in each table. ...

CREATE TABLE [email protected](..)

How to Create a Table in Oracle with name [email protected] I tried doing CREATE TABLE [email protected](..) but this gives me error so i was looking for some other way of doing it ...

Update Zero Rows and then Committing?

Which procedure is more performant for an update which affects zero rows? UPDATE table SET column = value WHERE id = number; IF SQL%Rowcount > 0 THEN COMMIT; END IF; or UPDATE table SET column = value WHERE id = number; COMMIT; In other words if an Update affect ZERO rows and a commit is issued am I incurring any added expense ...

match a word from a sentence in MYSQL using regex

How can I match a word in a sentence from a column using regex? I tried: "select * from table where column regex '/\b".$text."\b/i'" but that didn't work. Thanks in advance. ...

Database table names: Plural or Singular

What is the most common naming convention for SQL Database tables? Was it historically one way and now it's better to do another way? What are the most common practices now? ...

Table is present in SHOW TABLES; but MySQL cannot find its file...what do I do?

I am using MySQL 5.1.47 on a Mac. I have created a table named Stay in a database named LEAD. When I do a show tables command, Stay appears in the list. When I try to insert something into that table, MySQL tells me that it cannot find the 'stay' file, and gives me an errno of 2. MySQL documentation indicates that if you get an errno...

How can I find out the exact query that gets executed with LINQ to SQL in DbLinq and SQLite?

I'm using DbLinq with SQLite for a small project of mine. Is there any way to look at the actual SQL queries that get executed behind the scenes? I remember a monitoring program for SQL Server from my internship but SQLite is a quite different beast, I fear. ...

Why finally block is not given in SQL SERVER?

All language like C#,VB.NET all have try catch finally block but SQL server only have try and catch only why not finally block is given is there any specific reason for that? ...

Is it possible to pass table name as a parameter in Oracle?

I want to create a stored procedure like this: PROCEDURE P_CUSTOMER_UPDATE ( pADSLTable IN Table, pAccountname IN NVARCHAR2, pStatus IN NUMBER, pNote IN NVARCHAR2, pEmail IN NVARCHAR2, pMobi IN NVARCHAR2, pServiceTypeID IN NUMBER, pDate IN DATE ) IS BEGIN UPDATE pADSLTable ...

ruby on rails sql statement error

Hi guys i have a model livestream which has two columns in the database, 'user_id' and 'activity_id'. Very straight forward. Now when I try to insert multiple records into the database I get an invalid SQL statement: SQLite3::SQLException: near ",": syntax error: INSERT INTO livestreams (user_id, activity_id) VALUES (1, 2), ...

SQL for a movie database search system

I am building up a database of movies. Each movie will have fields genre, actors, director etc. Now my question is how do I design a database and write SQL as each movies can have multiple actors or directors etc. Right now my database design for table movie is: movie_id movie_title actors_id directors_id genre_id But this way it se...

how to rank customers in sql 2008(northwind)

i have been asked to write a query which in should rank customers base on the quantity of orders they have. the main important factor is that if two customers have been ordered the same quantity they should have be in same rank. i want to know the way to handle this query. for this i have began as below: select tble1.customerid, RANK()...

how to return a cell into a variable in sql functions.

i want to define a scaller fucntion which in that im giong to return the result into a variable but i do not know how to do this. CREATE FUNCTION dbo.Funname ( @param int ) RETURNS INT AS declare @returnvar int select @returnvar = select colname from tablename where someconditions = something return(@returnvar) i want to make a funct...