primary-key

Grails: String(username) as primary key, but save and get id string(username) with ignorecase?

I am using a string "username" as the primary-key of a table, But when saving and getting the column with the username id I want the case to be ignored so that new users can't try to impersonate another user. e.g. When registering a new user username = Daxon username = DaXoN //this should not be allowed When getting the unique user...

What is the difference between an Index and a Foreign Key?

I want to create a database with 3 tables. One for posts and one for tags and one that links posts to tags with the post_id and tag_id functioning as foreign key references. Can you explain what an Index would be in this scenario and how it differs from a Foreign Key and how that impacts my database design? ...

Is there a simple way to create a unique integer key from a two-integer composite key?

For various reasons that aren't too germane to the question, I've got a table with a composite key made out of two integers and I want to create a single unique key out of those two numbers. My initial thought was to just concatenate them, but I ran into a problem quickly when I realized that a composite key of (51,1) would result in the...

Generate unique key in Java to be used as primary key in Oracle tables.

I am trying to get a string of length 15 to be used as primary key in database tables. The following code in java returns some key with length 35 UUID.randomUUID().toString() Can I change it to return a key of the length 15 ? How to ensure thread safety? Any help is greatly appreciated. ...

Is it OK not to use a Primary Key When I don't Need one

If I don't need a primary key should I not add one to the database? ...

Necessity of foreign key in this case(innoDB/mysql)

Hi, i recently migrated my whole DB from myisam to innodb. I am fairly new to all this so i have a question regarding the use of the foreign key. Lets say i have two tables: users, messages. users id (pr_key) name messages id (pr_key) user_id message The id fields are both auto incremented. So now in my queries i join th...

Reset primary key in mysql?

Hi all; In my table tbphotos i had 100 recordes then i deleted all,now that i want restart data entry i see that my primary key doesn't start from 1 , but it start from 101 ,is there any way? -I work in "Mysql administrator" thanks ...

What is MySQL primary (key1, key2)

I am working on existing DB and try to optimize it. I see a table without a single primary key but with two foreign keys work as a primary key. I know it will work. however, is it better to have one single primary key with two foreign keys for better performance or primary (key1, key2) will just work as good as one? For example: CREA...

C#: Update dataset without any primary key

Is it possible in C# to use an OleDbAdapter and use its Update method for a dataset when a table has no primary key and how can I do this? ...

Specify PK name during table creation

In MSSQL is there a way to specify a name for a PK constraint so that MSSQL doesn't provide a randomly generated PK name like so: PK__Addresse__3214EC074E88ABD4 The only way I can see to do it now is to first create the table and then issue an ALTER command to rename the PK. It would be easier if I could do it in one shot. ...

How reorder primary key?

Hi; I have deleted one row(row 20) in my "table category" ,please let me know that how can i reorder the catid (primary key)? at this time it is 21 after 19. Thanks ...

Is it bad to use user name as primary key in database design?

I was told by a friend: What unique key do you use? I hope you are not saving the entire user name --- this will use up too much table space! Assign an unique userID to each (unique) userNAME and save this userID (should be INTEGER UNSIGNED auto_increment or BIGINT UNSIGNED auto_increment). Don't forget to create a re...

Identity Column as Primary Key

Hi Guys, Could you please opine if having identity column as primary key is a good practise? For ORM tools, having identity column on tables helps. But there are other side effects such as accidental duplicate insertion. Thanks Nayn ...

Do link tables need a meaningless primary key field?

I am working on a couple of link tables and I got to thinking (Danger Will Robinson, Danger) what are the possible structures of a link table and what are their pro's and con's. I came up with a few possible strictures for the link table: Traditional 3 column model id - auto-numbered PRIMARY table1fk - foreign key table2fk - foreign ...

Is it a good practice to use email address as a primary key in many tables in a website system?

For example, a website like stackoverflow.com, is it a good practice to use email address to identify users in many tables? Is it bad if the primary key is very long, say varchar(50) or even varchar(100) ? ...

SQL - Table join where primary key in first table is part of key in second

Hi I am fairly new to SQL - so be gentle with me! I basically have two tables that I am trying to join where the primary key in the first table is used multiple times in the second table (and forms the primary key in the second table along with another column) It's probably best if I provide an example: Table 1 : TravelRecords Travel...

SQL - Find missing data / negative search

Hi - following on from my other post... I have a table that uses two fields to make a primary key... TravelEventID RemarkNo Keyword Text 0001 1 TVL LOWCOST BOOKING 0001 2 TVL CREDIT CARD USED 0001 3 PSG COST CENTRE REQUIRED 00...

How do I rename primary key values in Oracle?

Our application uses an Oracle 10g database where several primary keys are exposed to the end user. Productcodes and such. Unfortunately it's to late to do anything with this, as there are tons of reports and custom scripts out there that we do not have control over. We can't redefine the primary keys or mess up the database structure. ...

How to create Composite Key and how to refer it in other table as a foreign key

I have a table following table create table tblcountry ( unqid uniqueidentifier name varchar(100) isremoved bit ) I want to create primary key on basis of unqid + isremoved and in which isremoved must be true i have got another table: create table tblstate ( unqid uniqueidentifier, name varchar(100) f_tblcountry uniquei...

How bad is it to simulate IDENTITY/AUTOINCREMENT columns using triggers in Oracle?

I maintain an application that was originally written to be SQL Server-specific (using IDENTITY fields). Thus, we've had to define a lot of triggers to auto increment tables' primary keys. I'm told that this is considered to be a hacky workaround in the Oracle world, but that was told to me in a "friend of a friend" kind of way. How b...