473,915 Members | 4,411 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 8331

"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
2167
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
26162
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
4236
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
10608
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
3
20320
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
9305
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
13838
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
1341
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
1462
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
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9881
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
10923
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
11066
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,...
1
8100
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
7256
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();...
1
4778
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
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3368
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.