sql

Oracle deadlock detection tool

I am looking for a static analyser of Oracle queries and PL/SQL procedures (triggers, constrains, ...) - a tool that will pass on our DB scheme and point to potential deadlocks. Just like FindBugs for Java. If such a tool does not exist, would you like to have it ? ...

How to forcibly create stored procedure even if some error occure?

Hi, When i execute database script, i got errors in stored procedure then it couldn't create that stored procedure that have errors. I want to forcibly create stored procedure even if some error occur in stored procedure. Thanks in advance ...

Creating an entity diagram of a database without any foreign keys

I need to create an entity diagram of a MSSQL 2005 database. Relationships are defined by using primary keys consistently, but there are no foreign keys anywhere. I tried Microsoft Visio's "Reverse Engineer" function, which of course failed due to the lack of foreign keys. Therefore, I need a diagram tool which doesn't solely rely on f...

SQL: INSERT INTO...VALUES..SELECT..

How do i write INSERT statement if i get the values of colA from TableX, colB from TableY and colC from TableZ? eg: INSERT INTO TableA (colA, colB, colC) VALUES (?,?,?) Any ideas if it is possible? ...

How to change nvarchar to datetime format?

My code generates some dataset per 10 minutes-log or per 30 minutes-log, but the DateTime Format is '1900-01-01 14:20:00'. I need '2009-05-13 14:20:00', so I want to change it. See Table1 and Table2 below. declare @date1 nvarchar(100) , @date2 nvarchar(100) , @countgap int,@count int set @date1='2009-05-12' set @date2 = '2009-05-13' ...

GROUP BY, ORDER BY - How to make group by consider latest apperance of item

I have a query like this (Mysql 5.X, PHP - formatted for legibility) $query =" SELECT p.p_pid, p.p_name, p.p_url FROM activity a, products p WHERE a.a_uid= ".$uid_int." AND a.a_pid > 0 AND p.p_pid = a.a_pid GROUP BY a.a_pid ORDER BY a.a_time DESC LIMIT 6 "); In general it should produce a unique list ...

Why are my SQL statement count different fields from differrent tables in one SQL statement?

I have a SQL query: SELECT e.name as estate_name , g.name as governing_body , count(s.id) as total_stands , count(sp.id) as service_providers FROM estates e LEFT JOIN governing_bodies ON e.governing_body_id = g.id LEFT JOIN stands s ON s.estate_id = e.id LEFT JOIN services sp ...

CLR Stored Procedures: how to set the schema/owner?

Hi there, I am working on a Linq based CLR Stored Procedure for some complex filtering and manipulation, which would otherwise require a lot of messy and poorly performant T-SQL code, if implemented in a more "traditional" Stored Procedure. This is working great, but I can't find how to set the schema of this Stored Procedure in phase ...

Need a good version control for SQL and Crystal Reports

We have several large data stores where we warehouse data for metric reporting. One is SQL 2000 and the other is 2005. We use Crystal Reports 11 as our reporting tool. Over the past several weeks we've had a couple very visible reports "crash" due to changes in the Db or changes within the reports. To minimalize these errors I am look...

Char(4) versus int as StatusID/StatusCode column in a table

I need a status column that will have about a dozen possible values. Is there any reason why I should choose int (StatusID) over char(4) (StatusCode)? Since sql server doesn't support named constants, char is far more descriptive than int when used in stored procedure and views as constants. To clarify, I would still use a lookup table e...

Linq to SQL Select in Stored Proc

I have a stored proc called via LINQ to SQL the stored proc calls another stored proc within it and has a SELECT to output the result. the SELECT result doesnt' get returned to my LINQ to SQL, I can only get the int result value. How can I get the select result of a stored proc with is within a stored proc ...

How to connect to SQL server database from javascript?

Can any body give me some sample source code showing how to connect to a SQL server 2005 database from javascript locally.I am learning web programming on my desktop.Or do I need to use any other scripting language. Suggest me some alternatives if u have. (but I am now trying to do it with javascript).Thanks in advance.My sql server is l...

How do I split a .sql script into multiple files?

I am using the DatabasePublishingWizard to generate a large create script, containing both data and schema. The file it produces is ginormous so opening the script to fix any syntax errors is next to impossible and machines with less than 4gb have a hard time getting it to run! What should I do and how should I do it? Thanks everyone for...

Synchronizing sql mobile data with mysql server

Hi, We can synchronize the data from SQL mobile with SQL Server. But i need to synchronize the mobile data with mysql server. Is there any way to accomplish my requirement...? ...

How to perform arithmetic operation on Oracle timestamps (in SQL)?

I need to select an entity that is valid at the midth of the validity of different entity. As a simplified example, I want to do something like this: select * from o1, o2 where o1.from < (o2.to - ((o2.to - o2.from) /2) ) and o1.to > (o2.to - ((o2.to - o2.from) /2) ) How can I compute "(o2.to - ((o2.to - o2.from)...

MySQL double query situation

Is there another way to do this Query ? $query = "SELECT * FROM produto, pt WHERE produto.refPT = pt.ref AND produto.refPT IN (SELECT idProduto FROM amb_prod WHERE idAmbiente='1');"; $result_set = mysql_query($query); The problem is my localhost have the MySQL version 5.1.30-community, but my Online server have the 5.0....

What is the best way to define a column in SQL server that may contain either an integer or a string?

I have a situation where two objects of the same type have parents of different types. The following pseudo code explains the situation the best: TypeA a1, a2; TypeB b; TypeC c; a1.Parent = b; a2.Parent = c; To complicate things even further TypeB and TypeC may have primary keys of different types, for instance, the following assertio...

"<>" vs "NOT IN"

I was debugging a stored procedure the other day and found some logic something like this: SELECT something FROM someTable WHERE idcode <> (SELECT ids FROM tmpIdTable) This returned nothing. I thought it looked a little odd with the "<>" so I changed it to "NOT IN" and then everything worked fine. I was wondering why this is? This is ...

SQL query to make all data in a column UPPER CASE?

Working on some legacy software that is kind of wobbly, found a quick way (hopefully) to stabilize it but need to run some queries on the tables to make some columns entirely UPPER CASE. Any ideas? ...

How do I store a binary file in an sql database?

I have a varbinary column we use to store excel files. I need to update this column with the contents of a different xls file that is currently on my filesystem. Given a java.sql.Connection, how should I update the row? We are using sql server 2005. ...