In: Computer Science
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence” with the following attributes (columns):
A field named “id” which has data type auto_increment,
A field named “country_name” which has data type varchar(50), and
A field named “independence_date” which has type “date.”
After you create the table, run the following SQL command:
INSERT INTO independence(country_name, independence_date) VALUE (‘United States’,’1776-07-04’)
Submit a 1-page Microsoft Word document that shows the following:
The SQL command you used to create the “independence” table and a list of the rows in the “independence” table.
Explain the purpose of the field named “id.” Why do you not have to include it in an insert statements? How would change the incrementing value to a number greater than one?
Solution:-
use world_x;
CREATE TABLE independence (
id int NOT NULL AUTO_INCREMENT,
country_name varchar(50),
independence_date date,
PRIMARY KEY (id)
);
INSERT INTO independence(country_name, independence_date)
VALUE (‘United States’,’1776-07-04’);
================
Explain the purpose of the field named “id.” =>
The id field is unique identifier, through which we identify the records in the independence table. So if row1 corresponds to id=1, row 2 as id=2, then we can select the records just using the ids.
Why do you not have to include it in an insert statements? =>
As id column is auto-increment, it means, each time a record is inserted, system itself will assign it a id, which is one more than the last assigned id.
How would change the incrementing value to a number greater than one? =>
SET @@auto_increment_increment=2;
Above statement will increment the ids using number 2 each time.