sql

Some SQL Questions

Hello there, I have been using SQL for years, but have mostly been using the query designer within SQL Studio (etc.) to put together my queries. I've recently found some time to actually "learn" what everything is doing and have set myself the following fairly simple tasks. Before I begin, I'd like to ask the SOF community their thoug...

Why no love for SQL?

I've heard a lot lately that SQL is a terrible language, and it seems that every framework under the sun comes pre-packaged with a database abstraction layer. In my experience though, SQL is often the much easier, more versatile, and more programmer-friendly way to manage data input and output. Every abstraction layer I've used seems...

Partition Or Separate Table

I am designing database for fleet management system. I will be getting n number of records every 3 seconds. Obviously, there will be millions of record in my table where I am going to store current Information of vehicle in the current_location table. Here performance is an BIG issue. To solve this, I received the following suggestions...

How to insert a blob into a database using sql server management studio

Hi, How can I easily insert a blob into a varbinary(MAX) field? for argument sake: assume the thing I want to insert is: c:\picture.png the table is mytable the column is mypictureblob and the place is recid=1 I've been googling for some time and I can't find a simple solution thanks! ...

MySQL: select the closest match?

I want to show the closest related item for a product. So say I am showing a product and the style number is SG-sfs35s. Is there a way to select whatever product's style number is closest to that? Thanks. EDIT: to answer your questions. Well I definitely want to keep the first 2 letters as that is the manufacturer code but as for the p...

How do I force SQL Server 2005 to run a join before the where?

I've got a SQL query that joins a pricing table to a table containing user-provided answers. My query is used to get the price based on the entered quantity. Below is my SQL statement: SELECT JobQuestion.Value, Price.Min, Price.Max, Price.Amount FROM Price INNER JOIN JobQuestion ON Price.QuestionFK=JobQuestion.QuestionFK ...

T-SQL: finding a group by its members

Given the following two tables in SQL Server 2005: IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'GroupItems') DROP TABLE GroupItems; CREATE TABLE GroupItems ( RowID INT IDENTITY(1,1) PRIMARY KEY , GroupID CHAR(1) , ItemID INT ); IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME...

rename tables columns in mysql

Hi, I would like to rename a table column in MySql and also have the name updated in any triggers, stored procs, etc. that reference the column. This does not appear to happen by default when using the alter table command. If a tool exists that can perform such a refactoring, it would be great if it could generate an SQL script that ap...

What's wrong with this query?

UPDATE `t` SET `col_x` = (SELECT `col_x` FROM `t` WHERE `col_y`='123456') WHERE `col_y`= '456789' MySQL version 4.0.27 I tried few changes - with LIKE '%123456%', without backticks mysql seems to not know subquery. it's error is "You have an error in your SQL syntax ..." thanks Error message: #1064 - You have an error in your SQL...

Get the maximum value of rows from database table

I need to write a SQL query which will get me those rows from the table which have the max value of files. The database table is as follows: > ID status dept files > > > 1 1 23 1256637314 > > > > 1 1 39 1256642968 > > > > 2 0 85 1256551419 > > > > 2 1 90 1256642968 > > > > 2 1 93 1256810937 > > > > 3 0 20 1256642968...

Ignoring spaces between words - an SQL question

I want to grab from a db a record with name='John Doe'. I'd like my query to also grab 'John(4 spaces between)Doe','John(2 spaces betwewen)Doe' etc. (at least one space however). I'd also like that the case won't matter, so I can also get 'John Doe' by typing 'john doe' etc. ...

Why does bcp output null when the column contains an empty string and empty string when the column is null?

This struck me as really weird behaviour and I spent a while checking for bugs in my code before I found this "out copies from the database table or view to a file. If you specify an existing file, the file is overwritten. When extracting data, note that the bcp utility represents an empty string as a null and a null string as an empty ...

Firebird 2.0 transaction SELECT performance

In Firebird 2.0, is using an explicit transaction faster on a SELECT command than executing the command with an implicit one? ...

Two If selection while a select query

Hello I have this query : SELECT o.id, o.id as oid, o.id as orderId, o.cid, o.date, o.state, o.price, o.currency, o.lastChange, o.url AS permalink, o.period, o.bloggerId, o.bloggerShare, o.offerValidity, o.rebate, o.cid, o.reason, o.bidReason, o.bidDate, o.bidPeriod, o.rate, o.lastChange2, o.permalinkDate, o...

Not able to remove injected script from database rows

I've been handed a MS SQL 2000 database which has been injected with malware. The malware script is as follows: <script src=http://www.someAddress.ru/aScript.js&gt;&lt;/script&gt; Now I want to remove this piece of code from the table rows. As a test, I inputed < h1> Test < /h1> on a row, and successfully ran the following query: UP...

Recommendation for JDBC SQL client tool

Can someone recommend a good, open source, standalone developer tool for querying SQL databases using JDBC and exporting the results to a file? I know a lot of database vendors provide their own tools, but I need one that will allow me to plug in my own custom JDBC driver and work against any database. A GUI is preferable, but not requir...

Creating tables with something similar to INFORMATION_SCHEMA.VIEW_DEFINITION in SQL Server

Is there a standard method to retrieve the 'CREATE TABLE..' definition of a table in SQL Server? I can ask INFORMATION_SCHEMA for definitions of views and functions/procedures, so I thought it would be natural to get the same for tables, but I didn't find anything. ...

merge msaccess tables

How can i merge two identical tables of two msaccess identical db? For eg: db1..table1 ID Name 1 Sanjana 2 Parul 3 Rohan db2...table1 ID Name 1 Sarika 2 Deepak I want to append the values of second table into first as follows: ID Name 1 Sanjana 2 Parul 3 Rohan 4 Sarik...

DROP...CREATE vs ALTER

When it comes to creating stored procedures, views, functions, etc., is it better to do a DROP...CREATE or an ALTER on the object? I've seen numerous "standards" documents stating to do a DROP...CREATE, but I've seen numerous comments and arguments advocating for the ALTER method. The ALTER method preserves security, while I've heard...

How do I add a column to large sql server table

I have a SQL Server table in production that has millions of rows, and it turns out that I need to add a column to it. Or, to be more accurate, I need to add a field to the entity that the table represents. Syntactically this isn't a problem, and if the table didn't have so many rows and wasn't in production, this would be easy. Reall...