primary-key

Relational Database Design - double primary key in one table ?

I have a table that keeps the user ratings for items. I want to allow each user to rate an item only once, is there any way to force the database not to allow duplicate for itemId and userId? I don't want each individual field to be a primary key. I want the primary key to be based on both of them at the same time. for example there i...

Generating a non-sequential ID/PK for a Django Model

I'm on the cusp of starting work on a new webapp. Part of this will give users pages that they can customise in a one to many relationship. These pages naturally need to have unique URLs. Left to its own devices, Django would normally assign a standard AUTOINCREMENT ID to a model. While this works fantastically, it doesn't look great an...

How to pull out the name of the primary key column(s) of a MS SQL Server table?

I have a MS SQL Server Database with about 75 tables on it, and I am trying to insert records into tables if a record with the same primary key doesn't exist, or update if they do. I could hard code the primary keys for every table into my vb.net code, but I'd rather not as more tables are to be added at a later date and my code needs to...

varchar() primary key or int primary key?

Hi Guys, I have a problem with MySql primary keys, it's for my project i'm working on now! i have to have a unit name(not a number)as a key in my database, it is a combination of letters and numbers, i can't use any primary key in INT type, where it increments as usual! what is better? should i stick to old INT, auto increment way? ...

reset postgresql primary key to 1

is there a way to reset the primary key of a postgres table to start at 1 again on a populated table? right now its generating numbers from 1000000 and up. I want it all to reset and start to 1, keeping all my existing data intact. Thanks. ...

What is the difference between Primary Key and unique key constraint?

What is the difference between Primary key And unique Key constraint? What's the use of it?? ...

Does MySQL handle a single utf-8 character key as well as an integer?

I' working on a Chinese/Japanese learning web app where many tables are indexed by the characters (the "glyphs") of those languages. I'm wondering if the integer codepoint value of the glyph would be better for performance than using a single utf8 character (for primary key and indexes)? Using a single utf8 character would be very usef...

Sql Server Indexes Include Primary Key?

One of my co workers is under the impression that when adding an index to a table in SQL Server 2008 that the PK's index is added to that index as well. Therefore if you are using a wider primary key then that key will also be included in the new index vastly increasing the disk space used above and beyond the penalty already paid for th...

What's the difference between Primary Key, Unique Key and Index in MySQL?

When should I use KEY, PRIMARY KEY, UNIQUE KEY and INDEX? ...

H2 database: Information about primary key in INFORMATION_SCHEMA

I create the following table in H2: CREATE TABLE TEST (ID BIGINT NOT NULL PRIMARY KEY) Then I look into INFORMATION_SCHEMA.TABLES table: SELECT SQL FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'TEST' Result: CREATE CACHED TABLE TEST( ID BIGINT NOT NULL ) Then I look into INFORMATION_SCHEMA.CONSTRAINTS table: SELECT SQ...

Creating index/pk in a huge table is taking too long. I am using Oracle. How do I know if it is going well?

Hi, I have a really huge table, with ~200 million rows. It had no index/pk at all. Selects in this table were (obviously) running slow. I decided to create a PK using 3 columns. I did it in a test environment that has a smaller version of this table and it worked like a charm. So, before going home i did a ALTER TABLE HUGETABLE ADD CO...

iPhone - Core Data Questions ???

Above is my data model diagram. Everytime i create a Car whcih contains a model and make, it adds a car object to core data. The problem is that it also adds 1 make and 1 model to the core data, so i get duplicates. for example, in the following code, it saves 1 car object 2 models, and 2 makes, so I get a duplicate Make in my table (...

Manual inserts on a postgres table with a primary key sequence

Hi guys! I'm converting a MySQL table to PostgreSQL for the first time in my life and running into the traditional newbie problem of having no auto_increment. Now I've found out that the postgres solution is to use a sequence and then request the nextval() of this sequence as the default value every time you insert. I've also read that...

Why to use "not null primary key" in TSQL?

I am seeing too frequently "not null primary key" in scripts creating tables in TSQL in blogs, articles, books, forums, here in SO, etc. For example, BING gives 630,000 results ((just in English) if to search against "not null" NEAR "primary key" "sql server": http://www.bing.com/search?q=%22not+null%22+NEAR+%22primary+key%22+%22sql+s...

How to drop a primary key? I get incorrect table definition.

I am trying to run this query: ALTER TABLE table DROP PRIMARY KEY, ADD PRIMARY KEY( `CUSTNO` , `DEPTNO` , `PRODNO` , `DT` ); I get Incorrect table definition; there can be only one auto column and it must be defined as a key ...

SQL Server keys and foreign keys

If I have a primary key in table A and in table B of the same database (table B has its own primary key) I create a relationship with the primary key in table A so that a column in table B is the foreign key, does it mean that the primary key data created in the primary key column of table A will also be added to table B by virtue of it ...

primary key in linked csv using schema.ini somehow?

For a number of reasons I have to use a linked csv file in a sqlexpress database. Col1 is always unique, although the data changes periodically, based on current logins. Is there a way to set as a primary key in some manner using the schema.ini or some other way? ...

Using a UUID as a primary key in Django models (generic relations impact)

For a number of reasons^, I'd like to use a UUID as a primary key in some of my Django models. If I do so, will I still be able to use outside apps like "contrib.comments", "django-voting" or "django-tagging" which use generic relations via ContentType? Using "django-voting" as an example, the Vote model looks like this: class Vote(mod...

Is there a reason for a Primary Key column that would never be used?

I have a routine that will be creating individual tables (Sql Server 2008) to store the results of reports generated by my application (Asp.net 3.5). Each report will need its own table, as the columns for the table would vary based on the report settings. A table will contain somewhere between 10-5,000 rows, rarely more than 10,000. Th...

Performance: UUID vs auto-increment in cakephp-mysql

I was searching if UUID generated by cakePHP (32 char long) is faster in performance compared to auto-increment. Comparison in both inserts and Select operation. Which one should I use UUID generated by cakePHP or by using simple auto-increment of MySQL Here's is a case-study I found but its not specific to cakePHP http://krow.livejour...