Database Systems - CREATE TABLE Statement - Creating Tables in SQL

Опубликовано: 06 Октябрь 2024
на канале: Appficial
284
7

The CREATE TABLE statement creates a new database table. Within this statement, you will specify the name of the table, and the data type and name of each column

CREATE TABLE Movie (
ID SMALLINT UNSIGNED,
Title VARCHAR(100),
Rating VARCHAR(9),
ReleaseDate DATE,
Budget DECIMAL(10,2)
);

If you need to add, modify, or delete any column in an existing database table, use the ALTER TABLE statement. To add a column:

ALTER TABLE TableName
ADD ColumnName DataType;

To change or modify a column:

ALTER TABLE TableName
CHANGE CurrentColumnName NewColumnName NewDataType;

To drop or delete a column:

ALTER TABLE TableName DROP ColumnName;

Note that if the table has a foreign key constraint that references a table's primary key, the table with primary key cannot be deleted with a DROP TABLE statement unless the table with the foreign key constraint is deleted first.


Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!