sql

n00b oracle question

I am using Oracle Sql Developer I have a huge script that creates tables, indexes, primary key constraints and such. my DB name is: dbo_other I logged into this dbo_other as sysdba. If I run my script then tables do not show up on left panel under 'Tables' However, if I append the script by adding 'dbo_other.' in front of every tab...

Setting Membership Store Passwords

I'm migrating an application from ColdFusion to ASP.Net MVC and have a little problem I cannot seem to get my head around. The original application stores user's passwords in a MD5 hash format with no salt in the database. I'm using the ASP.Net membership store and would like to allow for as seamless a transition for the existing users...

Simple SQL select in C#?

On my current project, to get a single value (select column from table where id=val), the previous programmer goes through using a datarow, datatable and an sqldatadapter (and of course sqlconnection) just to get that one value. Is there an easier way to make a simple select query? In php, I can just use mysql_query and then mysql_resul...

Joining tables (without a clause)

I want to join to tables and get the following output Table1 TestId1 ---------- one two three four five six seven eight Table2 TestId2 ---------- fiftythree fiftyfour fiftytwo fiftyfive fiftyone I want Table3 as my output with all rows from table1 and the first rows from table2 until there are no more rows left and then they shoul...

Oracle Dynamic Join Challenge

EDIT: Far simpler example. (Formerly titled: Oracle Column Injection) GOAL: Complete the query below generate the following results? PURPOSE: Create a column dependent on an existing column in a table without putting the table in a subquery. Rules: Restructuring the query to put tbl in a subquery is not an option. The query must use...

What's the difference between "LIKE" and "=" in SQL ?

Is there any difference between: SELECT * FROM users WHERE username="davyjones" and SELECT * FROM users WHERE username LIKE "davyjones" (I think I've bungled up the syntax... pardon me for that, I'm mostly a desktop app development guy) ...

Rating based upon which column matches a string

I am trying to write a query that rates how well a particular object matches some search criteria. I have a table with the columns: objectid, typeid and name. An object can have two names associated with it (current name or previous name). The typeid identifies what type of name the row is. A user can search the database from a form....

How do I query XML stored as text?

I have a table in a SQL Server 2005 database that logs purchases like so: ID (PK, int, not null) Request (text, null) Response (text, null) MerchantId (varchar(14), null) Amount (money, null) The Request and Response fields are really storing XML. I can't change the data type to XML. I need to draw a query that will get data out of ...

What is the proper way to check errors from a cascading save?

On creation of a user, a row must be inserted into both the User and Email table. It can fail in either of them(unique constraints). How can I find out which is the reason for failure? My thoughts have been using a lock and querying the database prior to the inserts or parsing the SqlException that comes back(which I'd prefer not to do)....

How to make a SQL query for last transaction of every account?

Say I have a table "transactions" that has columns "acct_id" "trans_date" and "trans_type" and I want to filter this table so that I have just the last transaction for each account. Clearly I could do something like SELECT acct_id, max(trans_date) as trans_date FROM transactions GROUP BY acct_id; but then I lose my trans_type. I c...

SQL Combine Columns into a string

Hello, I have a table with the following columns in table: id, t1, t2, t3, t4 All are of type bit (There are other columns as well, however I am only showing the relevant one) Now, I need to get the following string based on the ID: t1 t2 t3 t4 The best I thought of would be this: declare @t1 bit, @t2 bit... Select @t1 = t1, @t2 =...

SQL Server 2008 - find table with most rows

Is there a way in SQL Server 2008 to find the table with the most rows in the database? ...

Get first Sunday of next month using T-SQL

Looking for a way to get the date in the format "11/1/2009", which would be the first sunday of next month. I want to run this query after the first sunday in october to get the first sunday of the upcoming month. What is the best method to accomplish this with a T-SQL query? Thanks ...

Find All References to View

I've got various databases, and what to be sure I am removing something (a view in this case) that is truly orphaned. Is the the correct SQL to be using: SELECT r.routine_name, r.routine_definition FROM INFORMATION_SCHEMA.ROUTINES r WHERE r.routine_definition LIKE '%my_view_name%' The problem with it is that these referenc...

Log usage of database tables in PostgreSQL

Possible Duplicate: How do I find the last time that a PostgreSQL database has been updated? I need to be able to determine when the last time a database table was modified. I have seen the usage of sys.dm_db_index_usage_stats and last_user_update but this is not available in PostgreSQL. Is there similar functionality in Postgre...

Venue/Event Booking Database Design

I am task with designing a database for online bookings. I am not looking for a full design as we have had previous exp with online house rental. What i would like to know, is how do we design a db for booking of hotel, travel, events. We have some ideas. Basics... Have all venues/ events (once/reoccuring) register. That seems like ...

How can I compare two variables/columns of type NTEXT

I know I can convert the variables to nvarchar(max) first and then compare with the = or <> operators. But is this the right way? ...

Oracle Date Subtraction

How would i write an expression that gives me the difference between two dates in days, hours, minutes, seconds, etc? By default subtracting two dates in oracle returns days as a decmial. ...

T-SQL Query Returning Items It Shouldn't Be.

Here's the scenario. The column in question is called 'datein' and it's type is 'datetime'. I have three rows with the value of '2009-10-01 00:00:00.000' for 'datein'. Why does this query return the aforementioned rows? SELECT * FROM t_call AS tc WHERE tc.datein >= '2009-09-30 00:00:00.000' AND tc.datein <= '2009-09-30 ...

What would be the SQL Select statement for mixed dates in one column?

I have a customer who has legacy data stored in Oracle database. Such data contains mixed DATE values in one column in database (that field is VARCHAR(32)). For example they store '30-Sep-2009' and sometime '1254431689' (that is a timestamp in epoch time). I have no option to split the data into multiple columns (so I have to deal with...