195k views
4 votes
Write a SQL statement to create a table called students. The students table contains five fields: id, name, major, year, and gpa. You should also specify primary key of the table.

1 Answer

6 votes

Final answer:

To create a table called 'students' with fields 'id', 'name', 'major', 'year', and 'gpa', with 'id' as a primary key, use CREATE TABLE SQL statement with appropriate data types for each field.

Step-by-step explanation:

To create a table named students with the specified fields (id, name, major, year, and gpa) and to set the id field as the primary key, the following SQL statement can be used:

This SQL statement creates the table and defines the datatype for each field. The id field is designed to hold integers and is identified as the primary key to ensure each record has a unique identifier. The name and major fields are set to hold variable character strings up to 100 characters. The year field is set for integers to represent the academic year, and the gpa is a decimal type allowing for a grade point average to be stored with precision up to two decimal places.

User Facetus
by
7.5k points