472,374 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

drop index question

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
10 8157

"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

"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
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
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
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
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

"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

"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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: C White | last post by:
I've got another drop list problem I am using the following code where users select a name, but it should pass a name and email into the table <select name="user"> <option value="<%...
10
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
3
by: db2admin | last post by:
Hello, I always assumed that dropping table will drop everything associated with it like indexes, references etc. I just noticed that after dropping table A and recreating it and then creating...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
5
by: Romulo NF | last post by:
Greetings, Im back here to show the new version of the drag & drop table columns (original script ). Ive found some issues with the old script, specially when trying to use 2 tables with...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.