141k views
4 votes
Which of the following illustrates the author's preferred style of defining a primary key?

a) CREATE TABLE CUSTOMER (
CustomerID Integer Primary Key
LastName Char(35) Not Null
FirstName Char(25) Null):
b) CREATE TABLE CUSTOMER (
CustomerID Integer Not Null
LastName Char(35) Not Null
FirstName Char(25) Null
CONSTRAINT CustomerPK PRIMARY KEY (CustomerID);
c) CREATE TABLE CUSTOMER (
CustomerID Integer Not Null
LastName Char(35) Not Null
FirstName Char(25) Null):
ALTER TABLE CUSTOMER
ADD CONSTRAINT CustomerPK PRIMARY KEY (CustomerID);
d) either b or c
e) The author does not state a preference for how to define a primary key.

User Haleonj
by
8.2k points

1 Answer

0 votes

Final Answer:

The author's preferred style of defining a primary key is option b, where the PRIMARY KEY constraint is explicitly stated within the CREATE TABLE statement using the CONSTRAINT keyword. This approach aligns with best practices for clarity in database design. So, the correct option is b).

Step-by-step explanation:

The correct option is b). The author's preference for defining a primary key is evident in option b, where the CREATE TABLE statement includes the explicit declaration of the PRIMARY KEY constraint using the CONSTRAINT keyword. This approach enhances the clarity of the database schema definition by clearly associating the primary key with the corresponding table and fields.

The use of the CONSTRAINT keyword within the CREATE TABLE statement follows a straightforward and organized structure, contributing to better readability and understanding of the database design.

Additionally, this method allows for a more immediate recognition of the primary key, streamlining the communication of the table's key attributes. Overall, option b aligns with established best practices for maintaining a clean and comprehensible database structure.

User Cazzer
by
7.7k points