sql

Best way to do 10,000 inserts in a SQL db?

What happens is whenever i upload media onto my site; everyone will get a notification. Each person can click a box to remove and it will be gone from their msg queue forever. If i had 10,000 people on my site how would i add it to every person msg queue? I can imagine it takes a lot of time so would i opt for something like a filesyste...

Suggestions for insert with Foreign key constraint in mysql

I have a table containing 2 entries. Something like CREATE TABLE `db`.`main` ( `id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) ); The id for these 2 entries are automatically generated primary keys. I have another table with a rule linking CREATE TABLE `db`.`day` ( `main_id` int(10) unsigned NOT NULL, `day` tinyi...

SQL - How to INSERT to a column who's name is a sql keyword ("Key")

I need a table that stores key-value pairs, so I created one with a column called "Key" and a column called "Value". This fails: insert into mykeyvalues (Key,Value) values ('FooKey', 'FooValue') "Incorrect syntax near the keyword 'key'." Maybe I shouldn't call it "Key", but I just wonder if it is possible to work with a column who...

Is using MS SQL Identity good practice?

Is using MS SQL Identity good practice in enterprise applications? Isn't it make difficulties in creating business logic, and migrating database from one to another? ...

SQL: Select the highest conditional sum on a table

I have an OrdersProducts tables with order_id, product_id, and quantity fields. I'd like to know the most popular products, so how can I sum the quantity field for each product_id separately and then order the sums? Any pointers would be appreciated. I'm using MySQL 5.3, thanks. ...

Rails find query with no duplicates

How do I change the following bit of code so that I only have records with distinct sender_id and message_id combinations: @roles = Role.find_all_by_simulation_id(session[:sim_id]) @messages = RolesMessages.find(:all, :conditions => ["sender_id IN (?) ", @roles.map(&:id)], :order => 'created_at DESC') ...

Should SQL format the output or just retreive the raw data?

Generally speaking, the SQL queries that I write return unformatted data and I leave it to the presentation layer, a web page or a windows app, to format the data as required. Other people that I work with, including my boss, will insist that it is more efficient to have the database do it. I'm not sure that I buy that and believe that e...

SQL Server 2005 restore one schema only

I am pretty sure this isn't possible.... We have a database with several schemas. Each schema belongs to a different user. One user was asking "if I find out I made a whole load of errors would it be possible to revert to the state my data was in yesterday". Obviously we could restore the whole database, but that would restore the other...

PLSQL functions help

Hi all, I have this SELECT below which i have to run it in a LOOP for every activity_id(record) that i get from the join. Also,this SELECT has to be run in multiple places in a procedure to get details and for that records-->I run the assign_ course or assign_test as below. Can anyone please help me write a function which would have t...

SQL: Insert multiple sets of values in one statement?

Is it possible to insert multiple sets of values to a SQLite table in one statement? I was trying: INSERT INTO the_table VALUES (1,2,'hi'),(2,0,'foo'); with the different ()s representing different insert sets, but I get an error. ...

what is best practices for multilanguage database design?

What is the best way to create multilanguage database? To create localized table for every table is making design and querying complex, in other case to add column for each language is simple but not dynamic, please help me to understand what is the best choose for enterprise applicationsThanks a lot! ...

Get string representation of a sql DateTime day

Hi all, Let's say i have a sql datetime of '1 May 2009' or '12 May 2009'. Is there any built in sql function / operation i can perform on the dates above to return the string representation of the DAY of the date? So for '1 May 2009' i'll get "Friday" as the answer (case not important). For '12 May 2009' i'll get "Tuesday". ...

sql server login

hi, im writing a vb.net application which connect to a db using integrated security. however, i wanted to implement a login screen so that the user enters their NT user name and password for initially connecting. this is because our information governance team want to verify the someone else is not using a machine without authorisation....

How to write this query in LINQ?

Following query is used for Getting Categories and one news for each category. How can I write this query using LINQ SELECT * FROM News n where n.NewsID IN (SELECT TOP 1 NewsID FROM News v WHERE v.CategoryID = n.CategoryID ORDER BY CreatedOn DESC) Thanks in advance. ...

Is there common street addresses database design for all addresses of the world?

I am a programmer and to be honest don't know street address structures of the world, just how in my country is structured :) so which is the best and common database design for storing street addresses? It should be so simple to use, fast to query and dynamic to store all street addresses of the world which is identifying just by one i...

When is it safe to use non-parameterized variables in SQL commands?

I'm writing a select query in a C# method which lets client code provide a row ID and get back an object constructed from the row's data. If the row ID is an integer and I have confirmed it's positive, is there any harm in just passing it through using string.Format? I don't see how any damage could be done if they were only allowed to p...

SQL like wrapper for Windows Registry?

The per key handling of updating the registry seems a bit poor when dealing with large volumes of data. Are there any libraries that would treat all keys as tables and allow INSERTS, UPDATES, or SELECTS in a more programmatic fasion? ...

What kind of application should I develop for the purpose of learning right concepts of programming

I work as a ERP programmer, mostly with MS SQL and some kind of scripting programming language. I also wrote some simple projects in C# (a web application for our company and a simple windows service) and I like it very much, so my next job will hopefully be in .NET environment. Now I'm learning C# from a Wrox book and I went through ...

How do I display a java ResultSet visually?

I'm looking for a way to display a java.sql.ResultSet on the screen. preferably built-into java or swing. If neither of those have a decent method that's simple, I'd consider spring. How? ...

Group and count in Rails

I have this bit of code and I get an empty object. @results = PollRoles.find( :all, :select => 'option_id, count(*) count', :group => 'option_id', :conditions => ["poll_id = ?", @poll.id]) Is this the correct way of writing the query? I want a collection of records that have an option id and the number of...