CREATE TABLE Students
(
ROLL_NO integer,
NAME varchar(20),
SUBJECT varchar(20)
);
(
ROLL_NO integer,
NAME varchar(20),
SUBJECT varchar(20)
);
==========================================================================
create table from existing table:
CREATE TABLE table_name AS SELECT * FROM old_table_name WHERE ..... ;
The following SQL creates a copy of the employee table.
CREATE TABLE EmployeeCopy AS
SELECT EmployeeID, FirstName, Email
FROM Employee;
==========================================================================
Create table with primary Key and foreign key:
create table supplier
(
supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);
create table products
(
product_id numeric(10) not null,
supplier_id numeric(10) not null,
CONSTRAINT fk_supplier
FOREIGN KEY (supplier_id)
REFERENCES supplier(supplier_id)
);
For MySQL / SQL Server /Oracle / MS Access:
CREATE TABLE Employee(
EmployeeID NOT NULL,
FirstName varchar(255) NOT NULL,
LastName varchar(255),
City varchar(255),
CONSTRAINT PK_Employee PRIMARY KEY (EmployeeID, FirstName)
);
==========================================================================
Create entire table from existing table with data:
create table employee_copy as select * from employee where 1=1;
select * from employee_copy
==========================================================================
Create entire table from existing table withOutdata:
create table employee_copy2 as select * from employee where 1=0;
select * from employee_copy2
==========================================================================
Create/Back Table with Partition Columns;
drop table if exists employee_copy3;
create table if not exists employee_copy3 like employee;
insert into employee_copy3 partition(part_col) select * from employee;