primary-key

Database Design: Composite key vs one column primary key

A web application I am working on has encountered an unexpected 'bug' - The database of the app has two tables (among many others) called 'States' and 'Cities'. 'States' table fields: ------------------------------------------- idStates | State | Lat | Long ------------------------------------------- 'idStates' is an auto...

Primary Keys in Oracle and SQL Server

What's the best practice for handling primary keys using an ORM over Oracle or SQL Server? Oracle - Should I use a sequence and a trigger or let the ORM handle this? Or is there some other way ? SQL Server - Should I use the identifier data type or somehow else ? ...

What is the difference between a primary key and a unique constraint?

Someone asked me this question on an interview... ...

PHP Unable to echo ID field from MySQL database

I'm trying to print an ID from MySQL, the field loads into an array and is visible via print_r but I can't echo it or transfer it to another variable ... what am I missing? if ( $_POST['section'] == "freelance" ) { $field_name = "promoter"; } else { $field_name = "connector"; } echo $row[$field_name.'_login_ID'] As requested t...

sql server 2005

hi friends I have to update the primary key. When i am inserting in a data grid it newly inserting a record. I am unable to. What is the reason, pls help me. ...

Using datetime float representation as primary key

From my experience I have learn that using an surrogate INT data type column as primary key esp. an IDENTITY key column offers better performance than using GUID or char/varchar data type column as primary key. I try to use IDENTITY key as primary key wherever possible. But recently I came across a schema where the tables were horizonta...

MySQL Table primary keys

Greetings, I have some mysql tables that are currently using an md5 hash as a primary key. I normally generate the hash with the value of a column. For instante, let's imagine I have a table called "Artists" with the fields id, name, num_members, year. I tend to make a md5($name) and use it has an ID. I would like to know what are the ...

Primary Key when storing a lot of data for a short period of time

Hi, i'm having doubts on how to create a table for temporary storing error messages. A lot of inserts and deletes A GUID as foreign key, likely to be left outer joined A simple nvarchar field for the ErrorMessage Which primary key, if any, and indexes should I use for storing a lot of data for a short period of time? Thanks ...

Create a unique primary key (hash) from database columns.

I have this table which doesn't have a primary key. I'm going to insert some records in a new table to analyze them and I'm thinking in creating a new primary key with the values from all the available columns. If this were a programming language like Java I would: int hash = column1 * 31 + column2 * 31 + column3*31 Or something l...

Choice of primary key type

I have a table that potentially will have high number of inserts per second, and I'm trying to choose a type of primary key I want to use. For illustrative purposes let's say, it's users table. I am trying to chose between using GUID and BIGINT as primary key and ultimately as UserID across the app. If I use GUID, I save a trip to databa...

How to determine a primary key for a table in SQL Server?

What I'd like to be able to do via SQL somehow is with a table name as input determine all the fields that make up the primary key. sp_columns doesn't seem to have this field. Any ideas as to where to look? EDIT: This is SQL Server 2005 Statement on Answer: While others may have been right his was the cleanest and easiest to implemen...

How to add composite primary key to table

create table d(id numeric(1), code varchar(2)) After I create the above table how can I add a composite primary key on both fields and also a foreign key? ...

SQL Server Datetime vs Int key performance

For you database design/performance gurus out there. If you have a database that is intended to track financial data for fiscal year periods, is it better/more performance/more clear to do daterange type searches like PaymentDate Between X and Y or is it better to keep a int-key based table with fiscal year periods defined in it and tag...

Fluent NHibernate primary key constraint naming conventions

Is there any way to create a naming convention for my primary key constraints in Fluent NHibernate? I know you can name foreign key constraints, but it does not appear possible to name the primary key constraint. ...

MySQL ALTER TABLE on very large table - is it safe to run it?

I have a MySQL database with one particular MyISAM table of above 4 million rows. I update this table about once a week with about 2000 new rows. After updating, I then perform the following statement: ALTER TABLE x ORDER BY PK DESC i.e. I order the table in question by the primary key field in descending order. This has not given me a...

How to 'insert if not exists' in MySQL?

I started by googling, and found this article which talks about mutex tables. I have a table with ~14 million records. If I want to add more data in the same format, is there a way to ensure the record I want to insert does not already exist without using a pair of queries (ie, one query to check and one to insert is the result set is e...

dbms degree of an entity

if the dgree of an entity is 8. What is the minimum number of attributes required to form the primary key??...Thanks..... ...

Retrieving key attribute names of a given table

Hi all, I am working on a database middleware application again. I want to retrieve the names of all key values of a given table. For instance: CREATE TABLE foo(A INTEGER PRIMARY KEY, B VARCHAR(255)) I want to ask Oracle for the primary keys of 'foo' and I want to get 'A'. Is this possible in Oracle at all? I tried to search their d...

core data or sqlite or plist files

Hello, I have a situation where I need to store the data in local (iphone) and the same data will be in the web server to be accessed by other users (like sending messages) . For the web server part I am not worrying, I created all the tables and relations. but I am worrying about Iphone side data storage and sync both sides correctly....

Get Primary Key Value From SQLite database using Core Data in Iphone

Hi, I want to use core data in my application with back end Sqlite store. But I need the Primary key (auto inc Integer) value after an insert which I want to send this primary key value to a web server. Is there any way to get the primary key of the record from sqlite database through the core data feature ? I don't want the unique I...