0% found this document useful (0 votes)
21 views8 pages

Lesson 4 Creating, Altering, and Deleting Databases and Tables

The document discusses the four basic DDL commands in SQL: CREATE, USE, ALTER, and DROP. CREATE allows creating databases, tables, indexes, views and functions. USE selects an existing database. ALTER modifies database tables by adding, dropping, or changing column data types. DROP deletes existing database objects like tables.

Uploaded by

Jiiyad Lazo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views8 pages

Lesson 4 Creating, Altering, and Deleting Databases and Tables

The document discusses the four basic DDL commands in SQL: CREATE, USE, ALTER, and DROP. CREATE allows creating databases, tables, indexes, views and functions. USE selects an existing database. ALTER modifies database tables by adding, dropping, or changing column data types. DROP deletes existing database objects like tables.

Uploaded by

Jiiyad Lazo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

LESSON 4

Creating, Altering, and Deleting


Databases and Tables
The four basic DDL commands

CREATE USE ALTER DROP


CREATE – It allows you to create database objects like table, index, view, and function

USE – Before you can use the USE command, a database must first be created. USE
command is used to select any existing database in the SQL schema. You would need
to select a database where all the operations would be performed.

ALTER – It modifies the structure of an existing database table. This can add up
additional columns, drop existing columns, and even alter the data type of columns
involved in a database table.

DROP – It deletes existing objects from the database. It is used to remove a table,
including its data, indexes, triggers, constraints, and permission specifications
Creating a table •Create Table – It is a DDL language
that allows the creation of a table.
• [table name] – It is the name of the
• CREATE TABLE [table name] table you wish to create.
•( • Column name – It is the name of the
•[column name] [data type] [null | not field.
null], • Data type – It is the type of data that
the column will hold.
•[column name] [data type] [null | not
null], • [null|not null] – It is an optional value
that can be added or not. It enforces a
•[column name] [data type] [null | not column to accept or. not to accept null
null] values. By default, a column can hold
•) null values
Use Command
Syntax: USE [Database_Name]

Example: USe productprofile


Example: USE product profile
Example: USE product_profile
Example: use product_profile
Alter command
Example:
• ALTER TABLE student_profile
ADD username NVARCHAR(50);
• ALTERTABLE student_profile
ADD username NVARCHAR(50);
• ALTER_TABLE student_profile
ADD username NVARCHAR(50);
• To drop a column:
Syntax: ALTER TABLE [table_name]
DROP COLUMN [column_name];
Example : ALTER TABLE student_info
DROP COLUMN Student_address;
Note: Dropping or removing a column name is done one at a time.
• To alter or modify a column:
Syntax:ALTER TABLE [table_name]
ALTER COLUMN [column_name] [data type];
Example: ALTER TABLE student_info
ALTER COLUMN Student_ID int NOT NULL;
DROP Command

• Syntax:
• DROP TABLE [table_name];
• Example:
• DROP TABLE student_info

• Table Designer allows you to add a column.


• Column Properties allows you to specify column
attributes.
• Table Properties allows you to specify table attributes.

You might also like