0% found this document useful (0 votes)
2 views

SQL

The document provides SQL commands for creating and managing a database named 'gregs_list' and a table 'my_contacts' that stores contact information. It includes commands for inserting data, updating records, and retrieving table structure. Additionally, it explains the use of an auto-incrementing primary key for the 'contact_id' field.

Uploaded by

anshijain0306
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL

The document provides SQL commands for creating and managing a database named 'gregs_list' and a table 'my_contacts' that stores contact information. It includes commands for inserting data, updating records, and retrieving table structure. Additionally, it explains the use of an auto-incrementing primary key for the 'contact_id' field.

Uploaded by

anshijain0306
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

mysql -u root -p

CREATE DATABASE gregs_list;


USE gregs_list;
CREATE TABLE my_contacts(
-> last_name VARCHAR(30),
-> first_name VARCHAR(20),
-> email VARCHAR(50),
-> birthday DATE,
-> profession VARCHAR(50)
-> );

DESC my_contacts;
DROP TABLE my_contacts;
INSERT INTO my_contacts ( last_name,first_name,email ) VALUES ( ‘Jill’,
‘Anderson’, ‘[email protected]’);
'Grover\'s Mill’;

SELECT drink_name FROM drink_info WHERE drink_name >= ' I ' AND drink_name
< ‘M’;

UPDATE (table)
SET column_name=“ blah”
WHERE some_column=“ blah”;

UPDATE (table)
SET cost=cost+1
WHERE some_column=“blah”;

SHOW CREATE TABLE my_contacts:: For getting a code like this so that we dont
have to write the code for full table again.
:::
CREATE TABLE `my_contacts` (
`last_name` varchar(30) DEFAULT NULL,
`first_name` varchar(20) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`birthday` date DEFAULT NULL,
`profession` varchar(50) DEFAULT NULL

CREATE TABLE my_contacts (


contact_id INT NOT NULL,
last_name varchar(30) DEFAULT NULL,
first_name varchar(20) DEFAULT NULL,
email varchar(50) DEFAULT NULL,
birthday date DEFAULT NULL,
profession varchar(50) DEFAULT NULL,
PRIMARY KEY(contact_id));

contact_id INT NOT NULL AUTO_INCREMENT :- it starts the value from 1 and
keeps increasing by 1

You might also like