insert

Insert into temp values (select.... order by id)

I'm using an Informix (Version 7.32) DB. On one operation I create a temp table with the ID of a regular table and a serial column (so I would have all the IDs from the regular table numbered continuously). But I want to insert the info from the regular table ordered by ID something like: CREATE TEMP TABLE tempTable (id serial, folio ...

SQL Server - How to insert a record and make sure it is unique

Hi Folks, I'm trying to figure out the best way to insert a record into a single table but only if the item doesn't already exist. The KEY in this case is an NVARCHAR(400) field. For this example, lets pretend it's the name of a word in the Oxford English Dictionary / insert your fav dictionary here. Also, i'm guessing i will need to ma...

How to insert rows when using a many-to-many relation

Given the following, how could I insert rows in my db? (Or what should I correct in my schema?) Models: class Item < ActiveRecord::Base has_many :tran_items has_many :transactions, :through => :tran_items end class TranItem < ActiveRecord::Base belongs_to :item belongs_to :transaction end clas...

SQL - How to make a conditional INSERT

Using only MySQL, I'm seeing if it's possible run an insert statement ONLY if the table is new. I successfully created a user variable to see if the table exists. The problem is that you can't use "WHERE" along with an insert statement. Any ideas on how to get this working? // See if the "country" table exists -- saving the result to a ...

What is the best way to insert into and update a single row table in MySQL?

I have a MySQL table that will only have one row. What should my statement be for the first time I insert to this row, and for subsequent updates? I tried an insert where the primary key equals 1, but this doesn't account for the first time around when no row exists yet. Thanks! ...

What is the best way to achieve speedy inserts of large amounts of data in MySQL?

I have written a program in C to parse large XML files and then create files with insert statements. Some other process would ingest the files into a MySQL database. This data will serve as a indexing service so that users can find documents easily. I have chosen InnoDB for the ability of row-level locking. The C program will be gene...

SQL insert into related tables

This seems to me to be the kind of issue that would crop up all the time with SQL/database development, but then I'm new to all this, so forgive my ignorance. I have 2 tables: CREATE TABLE [dbo].[Tracks]( [TrackStringId] [bigint] NOT NULL, [Id] [bigint] IDENTITY(1,1) NOT NULL, [Time] [datetime] NOT NULL, CONSTRAINT [PK_Tra...

Why does my INSERT sometimes fail with "no such field"?

I've been using the following snippet in developements for years. Now all of a sudden I get a DB Error: no such field warning $process = "process"; $create = $connection->query ( "INSERT INTO summery (process) VALUES($process)" ); if (DB::isError($create)) die($create->getMessage($create)); but it's fine if I use numerics $process =...

Is it possible to do count(*) while doing insert...select... query in mysql/php ?

Is it possible to do a simple count(*) query in a php script while another php script is doing insert...select... query? The situation is that I need to create a table with ~1M or more rows from other table, and while inserting, I do not want the user feel the page is freezing, so I am trying to keep update the counting, but by using a...

Inserting and deleting UITableViewCell at the same time not working

Hiya, I'm having quite a bit of pain inserting and deleting UITableViewCells from the same UITableView! I don't normally post code, but I thought this was the best way of showing where I'm having the problem: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 5; } - (NSInteger)tableView:(UITableView *)t...

How would I insert data into an Access table using vb.net?

I want to insert a new row into an Access database. I'm looking at doing something like: oConnection = new Connection("connectionstring") oTable = oCennection.table("Orders") oRow = oTable.NewRow oRow.field("OrderNo")=21 oRow.field("Customer") = "ABC001" oTable.insert Which seems to be a sensible way of doing things to me. However...

SqlSelect: Update if exists, Insert if not - With date part comparison?

I need to update a record in a database with the following fields [ID] int (AutoIncr. PK) [ScorerID] int [Score] int [DateCreated] smalldatetime If a record exists for todays date (only the date portion should be checked, not the time) and a given scorer, I'd like to update the score value for this guy and this day. If the scorer do...

Getting primary key after an insert in asp.net (visual basic)

I'm adding a record like this: Dim pathString As String = HttpContext.Current.Request.MapPath("Banking.mdb") Dim odbconBanking As New OleDbConnection _ ("Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" + pathString) Dim sql As String sql = "INSERT INTO tblUsers ( FirstName, LastName, Addre...

Inserting rows in table that has a relationship with another table

In my database schema I have an entity that is identified. The identifier can be reused and thus there is a one-to-many relation with the entity. Example: A person can have a nickname. Nicknames are not unique and can be shared amongst many people. So the schema might look like: PERSON id name nickname_id NICKNAME id name The issue i...

How does one insert a column into a dataset between two existing columns?

I'm trying to insert a column into an existing DataSet using C#. As an example I have a DataSet defined as follows: DataSet ds = new DataSet(); ds.Tables.Add(new DataTable()); ds.Tables[0].Columns.Add("column_1", typeof(string)); ds.Tables[0].Columns.Add("column_2", typeof(int)); ds.Tables[0].Columns.Add("column_4", typeof(string)); ...

Faster bulk inserts in sqlite3?

I have a file of about 30000 lines of data I want to load into a sqlite3 database. Is there a faster way that generating insert statements for each line of data? The data is space delimited and maps directly to the sqlite3 table. Is there any sort of bulk insert method for adding volume data to a database? Has anyone devised some devio...

Faster Insert Oracle Hash Cluster Table

Hi! Since I kicked off the process of inserting 7M rows from one table into two others, I'm wondering now if there's a faster way to do this. The process is expected to finish in an hour, that's 24h of processing. Here's how it goes: The data from this table RAW (word VARCHAR2(4000), doc VARCHAR2(4000), count NUMBER); should find a...

Inserting data into SQL Table with Primary Key. For dupes - allow insert error or Select first?

Given a table such as: CREATE TABLE dbo.MyTestData (testdata varchar(50) NOT NULL) ALTER TABLE dbo.MyTestData WITH NOCHECK ADD CONSTRAINT [PK_MyTestData] PRIMARY KEY CLUSTERED (testdata) And given that we want a unique list of 'testdata' when we are done gathering items to be added from a list of external data with known duplicates...

How do I generate ids with NHibernate and Firebird?

I'm trying to insert some new objects into a firebird database using NHibernate. I get the error "could not get next sequence value[SQL: SQL not available]" Here is the mapping I'm using at present. Note ANML_EVNT is the name of the generator I want to use. <id name="Id" column="ID" type="integer"> <generator class="sequence"> ...

What is the benefit of update instead of doing delete and then Insert in the same table.

Hi, I have a table say example "ABC", I have a row that needs to be stored in to this "ABC" table. I plan to update it instead of doing delete from the table and then insert. What is the impact that this will make on database? In, table level, page level, time, cost and every thing. thanks Thiru ...