![]() |
Best way to set up this Mysql? (primary key?)
Me and a friend are technicians and I'm wanting to set up a database that contains info on the items we work on.
Products that are the exact same (model number, type) are grouped by "Item Number" which we have created over time. The database would include spaces for the item number, model number, etc. We work with several different objects though and there are thousands of differen t products so many many item numbers. I have been reading a little about how a "primary key" in mysql is like something unique.. like a way of tracking, I guess? would it be good for me to set up a primary key as our item number? |
If that number is *always* unique and there wont be any repetitions of it in the table, then yes. Tracking would be a pretty good way to look at it.
Its been a while since Ive done any DB work, Ill let others elaborate. |
I'm not real clear from what you've said whether it'll be helpful or not, but you can set up INT()-typed primary key fields to be auto-incrmenting. You can leave the field out of your INSERT statement, or insert NULL into the field, and the database will automatically give you the next number in that field.
Code:
CREATE TABLE Demonstration ( |
thanks
|
Quote:
|
As far as a primary key, it really just depends on your database structure. If you make your databases in a NORMALIZED fashion, then autonumbers have their place, however, I cannot proscribe a suggestion on your primary key w/o knowing your whole structure.
However, if you are asking "what is a primary key", then that's easy. A primary key (1 or more columns) is a value that the database will enforce uniqueness. The RDBMS will not permit you to put duplicate values in the specified column(s). Should you use Primary keys? Yes. Should you use indexs? Yes. My suggestion would be to find some SQL tutorials and read up on the finer points of the language before constructing your database and application. If you save you a lot of time in rebuilding later. As far as the capitalization in SQL, I am as lax as can be, other languages are strict and I don't have a problem conforming, however, I've never found a reason (readability, functionality, ect) to even try to change my mind. Whatever the fingers hit is what my command looks like... |
I'm going to set the primary key but I can't figure out how to alter my column to make it a primary key.
Right now it is just set as text.. what's the command to make that column primary key? ALTER TABLE mytable ALTER COLUMN column ........ ? |
Here is the MySQL guide for it
http://www.mysql.com/doc/en/ALTER_TABLE.html
Speficily(sp): To add an index on column d, and make column a the primary key: mysql> ALTER TABLE t2 ADD INDEX (d), ADD PRIMARY KEY (a); |
All times are GMT -8. The time now is 03:29 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project