sql

Adding a new SQL column with a default value

I am looking for the syntax to add a column to a MYSQL database with a default of 0 and for the life of me i have no idea how to read this Reference ...

SQL Table "Pointer"?

Using SQl Server 2000 I have a stored procedure that joins 2 tables and then returns the data. I want this sp to be able to do this for whatever table name I pass into it, otherwise I'll have the exact same code with the exception of the table name 20 or so times in a giant if statement. Basically, how do I use a variable to point to a t...

how to shorten the url in a mathematical approach

I am looking into the possibility of shortening / encrypting a url which will be from 150 to 250 characters in length to maximum 12 characters using an algorithm. Initially I am doubting it's possible but I wanted to leverage the great minds of StackOverflow :) the algorithm should be one that can be written in classic asp, sql, c#, vb...

Strange Problem With VBA in Access SQL

Hi, I have written this VBA module for a school project in Access 2007, and it works fine in the Immediate Window in the Visual Basic Editor. However when I use it in a query (SQL) the value just doesn't show up. I have no idea why. Here is the module code: Option Compare Database Function LoopIngredients(itemName As String) As Long Di...

Query with no autosort

Possible Duplicates: Ordering MySQL results by IN sequence? Ordering by the order of values in a SQL IN() clause i have the following table called "Products" id desc 1 BL10 2 BL15 3 BL45 4 BL50 well, this is my query SELECT * FROM Products WHERE id IN(3,1,4,2) I want it shows in the same order of clause IN, i.e. 3,1,4...

Automatically generate sql insert statement with dummy data

Possible Duplicate: Quickest way to fill SQL Table with Dummy Data I'm looking for a tool that will generate insert statement for an existing database filled with dummy data. This is meant to allow testing of the system. I'm thinking about something that reads the type of each field and generates data accordingly. If the fiel...

tsql Loop with external query

I am looping through all my databases and aggregating the results into an aggregates database. In my loop I call master.dbo.xp_cmdshell osql C:\whatever.SQL As the loop progresses, the cmdshell takes longer and longer to execute. If I stop the loop and run a single aggregate for one database it executes quickly. Is there anything...

How would I calculate EXPECTED income if I have PAST income data in mySQL?

Ok, I'm just curious what the formula would be for calculating an expected income over the next X weeks/months/etc, if the only data I have in mySQL DB is all past transactions (dates of transactions, amounts, etc) I am thinking taking some averages and whatnot, but I can't think of a specific formula (there must be something along thos...

Query to group by maximum depth of PostgreSQL Ltree?

I want to query for all products with the name "Shania Twain", but I want group them only by the tree with the deepest nlevel. Assuming I have a table like the following with the name categories +---------------+---------------+---------------+ |id |name |tree | +---------------+---------------+---------...

how can I delete date in this table ?

I have table like this create table tbl_1( year int, month int, day int ) insert into tbl_1 values(2009, 11, 30) insert into tbl_1 values(2010, 3, 4) insert into tbl_1 values(2011, 5, 13) insert into tbl_1 values(20011, 12, 24) I want to delete date from 2009-11-30 until 2011-5-13, but I can't because all of columns are i...

How are these tasks done in SQL?

I have a table, and there is no column which stores a field of when the record/row was added. How can I get the latest entry into this table? There would be two cases in this: Loop through entire table and get the largest ID, if a numeric ID is being used as the identifier. But this would be very inefficient for a large table. If a ra...

MySQL and foreign key conflicts when trying to INSERT.

I'm doing the Agile Yii book. Anyway, I'm trying to execute this command: INSERT INTO tbl_project_user_assignment (project_id, user_id) values ('1','1'), ('1','2'); And I get this error: ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`trackstar_dev`.`tbl_project_user_assignment`, CONSTRAINT `F...

How to order by multi relation table 's field?

Hi , I need to generate a list of receipts in rails which need to be ordered by item's order relationship field (payment_method_meta_type.name). Models : Receipt Deposit PaymentMethodMetaType In Deposit Model: class Deposit < ActiveRecord::Base belongs_to :payment_method_meta_type has_many :receipts, :class_name=>"Receipt", ...

MySQL: Error 1628: Comment for table 'customer' is too long (max = 60)

After fixing Error 1253 (http://stackoverflow.com/questions/3567808/mysql-unable-to-fulling-forward-engineering-sakila-sample-into-server), I have Error 1628. Executing SQL script in server ERROR: Error 1628: Comment for table 'customer' is too long (max = 60) Scripts: CREATE TABLE IF NOT EXISTS sakila.customer ( customer_id SMALLI...

Records write locked on a RepeatableRead

I have a SQL Server query (using the LLBL ORM, if that is important to the question) that is doing a large fetch on a set of related tables. This query is being performed in a transaction with the Isolation Level of Repeatable Read, and is being filtered by two 'state' columns in the main table of the query. Will the records being 'wri...

Import SQL database structure to the repository

What do you suggest as good ways to import database structure and commit database structure changes to the repository? Our current procedure is to export the structure into a text file then replace it the the existing text file in the repository. I find it tedious and time-consuming. Are there any utilities to do this? ...

Structure of the DB

I am trying to structure a database for optimal use. But I have no idea how to make that happen. Here is what i will have A category which will have many products and a count for each on of those products For example Restaurants will be the category and the products will be the computer system, cash register and each one of these pro...

How can I return a list of values from a stored procedure?

Well I am calling a stored procedure from another stored procedure and I need it to return something like an array.How can I do it? ...

Find parent based on children properties linq to sql

Lets say we have a sql relationship that can be modeled like this using C# classes public class Parent { public int ID { get; set; } public List<Child> Children { get; set; } } public class Child { public int ID { get; set; } public Parent Parent { get; set; } public int Number { get; set; } } I also know that th...

How to model time representation in the schema

We currently store the hours, minutes part separately to capture time (e.g. 10.30, 14.30). Is this the best way to model time representation (supported databases are h2, mysql, postgres) ...