sql

How to restrict NULL as parameter to stored procedure SQL Server?

Hi, Is it possible to create a stored procedure as CREATE PROCEDURE Dummy @ID INT NOT NULL AS BEGIN END Why is it not possible to do something like this? ...

Are Databases and Functional Programming at odds?

I've been a web developer for some time now, and have recently started learning some functional programming. Like others, I've had some significant trouble apply many of these concepts to my professional work. For me, the primary reason for this is I see a conflict between between FP's goal of remaining stateless seems quite at odds wi...

T-SQL: How to make cell-values unique?

If I have a table where the cells in a column should not have the same values, how do I check this and update? (I know I can set constraints in the settings, but I don't want to do that.) Say the column name is called unique hash name and contains Peter Peter Peter Dave Dave and so on. I want that to transform to: Peter Peter1 Pe...

SQL find non-null columns

I have a table of time-series data of which I need to find all columns that contain at least one non-null value within a given time period. So far I am using the following query: select max(field1),max(field2),max(field3),... from series where t_stamp between x and y Afterwards I check each field of the result if it contains a non...

How to insert a record and return the newly created ID using a single SqlCommand?

I'm using an SqlCommand object to insert a record into a table with an autogenerated primary key. How can I write the command text so that I get the newly created ID when I use the ExecuteScalar() method? ...

SQL Relationships and indexes

I have an MS SQL server application where I have defined my relationships and primary keys. However do I need to further define indexes on relationship fields which are sometimes not used in joins and just as part of a where clause? I am working on the assumption that defining a relationship creates an index, which the sql engine can r...

Does SQL Server CheckSum calculate a CRC? If not how can I get MS SQL to calculate a CRC on an arbitrary varchar column?

Does SQL Server CheckSum calculate a CRC? If not how can I get SQL Server to calculate a CRC on an arbitrary varchar column? ...

SQL Statement Help - Select latest Order for each Customer.

Say I have 2 tables: Customers and Orders. A Customer can have many Orders. Now, I need to show any Customers with his latest Order. This means if a Customer has more than one Orders, show only the Order with the latest Entry Time. This is how far I managed on my own: SELECT a.*, b.Id FROM Customer a INNER JOIN Order b ON b.CustomerID...

Version Control Algorithm

I have a database where I store objects. I have the following (simplified) schema CREATE TABLE MyObjects ( UniqueIdentifier Id; BigInt GenerationId; BigInt Value; Bit DeleteAction; ) Each object has a unique identifier ("Id"), and a (set of) property ("Value"). Each time the value of the proper...

Maintaining subclass integrity in a relational database

Let's say I have a table that represents a super class, students. And then I have N tables that represent subclasses of that object (athletes, musicians, etc). How can I express a constraint such that a student must be modeled in one (not more, not less) subclass? Clarifications regarding comments: This is being maintained manually, n...

Is the Table in Use?

How to figure out if a table is in use in SQL (on any type database)? if somebody is already using it, or have it "open" then its in use. ...

Are ActiveRecord/nHibernate SQL generation "safe"?

I'm doing this system Stacked and I am creating the search function. And in that process it occurs to me that maybe AR/nHibernate Expression.Like (and siblings) might maybe not be 100% "safe" in that you can create stuff like; "\r\ndrop database xxx;---" and similar things...? I would expect them to be safe, but I am not sure... ...

Access to multiple data sources using Oracle Brio

Trying to build a dashboard using Oracle's Brio. I have to access 6 different databases to grab the same type of data, aggregate it and display it. Except that when I do it, Brio grabs the data from the first source just fine. When I grab the data from the second data source, Brio replaces the original data with the second set. So I ...

Any guides on learning how to interpret a SQL query's Execution Plan in SQL Server 2005?

Is there any good article, tutorial or similar references on interpreting the Execution Plan of a query in SQL Server 2005? ...

separate table for picture items with image field

I store different items (notes, articles, pictures, files) in a single table (there are many metadata in common for all the item types - for example, categories, tags, rating, statistics etc.). My first design was like this: table Items, plus another "detail" table for each of the item types (NoteItems, ArticleItems, PictureItems etc.)....

SQL Timeout error

Guys Getting this error, NativeError = 258 Error = [Microsoft][SQL Native Client]Shared Memory Provider: Timeout error [258]. SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 258 Error = [Microsoft][SQL Native Client]Unable to complete login process due to de...

How to build a tree view with PHP / SQL?

What's the best way to: Get the data from the db using a single query Loop through the results building e.g. a nested unordered list My table has id, name and parent_id columns. ...

Fetching only rows that match all entries in a joined table (SQL)

I have the following five tables: ISP Product Connection AddOn AddOn/Product (pivot table for many-to-many relationship). Each Product is linked to an ISP, each Connection is listed to a Product. Each product can have a number of add-ons, through the use of the pivot table (which simply has 2 fields, one for the product ID and one fo...

SQl Query to Hibernate Query

I have a MYSQL query that I use to retrieve random rows from a table. The query is : SELECT * FROM QUESTION WHERE TESTID=1 ORDER BY RAND() LIMIT 10; Now I need to change this query to Hibernate. Did a bit of Googling but couldn't find the answer. Can someone provide help on this. Thanks ...

sql search query for multiple optional parameters

I'm trying to write a query for an advanced search page on my document archiving system. I'm attempting to search by multiple optional parameters. I have about 5 parameters that could be empty strings or search strings. I know I shouldn't have to check for each as a string or empty and create a separate stored procedure for each combi...