primary-key

How do I use a Rails ActiveRecord migration to insert a primary key into a MySQL database?

I need to create an AR migration for a table of image files. The images are being checked into the source tree, and should act like attachment_fu files. That being the case, I'm creating a hierarchy for them under /public/system. Because of the way attachment_fu generates links, I need to use the directory naming convention to insert ...

Sqlite primary key on multiple columns

What is the syntax for specifying a primary key on more than 1 column in SQLITE ? ...

Database Primary Key's -> An identity field AND a name field?

Hi folks, all my tables have an Id field of some type (UserId, PostId, FooId, etc). I usually make this a Primary Key. A table I have is called Countries. It has CountryId SMALLINT Name VARCHAR(100) -- Yes, english country names only, in this column. AndSomeOtherFields. Now, I know the Name has to be unique. All country names are u...

RDBMS Key Confusion

I'm trying to sort out the database behind my company's website. We deal with both Sites and Residents. At the moment the Site Reference is included in the Residents table as a foreign key but, obviously, this is only in 1NF. Site references are of the form nnnnn (12345, for example). Each resident has their own reference within the Si...

Weird compilation error: An object reference is required for the non-static field, method, or property 'Veryau.Data.VUsergroup.System.get'

Hi, guys, I got a weird compilation error with subsonic and really need your helps. I'm using SQL Server 2005 and there are 30+ tables within this project. Subsonic works well with all other tables except the one named "v_Usergroups". Originally, there was no primary key defined in this table. Naturally, SS will not generate code for i...

Reset primary key

Hi, I've tried to find an answer to do this online but apparently it can't be done (I mean at the app level, not database). I have a need to clear out my dataset completely and reset the primary key at the same time. Any ideas? Alternatively, one hack i can use is to reinitialize the dataset but that doesn't seem possible as well since...

Sqlite3: Disabling primary key index while inserting?

I have an Sqlite3 database with a table and a primary key consisting of two integers, and I'm trying to insert lots of data into it (ie. around 1GB or so) The issue I'm having is that creating primary key also implicitly creates an index, which in my case bogs down inserts to a crawl after a few commits (and that would be because the da...

Why is a GUID is the best choice for a PK if you're going to be doing replication?

I'm building an intranet web app with an Oracle back end. The Oracle DB will be replicated on another server for reasons that aren't important to this discussion. I'm reasonably certain we'll be using Oracle Basic Replication, not Advanced. Can someone explain to me why most discussions around Primary Keys go something like: Use of ...

Preventing Duplicate Keys Between Multiple Databases

I'm in a situation where we have a new release of software coming out that's going to use a separate database (significant changes in the schema) from the old. There's going to be a considerable period of time where both the new and the old system will be in production and we have a need to ensure that there are unique IDs being generat...

Does 'Select' always order by primary key?

A basic simple question for all of you DBA. When I do a select, is it always guaranteed that my result will be ordered by the primary key, or should I specify it with an 'order by'? I'm using Oracle as my DB. ...

SQL: To primary key or not to primary key?

I have a table with sets of settings for users, it has the following columns: UserID INT Set VARCHAR(50) Key VARCHAR(50) Value NVARCHAR(MAX) TimeStamp DATETIME UserID together with Set and Key are unique. So a specific user cannot have two of the same keys in a particular set of settings. The settings are retrieved by set, so if a use...

GUID vs INT IDENTITY

I'm aware of the benefits of using a GUID, as well as the benefits of using and INT as a PK in a database. Considering that a GUID is in essence a 128 bit INT and a normal INT is 32 bit, the INT is a space saver (though this point is generally moot in most modern systems). In the end, in what circumstances would you see yourself using a...

Should a database table always have primary keys?

Should I always have a primary key in my database tables? Let's take the SO tagging. You can see the tag in any revision, its likely to be in a tag_rev table with the postID and revision number. Would I need a PK for that? Also since it is in a rev table and not currently use the tags should be a blob of tagIDs instead of multiple entr...

Copy table + new PK

Hello, I have a table without a PK. The table has about 500 rows so I don't want to write them manually. What's the best way to add a PK? Thank you, Rafa ...

NetBeans 6.7 Beta - Why does it think certain tables have no primary key?

I am using NetBeans 6.7 Beta to create entity classes from a MySQL (version '5.0.45-log') database. NetBeans accepts most tables, but rejects certain ones consistently (I can't see a pattern), saying they have "no primary key". All tables are using the InnoDB engine. All tables have primary keys of one or more columns. The MySQL query br...

How do you resolve a many-to-many collection entity in a RDBMS?

I'm trying to model artists and songs and I have a problem where I have a Song_Performance can be performed by many artists (say a duet) so I have an Artist_Group to represent who the songs is performed by. Well, I now have a many-to-many relationship between Artist and Artist_Group, where an Artist_Group is uniquely identified by the...

Can one rely on the auto-incrementing primary key in your database?

In my present Rails application, I am resolving scheduling conflicts by sorting the models by the "created_at" field. However, I realized that when inserting multiple models from a form that allows this, all of the created_at times are exactly the same! This is more a question of best programming practices: Can your application rely on ...

Making primary key and identity column after data has been loaded.

I have quick question for you SQL gurus. I have existing tables without primary key column and Identity is not set. Now I am trying to modify those tables by making existing integer column as primary key and adding identity values for that column. My question is should I first copy all the records from the table to a temp table before m...

How to get the primary key of an Ms Access table in C#

I need the field or fields (just the name of the field will do) that form the primary key of a Microsoft Access Table, given a connection and a tableName. ...

Should I neccessarily have a PK on the source table to create an ADO.NET Entity Data Model?

I'm trying to "Entitify" some external table (which I don't administer) in order to use it within a MVC application and in principle I'm not being terribly successful with the attempt (VS2008 output): Error List [0 Errors] [0 Warnings] [1 Message] Description The table/view 'DATABASE.dbo.table' does not have a primary key defined and ...