primary-key

When would you ever need to change a primary key's value?

Hello, I've been reading up on foreign keys and such for postgres and I noticed that it allows a cascading update for foreign keys. Well, my question is, when would you need to update the primary key of a row? Apparently this guy needs to http://www.oreillynet.com/onlamp/blog/2004/10/hey_sql_fans_check_out_foreign.html but I'm not qu...

Can primary index be a CHAR in MySQL?

My primary indexes are unique reference numbers like 002345 and 000023. If I format them as integers I loose my zero's. They need to be 6 digits. Can I use CHAR? I don't need any auto increments. ...

Is it necessary to have a Primary key which is sequence generated even though I may not use it for DB operations

Hi I had parent table which has ID and some other columns and a child table which have many values based on this ID(foreign Key). I wanted to create the table with a Primary Key which is sequence and this Parent table ID as Foreign Key but later I found I had one more Foreign Key EMPID which on combination provides uniqueness. Even for r...

Performance - Int vs Char(3)

I have a table and am debating between 2 different ways to store information. It has a structure like so int id int FK_id varchar(50) info1 varchar(50) info2 varchar(50) info3 int forTable or char(3) forTable The FK_id can be a foreign key to one of 6 tables so I need another field to determine which ...

Is there a specific performance issue with Entity Framework + GUID PKs?

My company has a basic SOA, using Entity Framework for database access. One of our services must interface with a legacy database which uses uniqueidentifier primary keys in the database. Performance is good during unit and integration testing. However, under load, the affected service starts to produce a backlog of queued requests. Thi...

How to convert clustered primary key to non-clustered without dropping referring foreign keys in SQL Server 2005

I've made mistake creating clustered primary key on GUID column. There are many tables that reference that table with defined foreign keys. Table size is not significant. I would like to convert it from clustered to non-clustered without manually dropping and recreating any foreign keys or even primary key constraint. Is it possible to...

Possible to condense primary key/serial?

Hello, I have a database where everything is linked with foreign keys, so the Postgres knows exactly how the database is layed out.. Well, Lets say I have Table1 and Table2. Table1 has 3 fields. RID, table2_rid,data So table1.table2_rid references table2.RID and this is expressed with a foreign key. In both the RID field is the prima...

What's the difference between the two DDLs in MySQL?

create table categories(a integer unsigned NOT NULL,b integer unsigned NOT NULL,primary key(a,b)); And create table categories(a integer unsigned NOT NULL,b integer unsigned NOT NULL,unique (a,b)); Are there any functional difference? ...

Change Primary Key Oracle

I have a table in Oracle which has following Schema City_ID Name State Country BuildTime Time When i declared the table my primary key was both City_ID and the BuildTime but now i want to change the primary key to three columns: City_ID BuildTime and Time Can you guide me as to how to change the primary Key ...

Can a Compound key be set as a primary key to another table?

Can a compound key be set as a primary key to another table? For instance i have the tables: Books -with Primary Key:Product_ID Client -with Primary key: Client_ID Clients_Books -with Compound Primary Key:Product_Id and Client_ID I want to set this compound Primary key from Clients_Books as a Primary Key to another table named: O...

SQL Server 2008 Full text search on a table with a composite primary key

Hi everyone! I am trying to put full text search working on SQL Server 2008, however the table i am trying to index is a table with a composite primary key, something like this: EXEC sp_fulltext_catalog 'My_Catalog', 'create' EXEC sp_fulltext_table 'Message', 'create', 'My_Catalog', 'PK__MESSAGES__C87C0C9C0EC32C7A' // PK__MESSAGES__C87...

PostgreSQL bytea Primary Key

I have a table in my database which stores logs. The log files are timestamped with second accuracy and store the values of various sensors and their source: log_id, log_date, primary_system_source, sub_system_source, values Where log_id, primary_source and sub_source are integers and values is a variable length byte array (datatype: ...

Several similar DDL with different result in foreign key

This is a further discussion on this question: http://stackoverflow.com/questions/2321270/why-is-it-still-possible-to-insert-a-foreign-key-that-doesnt-exist This works: CREATE TABLE products ( id integer unsigned auto_increment primary key ) ENGINE=INNODB; CREATE TABLE orders ( id integer PRIMARY KEY auto_increment, pr...

PHP: Get primary key of table?

Hello! Is there a way to get the name of primary key field from mysql-database? For example: I have a table like this: +----+------+ | id | name | +----+------+ | 1 | Foo1 | | 2 | Foo2 | | 3 | Foo3 | +----+------+ Where the field id is primary key (it has auto increment but I can't use that). How can I retrieve fields name "id" i...

Updating MySQL primary key

I have a table user_interactions with 4 columns: user_1 user_2 type timestamp The primary key is (user_1,user_2,type) and I want to change to (user_2,user_1,type) So what I did was : drop primary key ... add primary key (user_2,user_1,type)... and voila... The problem is that database is live on a server. So befo...

Sql Server what to do to make collation key from a string value

I receive data files from a source I have no control over (the government) and in the records they have a Company Name field that I actually need to associate with existing company records in my database. I'm concerned that some of the names will vary by minor differences such as 'Company X, Inc.' vs 'Company X Inc'. So my initial thoug...

Using SELECT with a primary key in MySQL

I'm trying to speed up my SELECT queries in my web application. I have done some pretty major optimizations, like ordering the rows returned by PHP rather than MySQL itself. Now I'm just wondering, is it faster to use the SELECT statement on columns that are a primary key? Example, I have a table set up with the columns settingKey and s...

PK for web, autoincrement vs UUID style, wich is better and why?

What is the real diference between each one? I think auto inc is easy to hack vs uuid Uuid is slow than autoincrement in a query with to many records, but is there a huge difference in it? ...

Linq to SQL: How to delete using only the primary key?

How do I delete a record using Linq to SQL using only the primary key, without having to retrieve the exsting record from the database? ...

MySQL: Changing order of auto-incremented primary keys?

Hi, I have a table with a auto-incremented primary key: user_id. For a currently theoretical reason, I might need to change a user_id to be something else than it was when originally created through auto-incrementation. This means there's a possibility that the keys will not be in incremental order anymore: PK: 1 2 3 952 // changed k...