By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,482 Members | 2,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,482 IT Pros & Developers. It's quick & easy.

drop index question

P: n/a
Hi all.
I have a table that i create in MsAccess, using ado connection as follows:

create table PAYITEM (
PAYITEM_ID COUNTER PRIMARY KEY,
PAYITEM_NAME CHAR(255) UNIQUE,
PAYITEM_DESCRIPTION CHAR(255)
);
First question:
I need to drop the index on PAYITEM_NAME so that it is not unique anymore.
how would i do that in SQL? i beleive i need to know the index name, but i
don't have it. any ideas?

Second question:
After deleting the index, i want to add a new index that makes the table
unique by the combination of PAYITEM_NAME and PAYITEM_DESCRIPTION. how can i
do that (using an SQL command)

thank you for any help.
hilz


Nov 13 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a

"hilz" <no**@y.com> wrote in message
news:xO********************@comcast.com...
Hi all.
I have a table that i create in MsAccess, using ado connection as follows:

create table PAYITEM (
PAYITEM_ID COUNTER PRIMARY KEY,
PAYITEM_NAME CHAR(255) UNIQUE,
PAYITEM_DESCRIPTION CHAR(255)
);
First question:
I need to drop the index on PAYITEM_NAME so that it is not unique anymore.
how would i do that in SQL? i beleive i need to know the index name, but i
don't have it. any ideas?

Second question:
After deleting the index, i want to add a new index that makes the table
unique by the combination of PAYITEM_NAME and PAYITEM_DESCRIPTION. how can i do that (using an SQL command)

thank you for any help.
hilz

Ok, i got the Second question figured out:
create unique index INDEX_NAME on PAYITEM (PAYITEM_NAME,
PAYITEM_DESCRIPTION)

now all what remains is the first question. how do i delete the index
created by the keyword UNIQUE in a "create table" statement. i do not have
the name of that index.
the statement should be something like this i guess:
drop index INDEX_NAME on PAYITEM.

how do i get the "INDEX_NAME"?

please help.

thanks
hilz
Nov 13 '05 #2

P: n/a

"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:qm********************************@4ax.com...
On Mon, 13 Dec 2004 13:31:57 -0500, "hilz" <no**@y.com> wrote:
I have a table that i create in MsAccess, using ado connection as follows:create table PAYITEM (
PAYITEM_ID COUNTER PRIMARY KEY,
PAYITEM_NAME CHAR(255) UNIQUE,
PAYITEM_DESCRIPTION CHAR(255)
);
First question:
I need to drop the index on PAYITEM_NAME so that it is not unique anymore.how would i do that in SQL? i beleive i need to know the index name, but idon't have it. any ideas?
Second question:
After deleting the index, i want to add a new index that makes the table
unique by the combination of PAYITEM_NAME and PAYITEM_DESCRIPTION. how can ido that (using an SQL command)


Rather then doing all that, why not just make the table with the
Primary Key on the PAYITEM_NAME and PAYITEM_DESCRIPTION fields in the
first place?

CREATE TABLE PAYITEM (
PAYITEM_ID COUNTER,
PAYITEM_NAME VarChar (255),
PAYITEM_DESCRIPTION VarChar(255)
);

ALTER TABLE PAYITEM
ADD CONSTRAINT PrimaryKeyName PRIMARY KEY
(PAYITEM_NAME, PAYITEM_DESCRIPTION);
Please note that I changed the Item and Description fields to VarChar.
Access really doesn't support Char fields, so it's fairly useless to
declare them that way. And do they *really* have to be 255? That's a
fairly big waste of space if it's never used!

--
Help! I've Fallen And I Can't Reach My Beer!


Our users have mdb files that contain tables that were created using the
script i have shown (create table....)
I need to upgrade the database to make the unique index on both payitem name
and description.
so i don't have a choice to create it the way you specified, because it
already exists.

as for the varchar, i did not know that varchar existed in Access. how long
has access supported that?
i remember trying varchar before and it did not work.
thanks
hilz
Nov 13 '05 #3

P: n/a
It might depend on the context where you tried this. ADOX has constants for
acVarWChar etc.

For details on how to cross-reference DDL, DAO, ADOX, and the names in the
JET interface, see:
http://members.iinet.net.au/~allenbrowne/ser-49.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hilz" <no**@y.com> wrote in message
news:7b********************@comcast.com...

