SQL Tutorial – 9: Create Table Statement




In this tutorial we’ll learn to create tables in SQL using the CREATE TABLE Statement.

Original source


21 responses to “SQL Tutorial – 9: Create Table Statement”

  1. suppose i want to create a table name ABC using DDL queries… in this table we have a column named as month.. i want that values of month should integer between 1 and 12 only? can u plz help me how to write a DDL query for this in MS-Access?

  2. Sir Can you check if my answer to this question is right pls
    Write a single SQL statement to create a new table named Login with five columns: Username(Text), Password(Text) LastUpdate(Date) Status(Text) and CustomerID(Interger)

    Assign Username as the primary key of the table
    The Password should never be NULL
    Set the default value of LastUpdate to the current date and time (Aust Time)
    Define a check on Status to make sure the value could either be active or inactive
    Assign CustomerID as a foreign key referencing the Customer table

    ANSWER
    CREATE TABLE Login
    (Username TEXT PRIMARY KEY NOT NULL,
    Password TEXT NOT NULL,
    Last Update DATETIME DEFAULT GETDATE (NZTIME),
    Status TEXT CHECK (Status = "active" OR Status = "inactive"),
    FOREIGN KEY (CustomerID) REFERENCE Customer (CustomerID) ON DELETE NO ACTION ON UPDATE NO ACTION
    )

Leave a Reply