There are no items in your cart
Add More
Add More
Item Details | Price |
---|
1 August 2025
Welcome to the SQL magic show, where we transform data using the CREATE TABLE statement! 🎩✨
In the enchanted world of relational databases, tables are where the real magic happens. Let's cast the CREATE TABLE spell and see the wonders unfold:
CREATE TABLE table_name
( column1 datatype,
column2 datatype,
column3 datatype,
...
columnN datatype,
PRIMARY KEY(one or more columns));
Here, we define the name of our mystical table and the essence of each column within it. The PRIMARY KEY is like the secret key to unlock the true power of your table.
CREATE TABLE CUSTOMERS (
ID INT NOT NULL,
NAME VARCHAR(20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(25),
SALARY DECIMAL(18, 2),
PRIMARY KEY(ID)
);
DESC CUSTOMERS;
objective Copy code
Field. Type Null Key Default Extra
ID int(11). NO PRI NULL
NAME. varchar(20) NO NULL
AGE int(11) NO NULL
ADDRESS char(25) YES NULL
SALARY decimal(18,2) YES NULL
Your table is alive and kicking!
Sometimes, in the vast realms of SQL, tables may already exist. Fear not! We wield the magic words:
CREATE TABLE IF NOT EXISTS CUSTOMERS (
ID INT NOT NULL,
NAME VARCHAR(20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(25),
SALARY DECIMAL(18, 2),
PRIMARY KEY(ID)
);
Ever wanted to clone a table? With SQL, you can create a new table from an existing one!
CREATE TABLE NEW_TABLE_NAME AS
SELECT [column1, column2...columnN]
FROM EXISTING_TABLE_NAME
WHERE Condition;
For instance:
CREATE TABLE SALARY AS
SELECT ID, SALARY
FROM CUSTOMERS;
A new table named SALARY is born, inheriting the magic of ID and SALARY from the CUSTOMERS table.
And there you have it – the SQL CREATE TABLE spellbook! Now go forth, create tables, and let the data magic flow! 🌟🔮
Sajan Tonge
Founder & CEO
My Analytics School