Learning SQL
Using SQL
Structured Query Language (SQL) is a declarative programming language used for accessing data storied in relational databases. It appears in or is a core part of many common software packages like MySQL, PostgreSQL, Microsoft SQL Server, and Oracle Database.
While the standard actions of SELECT, INSERT, UPDATE, and DELETE help with interacting with existing data, there are also ways to add, change, or remove tables themselves. These are CREATE TABLE, ALTER TABLE, and DROP TABLE.
ALTER TABLE
Sometimes, it can be useful to change the columns of a table. For this purpose, the keywords ALTER TABLE can be used.
Table Name: Companies | |
ID | Name |
Like with CREATE TABLE, the ALTER TABLE keywords also need to know what table needs to be changed.
ALTER TABLE Companies
ADD
To add new columns to a table, the keyword ADD is used.
ALTER TABLE Companies ADD StockPrice
Table Name: Companies | ||
ID | Name | StockPrice |
DROP
To remove columns from a table, the keyword DROP is used.
ALTER TABLE Companies DROP StockPrice
Table Name: Companies | |
ID | Name |