473,685 Members | 3,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_DESCRIP TION 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_DESCRIP TION. how can i
do that (using an SQL command)

thank you for any help.
hilz


Nov 13 '05 #1
10 8310

"hilz" <no**@y.com> wrote in message
news:xO******** ************@co mcast.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_DESCRIP TION 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_DESCRIP TION. 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_DESCRIP TION)

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.*******@worl dnet.att.net.in valid> wrote in message
news:qm******** *************** *********@4ax.c om...
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_DESCRI PTION 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_DESCRIP TION. 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_DESCRIP TION fields in the
first place?

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

ALTER TABLE PAYITEM
ADD CONSTRAINT PrimaryKeyName PRIMARY KEY
(PAYITEM_NAME, PAYITEM_DESCRIP TION);
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******** ************@co mcast.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.*******@worl dnet.att.net.in valid> 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_DESCRI PTION 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_DESCRIP TION. 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_DESCRIP TION fields in the
first place?

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

ALTER TABLE PAYITEM
ADD CONSTRAINT PrimaryKeyName PRIMARY KEY
(PAYITEM_NAME, PAYITEM_DESCRIP TION);
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_DESCRIP TION 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_DESCRIP TION)

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_DESCRIP TION 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_DESCRIP TION)

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(str Table 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(st rTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary , "Primary", ""), _
IIf(ind.Foreign , "Foreign", ""), ind.Fields.Coun t
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******** ************@co mcast.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_DESCRIP TION 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_DESCRIP TION)

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*********@Se eSig.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(str Table 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(st rTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary , "Primary", ""), _
IIf(ind.Foreign , "Foreign", ""), ind.Fields.Coun t
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******** ************@co mcast.com...

"Allen Browne" <Al*********@Se eSig.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(str Table 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(st rTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary , "Primary", ""), _
IIf(ind.Foreign , "Foreign", ""), ind.Fields.Coun t
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

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

Similar topics

15
2149
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="<% Response.Write (rsUser("Name")) %>"> <% Response.Write (rsUser("Name")) %> <input type="hidden" name="Email" value="<% Response.Write (rsUser("Email")) %>">
10
26104
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 null references another, FK_LASTLYOID bigint not null references lastly, unique (FK_OTHEROID,FK_ANOTHEROID))
5
4224
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); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
3
10590
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
3
20309
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 index on it gave me error DROP TABLE tmp DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it
4
9290
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 if it works, and if it does not, tell me why it does not work. Thanks.
5
13773
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented. I´ve also commented the whole code so you guys can easier understand it engine. What exactly we need when trying to make a column drag &...
0
1335
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 & update to the database based on the hidden ID. DELETE ALL will delete everything the databse.
0
1448
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 & update to the database based on the hidden ID. DELETE ALL will delete everything the databse.
0
8773
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
7589
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
6431
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
5792
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
4302
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
4523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2938
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.