DBMS - SQL 1
DBMS - SQL 1
To create a table in a Database Management System (DBMS) using SQL (Structured Query
Language), you use the CREATE TABLE command. This defines the table name and the
columns, along with their data types and optional constraints.
Basic Syntax:-
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);
Examples:
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(30),
age INT,
dob DATE
);
Explanation:
• student_id is an integer and the primary key (unique identifier).
• name is a variable-length string of up to 100 characters.
• age is an integer.
• dob is a date field.
Fields/Attributes
Practice problems:
Create a Books Table
Requirements:
• book_id (Primary Key, Integer)
• title (VARCHAR, not null)
• author (VARCHAR, not null)
• price (DECIMAL, must be > 0)
• published_year (INTEGER)
General syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Or
Examples
Or