as for the varchar, i did not know that varchar existed in Access. how
long
has access supported that?
i remember trying varchar before and it did not work.
thanks

Nov 13 '05 #4

P: n/a
On Tue, 14 Dec 2004 01:00:13 -0500, "hilz" <no**@y.com> wrote:

"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:qm********************************@4ax.com.. .
On Mon, 13 Dec 2004 13:31:57 -0500, "hilz" <no**@y.com> wrote:
>I have a table that i create in MsAccess, using ado connection asfollows: >create table PAYITEM (
>PAYITEM_ID COUNTER PRIMARY KEY,
>PAYITEM_NAME CHAR(255) UNIQUE,
>PAYITEM_DESCRIPTION CHAR(255)
>);
>First question:
>I need to drop the index on PAYITEM_NAME so that it is not uniqueanymore. >how would i do that in SQL? i beleive i need to know the index name, buti >don't have it. any ideas?
>Second question:
>After deleting the index, i want to add a new index that makes the table
>unique by the combination of PAYITEM_NAME and PAYITEM_DESCRIPTION. howcan i >do that (using an SQL command)


Rather then doing all that, why not just make the table with the
Primary Key on the PAYITEM_NAME and PAYITEM_DESCRIPTION fields in the
first place?

CREATE TABLE PAYITEM (
PAYITEM_ID COUNTER,
PAYITEM_NAME VarChar (255),
PAYITEM_DESCRIPTION VarChar(255)
);

ALTER TABLE PAYITEM
ADD CONSTRAINT PrimaryKeyName PRIMARY KEY
(PAYITEM_NAME, PAYITEM_DESCRIPTION);
Please note that I changed the Item and Description fields to VarChar.
Access really doesn't support Char fields, so it's fairly useless to
declare them that way. And do they *really* have to be 255? That's a
fairly big waste of space if it's never used!

--
Help! I've Fallen And I Can't Reach My Beer!


Our users have mdb files that contain tables that were created using the
script i have shown (create table....)
I need to upgrade the database to make the unique index on both payitem name
and description.
so i don't have a choice to create it the way you specified, because it
already exists.

as for the varchar, i did not know that varchar existed in Access. how long
has access supported that?
i remember trying varchar before and it did not work.
thanks
hilz

Hi
I think you will find that the default name for the primary key index
is PRIMARYKEY but you can set the names of constraints yourself, eg

create table PAYITEM (PAYITEM_ID COUNTER CONSTRAINT keyname PRIMARY
KEY, PAYITEM_NAME CHAR(255) CONSTRAINT uniquename UNIQUE,
PAYITEM_DESCRIPTION CHAR(255));

To drop the primary key
DROP INDEX keyname ON PAYITEM

To add the new index
ALTER TABLE PAYITEM ADD
CONSTRAINT multifieldindex UNIQUE (PAYITEM_NAME, PAYITEM_DESCRIPTION)

David

Nov 13 '05 #5

P: n/a
Hi
I think you will find that the default name for the primary key index
is PRIMARYKEY but you can set the names of constraints yourself, eg

create table PAYITEM (PAYITEM_ID COUNTER CONSTRAINT keyname PRIMARY
KEY, PAYITEM_NAME CHAR(255) CONSTRAINT uniquename UNIQUE,
PAYITEM_DESCRIPTION CHAR(255));

To drop the primary key
DROP INDEX keyname ON PAYITEM

To add the new index
ALTER TABLE PAYITEM ADD
CONSTRAINT multifieldindex UNIQUE (PAYITEM_NAME, PAYITEM_DESCRIPTION)

David


The problem is that the database already exists, and the unique index on the
payitem_name has no name.
so i need to upgrade my database my removing that index and adding a new
composite one.
i figured out the part on how to add the new composite index.
but i still do not know how to delete the old one since it does not have a
name that i know.
is there any way of getting that name? or any other way of doing that?

thanks
hilz
Nov 13 '05 #6

P: n/a
This illustrates how to get information on the indexes of a table using DAO:

