473,739 Members | 4,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cant figure out some mysql commands

hi,
i'm new to sql
i'd appretiate if someone would helpme out with this doudt i have

CODE:
CREATE TABLE entry (
uno int(6) NOT NULL auto_increment,
fname varchar(30) NOT NULL,
sname varchar(30) NOT NULL,
email varchar(30) NOT NULL ,
college varchar(30) NOT NULL,
dob varchar(9) NOT NULL,
id varchar(10) NOT NULL,
mobile varchar(20) NOT NULL,
dom varchar(30) NOT NULL,
sex varchar(30) NOT NULL,
verified varchar(3) NOT NULL,
PRIMARY KEY (uno),
UNIQUE uno (uno),
KEY uno_2 (uno)
)
i totally cant understand the last two lines of code in this create
statement :
UNIQUE uno (uno),
KEY uno_2 (uno)
.... got it from an undocumented project i am working on
i need help immediately please help

Aug 3 '06 #1
6 3136
an******@gmail. com wrote:
i totally cant understand the last two lines of code in this create
statement :
UNIQUE uno (uno),
KEY uno_2 (uno)
"KEY" is a synonym for "INDEX". It just means that the column `uno` is
indexed.

"UNIQUE" is a unique constraint; all values in the column must be
distinct. This also implies the creation of an index on the `uno` column.

It appears in this case that both of these are redundant and
unnecessary, since you already have the `uno` column declared as a
PRIMARY KEY, which implies both an index and a unique constraint.

But in some older versions of MySQL, you had to explicitly create an
index on a column before declaring a foreign key constraint on that
column. In more recent versions, declaring a FOREIGN KEY does it for you.

I don't think it was ever necessary to create an index for a PRIMARY
KEY, the declaration of that constraint automatically creates a unique
index. But the designer of the database may not have known this.

I don't think it hurts anything to have these redundant indexes, but it
uses space that you don't need to use, and may have effects on the query
optimizer. You should be able to drop the redundant indexes safely:

ALTER TABLE DROP INDEX uno, DROP INDEX uno_2;

Regards,
Bill K.
Aug 3 '06 #2
hi
thanks so much for that man
i new that code was fishy
Bill Karwin wrote:
an******@gmail. com wrote:
i totally cant understand the last two lines of code in this create
statement :
UNIQUE uno (uno),
KEY uno_2 (uno)

"KEY" is a synonym for "INDEX". It just means that the column `uno` is
indexed.

"UNIQUE" is a unique constraint; all values in the column must be
distinct. This also implies the creation of an index on the `uno` column.

It appears in this case that both of these are redundant and
unnecessary, since you already have the `uno` column declared as a
PRIMARY KEY, which implies both an index and a unique constraint.

But in some older versions of MySQL, you had to explicitly create an
index on a column before declaring a foreign key constraint on that
column. In more recent versions, declaring a FOREIGN KEY does it for you.

I don't think it was ever necessary to create an index for a PRIMARY
KEY, the declaration of that constraint automatically creates a unique
index. But the designer of the database may not have known this.

I don't think it hurts anything to have these redundant indexes, but it
uses space that you don't need to use, and may have effects on the query
optimizer. You should be able to drop the redundant indexes safely:

ALTER TABLE DROP INDEX uno, DROP INDEX uno_2;

Regards,
Bill K.
Aug 4 '06 #3

an******@gmail. com wrote:
hi
thanks so much for that man
i new that code was fishy
Bill Karwin wrote:
an******@gmail. com wrote:
i totally cant understand the last two lines of code in this create
statement :
UNIQUE uno (uno),
KEY uno_2 (uno)
"KEY" is a synonym for "INDEX". It just means that the column `uno` is
indexed.

"UNIQUE" is a unique constraint; all values in the column must be
distinct. This also implies the creation of an index on the `uno` column.

It appears in this case that both of these are redundant and
unnecessary, since you already have the `uno` column declared as a
PRIMARY KEY, which implies both an index and a unique constraint.

But in some older versions of MySQL, you had to explicitly create an
index on a column before declaring a foreign key constraint on that
column. In more recent versions, declaring a FOREIGN KEY does it for you.

I don't think it was ever necessary to create an index for a PRIMARY
KEY, the declaration of that constraint automatically creates a unique
index. But the designer of the database may not have known this.

I don't think it hurts anything to have these redundant indexes, but it
uses space that you don't need to use, and may have effects on the query
optimizer. You should be able to drop the redundant indexes safely:

ALTER TABLE DROP INDEX uno, DROP INDEX uno_2;

Regards,
Bill K.
hi
i still dont get what the uno_2 is
is it the name for the index variable as different from the variable or
is it some sql convention

