primary-key

DataMapper import primary key

I'm running an import script which imports a CSV dump of a database into a local sqlite database using DataMapper. My models look like this: class Staff include DataMapper::Resource property :staff_id, String, :key => true property :full_name, String end class Project include DataMapper::Resource property :pro...

Indexes and multi column primary keys

Went searching and didn't find the answer to this specific noob question. My apologies if I missed it. In a MySQL database I have a table with the following primary key PRIMARY KEY id (invoice, item) In my application I will also frequently be selecting on "item" by itself and less frequently on only "invoice". I'm assuming I would ...

The best way to structure this database?

At the moment I'm doing this: gems(id, name, colour, level, effects, source) id is the primary key and is not auto-increment. A typical row of data would look like this: id => 40153 name => Veiled Ametrine colour => Orange level => 80 effects => +12 sp, +10 hit source => Ametrine (Some of you gamers might s...

MySQL INSERT only if row doesn't exist, otherwise select the duplicate row.

I am looking for a statement that will try to insert a row into a table, but return the primary key of the duplicate row if one is encountered. One field in the table is the auto incrementing primary key, the other is unique. ...

GUID. and automatic id as primary key in sql databases

SELECT COUNT(*) FROM table_name; check count count+1 is the new primary key starting point then keep on incrementing before every insert operation but what is this GUID? doe sql server provide something where it automatically generates and incremented primary key? any link to description and any help thanks ...

Rails Multi Model 'Primary Key' Validation

Hello, I have three models, say Item, Category, Label. Item can have one Category and many Labels, however each Item record must have a unique combination of Category and/or Labels. I'm using Rails 2.3.5, what is the best way to ensure this integrity? Thanks! ...

Should a database table that contains two columns that are foreign keys have a third column which is the primary key?

I am guessing no, since the foreign keys are the primary keys in their own tables, so they will be unique. More info I am using MySQL and the following three tables are using the InnoDB engine. ======================= ======================= | galleries | | images | |---------------------| |------------...

Can a Microsoft SQL table have more than one Primary Key?

I was always curious but can't find a concise answer. Any help? ...

Consensus? MySQL, Signed VS Unsigned Primary/Foreign Keys

Hello, I have seen a couple threads about what everyone was doing now a days in regards to signed vs unsigned key values. It would seem that unsigned is optimal since it allows twice the number of rows for the same cost. Are there any benefits with signed keys? Is there any standard consensus? Its seems like signed is the answer since "...

How do I tell Hibernate to create a primary key for a many-to-many relationship in an .hbm file?

How do I tell Hibernate to create a primary key for a many-to-many relationship in an .hbm file? ...

Which is best temp. linking method of records which are to be sent to a server for insertion in DB

Hi, [SCENARIO] The scenario is, there is a requirement to send multiple records through XML file to the server, for insertion in the database. These records consists of multiple master and detail tables data linked together through primary and foreign keys. Now the client cannot fill the Primary key and foreign key columns/data in thos...

Schemas and Indexes & Primary Keys : Differences in lookup performance ?

Hi. I have a database (running on postgres, precisely) , with the following structure : user1 (schema) | - cars (table) - airplanes (table, again) ... user2 | - cars - airplanes ... It's clearly not structurized the way classic relational databes should be, but it "just works" as it is now. As you can see, schemas are like prim...

Keys/indexes for revisions of user submitted text

I have a table: id:int revision:int text:ntext In general I will need to retrieve the latest revision of text for a particular id, or (considerably less frequently) add a new row containing a new revision for a particular id. Bearing this in mind, it would be a good idea to put indexes on the id and revision columns. I don't have a pr...

Rails Issue with associations using primary_key+foreign_key options

I want to access a legacy database schema from Rails. I have one table NAGIOS_OBJECTS with a primary key OBJECT_ID and one table NAGIOS_HOST_CHECKS that refers to NAGIOS_OBJECTS with a column HOST_OBJECT_ID. I thus defined the relations as follows: class NagiosObject < ActiveRecord::Base has_one :nagios_host_check, :foreign_key => :ho...

Sqlite: Need to retrieve the automatic primary keys generated for each entry I insert

What's the best way to do this? Note that this is the sqlite version packaged with Google Gears, also. ...

NHibernate - Name Primary key constraint?

Hi, We're starting to using NHibernate at my workplace, including generating the schema from the mappings. One thing our DBAs want is consistent names for the primary and foreign key relationships. I've been able to set the FK constraint name, but looking at the documentation for <id> it doesn't look like there's a way to name the pri...

Methods of using a long varchar key as a lookup key

I'm building a commenting mechanism into an application that allows a programmer/plugin author to implement comment threads in a simple manner. The way I wanted to do this is by using a unique identifier for the comment threads, which took the hard work away from the developer by using a unique key for the thread, where you can place co...

SQL Server composite key problem

I have 2 tables: create table numbers2 ( id1 int IDENTITY(1,1) not null, id2 int not null, primary key(id1, id2) ) and table 2 create table ttt ( id int identity(1,1) not null, first_name varchar(50) null, last_name varchar(50) null, sex varchar(1) check (sex in ('m', 'f')) null, number_id int not null, id_id1 int not null, id_id2 i...

Auto increment a non-primary key field in Ruby on Rails

In a RoR migration, how do I auto increment a non-primary-key field? I'd like to do this in the db definition, and not in the model. ...

INDEX NAME on PRIMARY KEY

Hi, I would like create a table and add to it a Primary Key. As for my understanding MS SQL add a clustered Index on the Primary Key and will name it with a default name. I would like to know if is possible create a table and ASSIGN a custom name for the index created by default or how can i change the default name after the table as ...