-
Creating Primary Keys using SQL
I would like to use SQL to create a table that contains two fields that would be used as the primary key (not allowing duplicates). Is this possible and if so please provide an example. Thanks
-
create table test (a number primary key)
-
Yes, this is possible. What you need to do is create a multi-field primary key - also known as a composite key. In MS Access, you would do this by highlighting the fields that you wish to make up the composite and clicking the 'primary key' icon on the toolbar.
In SQL Enterprise Manager you would do something similar.
Search out the 'composite key' help topic in both Access help and SQL Server books online for more exhaustive information.
-
I didn't realize you wanted multiple column primary key. You can run this in query windows
alter table test add constraint pk_test primary key (a,b)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|