Lab 2 - CLC
Lab 2 - CLC
The ALTER TABLE statement is also used to add and drop various constraints on
an existing table.
To delete a column in a table, use the following syntax (notice that some database
systems don't allow deleting a column):
To change the data type of a column in a table, use the following syntax:
Constraints can be specified when the table is created with the CREATE TABLE
statement, or after the table is created with the ALTER TABLE statement.
1
Huynh Ngoc Tu
TON DUC THANG UNIVERSITY Database System
FACULTY OF INFORMATION TECHNOLOGY Semester II
Syntax
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
....
);
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This ensures
the accuracy and reliability of the data in the table. If there is any violation
between the constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to
a column, and table level constraints apply to the whole table.
Syntax
It is possible to write the INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be inserted:
2
Huynh Ngoc Tu
TON DUC THANG UNIVERSITY Database System
FACULTY OF INFORMATION TECHNOLOGY Semester II
If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of the
values is in the same order as the columns in the table. The INSERT INTO syntax
would be as follows:
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; The DELETE statement is used to delete existing records in a
table.
Syntax
DELETE FROM table_name
WHERE condition;
3
Huynh Ngoc Tu
TON DUC THANG UNIVERSITY Database System
FACULTY OF INFORMATION TECHNOLOGY Semester II
PRACTICE EXERCISE
Please create the MovieDB database and input its data according to the above
tables.
4
Huynh Ngoc Tu