sql

How does a "Schema changed after the target table was created" error occur?

I hit this error while my web application was trying to execute a SELECT INTO on a MSSQL 2005 database. I really have two questions: What does this error mean and how does this happen? Is there a way to prevent these errors by coding in a different way? ...

How to check the maximum number of allowed connections to an Oracle database?

What's the best way, using SQL, to check the maximum number of connections that is allowed for an Oracle database? In the end, I would like to show the current number of sessions and the total number allowed, e.g. "Currently, 23 out of 80 connections are used". ...

SQL Duplicate Delete Query over Millions of Rows for Performance

This has been an adventure. I started with the looping duplicate query located in my previous question, but each loop would go over all 17 million records...meaning it would take weeks (just running *select count * from MyTable* takes my server 4:30 minutes => mssql 2005). I gleamed information from this site and at this post: http:/...

SQL count query

Hi why doesn't this work in SQL Server 2005? select HALID, count(HALID) as CH from Outages.FaultsInOutages where CH > 3 group by HALID I get invalid column name 'CH' ...

SQL Join question

I have 3 tables Links Link ID Link Name GroupID (FK into Groups) SubGroupID (FK into Subgroups) Groups GroupID GroupName SubGroup SubGroupID SubGroupName GroupID (FK into Groups) Every link needs to have a GroupID but teh SubGroupID is optional. How do i write a SQL query to show: Links.LinkName, Groups.GroupName, SubGroup.SubGro...

Update Month value on datefield in MS sql 2005

I need a way to update the month value on a dateTime field in my db. I'm being past an int value for the month and need to use that for the update. Is it possible to do this in the sql statement or would I be best doing it in c# in the webservice? ...

Spawning multiple SQL tasks in SQL Server 2005

I have a number of stored procs which I would like to all run simultaneously on the server. Ideally all on the server without reliance on connections to an external client. What options are there to launch all these and have them run simultaneously (I don't even need to wait until all the processes are done to do additional work)? I h...

Is there a way to get types/names of an unknown db query without executing it?

I have a web application where users enter arbitrary sql queries for later batch processing. We want to validate the syntax of the query without actually executing it. Some of the queries will take a long time, which is why we don't want to execute them. I'm using Oracle's dbms_sql.parse to do this. However, I now have a situation where...

Microsoft Access - SQL - Internal Foreign Key

Does MS Access 2007 support internal foreign keys within the same table? ...

SQL query: Simulating an "AND" over several rows instead of sub-querying

Suppose I have a "tags" table with two columns: tagid and contentid. Each row represents a tag assigned to a piece of content. I want a query that will give me the contentid of every piece of content which is tagged with tagids 334, 338, and 342. The "easy" way to do this would be (pseudocode): select contentid from tags where tagid ...

OPTION(MAXDOP 1) in SQL Server

I have never clearly understood the usage of MAXDOP. I know it makes the query faster and thats the last that I can use in Query Optimization. But when and where it is best suited.. Thanks Guys!!! ...

Is it possible to determine when a stored procedure was last modified in SQL Server 2000?

I know that you can do this in SQL Server 2005, but I'm at a loss for 2000. ...

Converting a UNION query in MySQL

Hi All, I have a very large table (8gb) with information about files, and i need to run a report against it that would would look something like this: (select * from fs_walk_scan where file_path like '\\\\server1\\groot$\\%' order by file_size desc limit 0,30) UNION ALL (select * from fs_walk_scan where file_path like '\\\\server1\\hro...

Informix SQL Syntax - Nest Count, Sum, Round

Let me apologize in advance for the simplicity of this question (I heard Jeff's podcast and his concern that the quality of the questions will be "dumbed down"), but I'm stuck. I'm using AquaData to hit my Informix DB. There are quirky little nuances between MS SQL and Informix SQL. Anyway, I'm trying to do a simple nested expression ...

Is there any difference between Group By and Distinct

I learned something simple about SQL the other day: SELECT c FROM myTbl GROUP BY C Has the same result as: SELECT DISTINCT C FROM myTble What I am curious of, is there anything different in the way an SQL engine processes the command, or are they truly the same thing? I personally prefer the distinct syntax, but I am sure it's m...

Calling stored procedures

I have a c# application that interfaces with the database only through stored procedures. I have tried various techniques for calling stored procedures. At the root is the SqlCommand class, however I would like to achieve several things: make the interface between c# and sql smoother, so that procedure calls look more like c# function ...

how to compare/validate sql schema

I'm looking for a way to validate the SQL schema on a production DB after updating an application version. If the application does not match the DB schema version, there should be a way to warn the user and list the changes needed. Is there a tool or a framework (to use programatically) with built-in features to do that? Or is there som...

SQL query for cumulative frequency of list of datetimes

I have a list of times in a database column (representing visits to a website). I need to group them in intervals and then get a 'cumulative frequency' table of those dates. For instance I might have: 9:01 9:04 9:11 9:13 9:22 9:24 9:28 and i want to convert that into 9:05 - 2 9:15 - 4 9:25 - 6 9:30 - 7 How can I do that? Can i ev...

SQL 2005 Foreign key between another base

Is it possible to create in a table of database a foreign key to a column of table in another database in SQL 2005 ? ...

SQL Query which returns a table where each row represents a date in a given range

Is it possible to create a SQL query which will return one column which contains the dates from a given date range (e.g. all dates from last year till today). E.g. dat ---- 2007-10-01 2007-10-02 2007-10-03 2007-10-04 ... I am wondering if this is possible as an alternative to creating a table which holds all those dates precalculated....