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 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
"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
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
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 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
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
"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?
"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!
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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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="<%...
|
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...
|
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);...
|
by: VB Programmer |
last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!
|
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...
|
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...
|
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...
|
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 &...
|
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 &...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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++...
|
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...
|
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...
|
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.
| |