Aug 5 '06 #4
an******@gmail. com wrote:
i still dont get what the uno_2 is
is it the name for the index variable as different from the variable or
is it some sql convention
Indexes have names, so you can specify the index when you want to drop it.

Sometimes indexes are automatically assigned a name. For instance, in
MySQL the index for a primary key is always named simply "PRIMARY".

Regards,
Bill K.
Aug 5 '06 #5
so that means i can index two columns with the same name
like
*
KEY id_2(id),
KEY id_2(email)
*?????????????? ??????
Bill Karwin wrote:
an******@gmail. com wrote:
i still dont get what the uno_2 is
is it the name for the index variable as different from the variable or
is it some sql convention

Indexes have names, so you can specify the index when you want to drop it.

Sometimes indexes are automatically assigned a name. For instance, in
MySQL the index for a primary key is always named simply "PRIMARY".

Regards,
Bill K.
Aug 6 '06 #6
an******@gmail. com wrote:
so that means i can index two columns with the same name
like
*
KEY id_2(id),
KEY id_2(email)
*?????????????? ??????
If you want a compound index comprised of two columns, the way to
declare it is:

KEY id_2 (id, email)

Note that the order of the columns in a compound key is significant. If
you were to search this table based solely on email, it would not be
able to use the index. If you search based on id, or an expression
including both id and email, it can use the index.

Regards,
Bill K.
Aug 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6488
by: Eric W. Holzapfel | last post by:
Hello PHP group, I have mysql running on a linux box. I have apache (2.0.4) running on a diff linux box. I have php 4.X. I can connect to the mysql db using odbc from a windows box, but cannot connect to the remote db from web server box (linux) to mysql database (another linux box). Apache is on RH Enterprise 3.0, mysql is on slacware (2.4.22 kernel). I am using php, require_once('DB.php'), and the dsn style connect string:...
4
9340
by: Mark Wilson CPU | last post by:
A colleague has written a prototype program in PHP, using a MySQL database. It's a relatively simple app, with a restricted set of mysql commands used (see below). The MySQL DB is being replaced with an Oracle DB (same schema). My plan 1) globally replace the few mysql commands with intermediate equivalents (such as myDB_connect for mysql_connect) 2) those central functions would then (for now) call the original mysql function to prove...
0
2288
by: Duane Winner | last post by:
Hello all - I'm having a small problem with the mysql startup script that ships with MySQL-3.23.56-1. I'm running on RedHat Linux. It works fine, but I have a backup server that runs a script that passes these commands remotely through ssh: (1) ssh dbsys-dc "sudo /etc/init.d/mysql stop" (2) ssh dbsys-dc "sudo tar
1
1752
by: TheKeith | last post by:
I'm just learning mysql--having no db experience. I'm wondering if my-sql-specific commands overlap with sql standard commands. I noticed when reading the mysql manual, that one of the user comments on the bottom of the page says that the "describe table" and "show tables" are mysql-specific. I also noticed that they use the non-standard "load data" command, where "insert" is the standard. I was under the impression that mysql-specific...
3
10311
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the following: runs several queries against different tables in a database; returns several lists of pictures being used in the database; removes any obsolete images from specific directories. The script is bash shell script. The problem is that...
1
2076
by: Karuna | last post by:
Hi, I am new to MySQL. I want to create a script file which will include a number of commands and execute it, just like we do in Oracle. Can any one tell me how to do it? Suppose I want to create a script called "temp" that will contain say 4 create statement. I want someone to show me how to create that file and execute it. And how to capture the output in a separate file like we do in Oracle. And what should be the extension of the...
3
1809
by: Kentor | last post by:
hello, im trying to make a little loop, but i cant figure it out... i have a string with a bunch of 1s and 0s in it: 110101010101111010101 .... i need to count the number of 1s divide it by 2 and make a table with 2 columns and then for every one, depending on its position in the string i need to output a word and then go to the next 1 and output a dif word.... its amenities, winter activities and summer activities for cottages that i...
2
7377
by: g35rider | last post by:
Hi, I have the following code that is giving this error, I cant simplify the code, I was just testing some theory for something we are doing and was getting an issue here. Please someone point out whats wrong with my code. class MsgData { char* data;
17
2032
by: so many sites so little time | last post by:
all right so the script is pretty simple it goes it retrives what the id of the post is and it lets you edit it well no it doesnt. now if you go to www.kirewire.com/pp2/index/php you will see a number 1 that is the value of collumn home_id which is set to auto increment ect ect but this script which gets the id of home_id of a row and lets you edit it does not work for somereason...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.