sql

Altering a non clustered index in a sybase

I have a unique non-clustered index on a sybase table which includes 4 columns: col1, col2, col3 and col4. I want to drop one of the columns from the table. I don't want to drop and recreate the index. Can I alter the index to not consider this column? ...

Integrated windows authentication to SQL Server

Hi, I have an application that uses a database on SQL Server and I want users to connect to that server using integrated windows authentication. The connection string is: SqlConnection scn = new SqlConnection("Data Source='server name';Initial Catalog=temp;Trusted_Connection=true;Integrated Security=SSPI"); When I run the application...

Oracle INSERT only if values are in another table

Hi, I have two tables: players (has a team name column) and teams (also has a team name column) I want to only allow inserts of new players if the team name exists in the team table. Any help would be appreciated. Please keep it simple because I'm still learning. ...

Need help with MySQL query & PHP

I have the following 3 tables: (PK = Primary Key, FK = Foreign Key) Files Table File ID (PK) File Name ... ------------ --------- 1 a.jpg ... 2 b.png ... 3 c.jpg ... . . . . . . Tags Table Tag ID (PK) Ta...

Create SQL table with the data from another table

How do I create a table using data which is already present in another table (copy of table)? ...

TSQL how do you iterate through rows while parsing them?

Sorry for the poor question wording I wasn't sure how to describe this. I want to iterate through every row in a table and while doing so, extract a column, parse the varchar that is in it and depending on what it finds insert rows into another table. Something along the lines of this: DECLARE @string varchar(max); foreach row in (selec...

Optimizing query and/or data model for calendar app

Our calendar application represents an appointment domain as: Appointment ID (PK) StartDateTime EndDateTime ... AppointmentRole AppointmentID (FK) PersonOrGroupID (FK) /* joins to a person/group, outside the scope of this question */ Role ... Appointment has a 1 to many relationship with AppointmentRoles. Ea...

Whether to Split Data in to Separate PostgreSQL Table

I am creating an app with a WPF frontend and a PostgreSQL database. The data includes patient addresses and supplier addresses. There is an average of about 3 contacts per mailing address listed. I'm estimating 10,000 - 15,000 contact records per database. When designing the database structure, it occurred to me that rather than storing...

Count n-tuples in SQL

I have a table with two int columns, the combination of them is unique. ids idk --------- 1 2 1 3 1 4 2 2 2 3 2 4 3 2 3 5 3 4 4 2 4 3 What I want is to get the biggest set of idks which is common to at least 2 ids. The result here should look like this: (2,3,4) - 2x (2,4) - 3x (2,3) - 3x (3,4) - ...

Match against with multi values - the right way?

Hello guys, i really hope that someone can help me with my problem. I would like to realize a match against query with multiple searchstrings. In the moment it looks like this: SELECT result.* FROM ( SELECT A.TITLE AS title MATCH(A.TITLE) AGAINST('$searchstring1' IN BOOLEAN MODE) AS REL, MATCH(A.TITLE) AGAI...

MYSQL select count of rows that fall in a month for every month of the year.

With the table: id date_from date_to --------------------------- 1 2010-01-01 2010-03-01 2 2010-02-07 2010-05-01 3 2010-07-05 2010-07-10 I am trying to return a result which has one row for each month of the year that lets me know how many rows were active in that period. So for the above I would want the result ...

Remove duplicates using only a MySQL query?

I have a table with the following columns: URL_ID URL_ADDR URL_Time I want to remove duplicates on the URL_ADDR column using a MySQL query. Is it possible to do such a thing without using any programming? ...

MySQL - How can I update a table with values from another table?

Hello, i'have the task to repair some invalid data in a mysql-database. In one table there are people with a missing date, which should be filled from a second table, if there is a corresponding entry. TablePeople: ID, MissingDate, ... TableEvent: ID, people_id, replacementDate, ... Update TablePeople set missingdate = (select re...

Delete sql rows where IDs do not have a match in another table

Hi, please can I have some help on this. I'm trying to delete orphan entries in a table. I have 2 tables like this: table files: | id | .... ------------ | 1 | .... | 2 | .... | 7 | .... | 9 | .... table blob: | fileid | .... ------------ | 1 | .... | 2 | .... | 3 | .... | 4 | .... | 4 | .... | 4 | .... | 9 | .... The ...

Can't drop table that was just created

I created a table named dual2. I've a rows there, and can select from it. When attempting to drop it, it produces this error: ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-00942: table or view does not exist However, the table still exists! It returns from dba_tables and user_tables. Any ideas on wha...

Prevent duplicate rows being inserted

I'm trying to use an SQL insert statement to migrate rows from a table in one database to a table in a different database. The statement works until I add a unique index on the destination table and at that point I'm struggling to get the insert statement to be able to exclude the duplicates. Here's what I though should work: INSERT INT...

Return sql query as array

Hello, I'm using jqueryui and its Autocomplete plugin. It use a json to extract items. I want to modify it so that items will be extracted from my db. Here is how items should be : $items = array( "Great <em>Bittern</em>"=>"Botaurus stellaris", "Great2 <em>Bittern</em>"=>"Botaurus stellaris 2" ); How to make an sql query that extra...

Select n largest values from a table

Hi, How can I select the 100 largest rows in a table based on a column 'score'? I can find the largest score in the 'score' column with: SELECT max(score) FROM mTable And then obtain that row(s): SELECT * FROM mTable WHERE score=largestScore But how would I wrap this up and obtain the following 99 lower scored rows? Thanks. ...

PostgreSQL aggregate views

Are views in PostgreSQL completely recalculated every time one of underneath tables are changed? More precisely, if I have aggregate view over table votes, will complete recalculation of a view be needed, when any changes are made in votes table? If I expect often changes of votes table, what are alternatives to aggregate view? I need ...

How do I filter this MySQL query to only include items not rated by a specific user?

Given this sample dataset: item ---- item_id item_name item_added 1 Apple <date_time> 2 Banana <date_time> user ---- user_id user_name 1 Alice 2 Bob 3 Carol rating ------ rating_id item_id user_id rating_value 1 1 1 3 2 1 2 4 3 1 ...