sql

oracle sql precision,scale ,insert calculate and drop

table = mytable temp col = tempcol col = mycol currently contains 5000 rows various values from 99999.99999 to 0.00001 I need to keep the data create a script to create a temp column,round the values to 7,3 update mycol to a null value, modify my column from 10,5 to 7,3 return the data to mycol, drop the temp column. Job done. so far...

How can I learn to optimize sql queries

I know how to write SQL queries and can get the results I need. But sometimes my queries are slow and I don't fully understand why. What are some good resources for learning to write efficiant queries and to optimze the quries I've allready written? ...

Recursive query that returns itself and all of its descendants

My Table 'Levels' in a SQL Server 2005 database looks like this: LevelId Description ParentLevelId 0 Level_1 NULL 1 Level_2 0 2 Level_3 0 3 Level_4 1 4 Level_5 3 I now want to create a query that will produce a results set in which every level and all of i...

SQL/C# - Best method for executing a query

Hi everyone I need to execute a sql query from within a c# class. I have thought of 2 options Starting a process of sqlcmd. Using a SqlCommand object. My question is which would be the better way? It's important that the solution only holds a connection to the server for a short time. I'm open to other ideas if the above aren't goo...

how to get all SQL keywords in Java

I need to have a list of all SQL keywords of particular DB engine in my Java program. I know that I can use DatabaseMetaData.getSQLKeywords() method from JDBC to list all DB specific SQL keywords that are not in ANSI:2003 But how I get a list of all ANSI (standard) SQL keywords? P.S. don't suggest to hardcode them, I still hope someon...

Convert SQL query to LINQ

Hello everybody, I have a beginners LINQ2SQL question. I have this huge (but not complex) SQL statement: SELECT Artikel.ArtikelID, Artikel.CategorieID, Artikel.ImageFile, Artikel.RetailPrijs, ISNULL(ShopArtikel.VerkoopsPrijs, Artikel.VerkoopsPrijs) AS VerkoopsPrijs, Artikel.ArtikelCode, A...

SQL in Python 3.0 ?

How to use any SQL database eg. mysql, pgsql or other except the ones Python has built-in support for? def example(): con= Mysql("root", blablabla) con->query("SELECT * bla bla bla") .... ...

SQL Server Enterprise Manager - Mass Delete of Tables and Changing Ownership of Tables

I have pretty much no experience with SQL Server's Enterprise Manager so I am not sure if this is even possible (or hopefully laughably simple!) During an import into a database something has happened where each table has duplicated itself with two important differences. The first is that the Owner on both tables is different, the seco...

Entering dates into a SQL database

The problem I'm having at the moment is that the date is being entered into the SQL database as 30/12/1899. I'm using Access 2003 for the database and can't think of any potential reason why this is happening! window.status='Loading contingency scripts - please wait...'; audit('Loading contingency scripts'); var conting={ i:0 ,start:fu...

Query works in PostgreSQL but fails with HSQL. How can I fix it?

Dear SQL gurus ;-) I have the following query (inherited from legacy) similar to SELECT bla FROM table WHERE some.id IN ( SELECT id FROM ( SELECT some FROM tag WHERE bla UNION SELECT some FROM dossierinfo WHERE bla ORDER BY tag LIMIT :limit OFFSET :offset ) AS aggregated WHERE dossier_type = ...

Need advice concerning the restoration of an sql 2005 Database

Hello. Our goal is to restore a test environment from our live environment, so basically we would like to simply backup our current live databases, and just restore them in our test server. However... we do not have enough room to move the backups, one of our databases is 50 GB, and we only have around 20 GB free(the backup is 40 GB u...

how to solve this particular query?

table1 table2 col1 date col1 date a d1 e d4 b d2 f d5 c d3 a d6 I want a new table which have 4 entries order by date but if any entries of column 1 replicate it remove this duplication also. suppose if my date order is d1>d6>d2>d3>d5>d4 then result should be: col1 date a d1 b ...

SqlDbType and Geography

What SqlDbType enumeration should I use when my column is the Geography type? I'm using MS SQL Server 2008 R2. This is what I'm looking for specifically: // ADO.net - what do I use for the SqlDbType when it's defined // as Geography in the stored proc SqlCommand command = new SqlCommand(); command.CommandText = "dbo.up_Foobar_Insert"...

Trigger for update multi line

Hi, I'm having a problem with this trigger: ALTER TRIGGER [dbo].[trg_B_U_Login] ON [dbo].[Login] FOR UPDATE AS BEGIN IF @@ROWCOUNT = 0 RETURN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @Campos nvarchar(500); DECLARE @Old...

Update or Insert (multiple rows and cols) from Subquery in PostgreSQL

hi folks, i'm trying to do something like this in postgres: UPDATE table1 SET (col1, col2) = (SELECT col2, col3 FROM othertable WHERE othertable.col1 = 123); INSERT INTO table1 (col1, col2) VALUES (SELECT col1, col2 FROM othertable) but point 1 is not possible even with postgres 9.0 as mentioned in the docs (http://www.postgresql.or...

Can I avoid all SQL-injection attacks by using parameters?

Can I avoid all SQL-injection attacks by using parameters? And don't worry about any thing in SQL injection in this case? Or are there some types of these attacks which require more care on the part of the programmer? ...

How to add column in a table on fly?

i want to add two tables. But how should i distinguish that which entries is from which table? table1 col1 ----- a b c table 2 1 2 3 The result should be: col1 tablename ---------------- a table1 b " c " d table2 e " f " ...

SQL Stored proc, select data from secondary tables

I am trying to modify a stored procedure I wrote to pull data from other tables and insert it to a table. Basically I have one table where we store mappings by ID. In that table I put together a field that should be storing the concatenation of that data, which works fine. The problem is it is storing the ID of the mapping, not the name...

Show SQL errors of Spring-security in tomcat.

I got a web application using the spring-security framework. I setted up a database to store users and their roles, but tomcat gives the following error. 17-sep-2010 11:56:14 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [org/springframework/...

SQL - Correct query for sorting items by values from other table

Hi there! I've got a little problem with correct query and hope you can help me. My testing tables structures are as follow: CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), ) ; CREATE TABLE IF NOT EXISTS `user_throws` ( `id` int(11) NOT NULL AUTO_I...