Function ShowIndexes(strTable As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim ind As DAO.Index
Dim fld As DAO.Field

Set db = DBEngine(0)(0)
Set tdf = db.TableDefs(strTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary, "Primary", ""), _
IIf(ind.Foreign, "Foreign", ""), ind.Fields.Count
Debug.Print " Field(s): ";
For Each fld In ind.Fields
Debug.Print fld.Name;
Next
Debug.Print
Next

Set ind = Nothing
Set tdf = Nothing
Set db = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hilz" <no**@y.com> wrote in message
news:zI********************@comcast.com...
Hi
I think you will find that the default name for the primary key index
is PRIMARYKEY but you can set the names of constraints yourself, eg

create table PAYITEM (PAYITEM_ID COUNTER CONSTRAINT keyname PRIMARY
KEY, PAYITEM_NAME CHAR(255) CONSTRAINT uniquename UNIQUE,
PAYITEM_DESCRIPTION CHAR(255));

To drop the primary key
DROP INDEX keyname ON PAYITEM

To add the new index
ALTER TABLE PAYITEM ADD
CONSTRAINT multifieldindex UNIQUE (PAYITEM_NAME, PAYITEM_DESCRIPTION)

David


The problem is that the database already exists, and the unique index on
the
payitem_name has no name.
so i need to upgrade my database my removing that index and adding a new
composite one.
i figured out the part on how to add the new composite index.
but i still do not know how to delete the old one since it does not have a
name that i know.
is there any way of getting that name? or any other way of doing that?

thanks
hilz

Nov 13 '05 #7

P: n/a

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
This illustrates how to get information on the indexes of a table using DAO:
Function ShowIndexes(strTable As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim ind As DAO.Index
Dim fld As DAO.Field

Set db = DBEngine(0)(0)
Set tdf = db.TableDefs(strTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary, "Primary", ""), _
IIf(ind.Foreign, "Foreign", ""), ind.Fields.Count
Debug.Print " Field(s): ";
For Each fld In ind.Fields
Debug.Print fld.Name;
Next
Debug.Print
Next

Set ind = Nothing
Set tdf = Nothing
Set db = Nothing
End Function

The funny thing is that my program is in Java and i use a JDBC-ADO bridge!
:)
so this code is like chinese to me!
The only thing i can do is call the jdbc api or send SQL statements.
any other toughts?

Nov 13 '05 #8

P: n/a

"hilz" <no**@y.com> wrote in message
news:L6********************@comcast.com...

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
This illustrates how to get information on the indexes of a table using

DAO:

Function ShowIndexes(strTable As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim ind As DAO.Index
Dim fld As DAO.Field

Set db = DBEngine(0)(0)
Set tdf = db.TableDefs(strTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary, "Primary", ""), _
IIf(ind.Foreign, "Foreign", ""), ind.Fields.Count
Debug.Print " Field(s): ";
For Each fld In ind.Fields
Debug.Print fld.Name;
Next
Debug.Print
Next

Set ind = Nothing
Set tdf = Nothing
Set db = Nothing
End Function

The funny thing is that my program is in Java and i use a JDBC-ADO bridge!
:)
so this code is like chinese to me!
The only thing i can do is call the jdbc api or send SQL statements.
any other toughts?

Oh, just to add to the complixity, the conversion must be done using an SQL
script that is read from a text file, so it has to be done using SQL!
Nov 13 '05 #9

P: n/a
On Tue, 14 Dec 2004 02:46:05 -0500, "hilz" <no**@y.com> wrote:

Oh, just to add to the complixity, the conversion must be done using an SQL
script that is read from a text file, so it has to be done using SQL!

Hi
Create a new table "FRED" with the fields and indexes you require and
copy the data from PAYITEM into it.
Drop the original table and re-name FRED.

Actually I'm not sure how to rename a table in SQL so maybe you will
need to recreate PAYITEM and do a further copy of the data.

David
Nov 13 '05 #10

P: n/a

"David Schofield" <d.***************@blueyonder.co.uk> wrote in message
news:41beaef2.403382643@localhost...
On Tue, 14 Dec 2004 02:46:05 -0500, "hilz" <no**@y.com> wrote:

Oh, just to add to the complixity, the conversion must be done using an SQLscript that is read from a text file, so it has to be done using SQL!

Hi
Create a new table "FRED" with the fields and indexes you require and
copy the data from PAYITEM into it.
Drop the original table and re-name FRED.

Actually I'm not sure how to rename a table in SQL so maybe you will
need to recreate PAYITEM and do a further copy of the data.

David


Not a bad idea!
I'll try doing that.

thanks.
hilz
Nov 13 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.