SQL
What is SQL Database?
Table is a collection of data in terms of rows and columns.
Example: student
Drop Table:
Rename Table:
Copy Table:
student_name | address | age |
---|---|---|
john | USA | 20 |
william | UK | 22 |
doe | NEW YORK | 21 |
In the above table, "student" is the table name, "student_name","address"and "age" are the column names.
Syntax
create table "tablename" ("column1" "data type", "column2" "data type", ...
"columnN" "data type");
CREATE TABLE:
CREATE TABLE STUDENTS (ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), PRIMARY KEY (ID) );
CREATE TABLE:
CREATE TABLE STUDENTS (ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), PRIMARY KEY (ID) );
Sql Drop Table is used to delete a table and all data from a table.
Syntax
DROP table "table_name"; (
WHERE condition1 AND condition 2;
WHERE condition1 AND condition 2;
Example
Sql Rename Table is used to change the name of a table.
Syntax
ALTER TABLE "table_name"; (
Rename TO new_table_name;
Rename TO new_table_name;
Example
Alter table students Rename to student1;
Copy a one SQL Table into another table in the same database.
Syntax
SELECT * INTO destination_table FROM source_table
Example
SELECT * INTO CustomersBackup FROM Customers;