Free Study Material
A MySQL server can hold many separate databases at once — before running any table commands, SQL needs to know which one you mean. Aliases, separately, are about making query output more readable.
USE database_name; — selects which database your subsequent commands apply to.DESC table_name; (short for DESCRIBE) — displays a table's structure: its columns, their data types, and constraints — not the data inside it.AS — creates an alias, a temporary display name for a column (or table) in a query's output only.USE school;
DESC STUDENT;
USE school; tells the server every command after it applies to the school database — the same one connected to in the Python-SQL Interface topics. DESC STUDENT; then lists STUDENT's structure: each column's name, its data type (INT, VARCHAR(20), and so on), and whether it allows NULL — not a single row of actual data.
SELECT Name, Marks AS Score_Card FROM STUDENT;
The actual column in the table is still named Marks — Score_Card only appears as the heading in this one query's result. The underlying table is completely unchanged.
Note: DESC shows a table's STRUCTURE (columns and types), not its data — for that, you'd still use SELECT * FROM table_name.
USE database_name; selects which database to work in. DESC table_name; shows a table's structure. AS creates a temporary alias for a column's display name in query output, without renaming anything in the actual table.
Before you can create a Table, you must create a **Database** to hold it. Here are the commands to manage the database environment.
Creates a new empty container.
CREATE DATABASE School;
Selects the database to work on.
USE School;
Lists all tables in the current DB.
SHOW TABLES;
Shows structure (cols, types) of a table.
DESC Student;
You can give a temporary "nickname" to a column or table using the keyword AS. This is useful for making output readable.
| Name | Half_Marks |
|---|---|
| Ravi | 45.0 |
/* ==================================================
SYSTEM SETUP
================================================== */
DROP TABLE IF EXISTS STUDENT;
CREATE TABLE STUDENT (Name VARCHAR(20), Marks INT);
INSERT INTO STUDENT VALUES ('Ravi', 90);
/* ==================================================
YOUR TASK
Select Name and Marks.
Use alias 'AS Score_Card' for Marks.
================================================== */
-- SELECT Name, Marks AS ...