mysql>DESCRIBE potluck; +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | YES | | NULL | | | food | varchar(30) | YES | | NULL | | | confirmed | char(1) | YES | | NULL | | | signup_date | date | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 5 rows inset (0.01 sec)
Add Information to a Table
1
INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "John", "Casserole","Y", '2016-11-22');
Once you input that in, you will see the words:
1
Query OK, 1 row affected (0.00 sec)
Let’s add a couple more people to our group:
1 2 3
INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "Sandy", "Key Lime Tarts","N", '2016-11-22'); INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "Tom", "BBQ","Y", '2016-11-18'); INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "Tina", "Salad","Y", '2016-11-15');
1 2 3 4 5 6 7 8 9 10
mysql> SELECT * FROM potluck; +----+-------+----------------+-----------+-------------+ | id | name | food | confirmed | signup_date | +----+-------+----------------+-----------+-------------+ | 1 | John | Casserole | Y | 2012-04-11 | | 2 | Sandy | Key Lime Tarts | N | 2012-04-14 | | 3 | Tom | BBQ | Y | 2012-04-18 | | 4 | Tina | Salad | Y | 2012-04-10 | +----+-------+----------------+-----------+-------------+ 4 rows inset (0.00 sec)
Update Information in the Table
1 2 3 4
UPDATE `potluck` SET `confirmed` = 'Y' WHERE `potluck`.`name` ='Sandy';
Add and Delete a Column
1 2 3
ALTER TABLE potluck ADD email VARCHAR(40); # Add ALTER TABLE potluck ADD email VARCHAR(40) AFTER name; # Add a Column 'email' after 'name' ALTER TABLE potluck DROP email; # Delete
Delete a Row
1
DELETE from [table name] where [column name]=[field text];
For example,
1 2 3 4 5 6 7 8 9 10 11 12
mysql> DELETE from potluck where name='Sandy'; Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM potluck; +----+------+-----------+-----------+-------------+ | id | name | food | confirmed | signup_date | +----+------+-----------+-----------+-------------+ | 1 | John | Casserole | Y | 2012-04-11 | | 3 | Tom | BBQ | Y | 2012-04-18 | | 4 | Tina | Salad | Y | 2012-04-10 | +----+------+-----------+-----------+-------------+ 3 rows inset (0.00 sec)
Notice that the id numbers associated with each person remain the same.