Create a database:


CREATE DATABASE places;


Create a table with columns specifying the datatype:

CREATE TABLE cities
(
id          int,
city        varchar(30),
state       varchar(2),
costindex   decimal(5,2)
)

Insert a new row of data:

INSERT INTO cities(id, city, state, costindex)
VALUES(1, 'Reno', 'NV', 80.20)

Insert data with empty columns:

INSERT INTO cities(id, city, state)
VALUES(2, 'Provo', 'UT')

sql1

Update a value of data:

UPDATE cities
SET costindex = 80.50
WHERE city = 'Reno';

Add a column:

ALTER TABLE cities
ADD COLUMN avgtemp int;

Sort results in descending order:

SELECT name
FROM cities
ORDER BY avgtemp DESC;

Select results based on a condition:

SELECT *
FROM cities
WHERE avgtemp > 80;

Select results based on multiple conditions:

SELECT *
FROM cities
WHERE avgtemp > 80 and costindex < 90;

Delete a row:

DELETE FROM cities
WHERE id = 2;

Drop a table:


DROP TABLE states;

Tags: , , ,

In categories: databases

COMMENTS

LEAVE A REPLY

Only the name field is required. Your email will not be published.