Answers for "create table with select in oracle"

SQL
9

create table oracle

CREATE TABLE ot.persons(
    person_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
    first_name VARCHAR2(50) NOT NULL,
    last_name VARCHAR2(50) NOT NULL,
    PRIMARY KEY(person_id)
);
Posted by: Guest on February-07-2020
1

oracle sql create table from select

-- Copy a table (datas, columns and storage parameters)
CREATE TABLE my_new_table AS SELECT * FROM my_source_table;
-- Use NOLOGGING, and PARALLEL if allowed for faster copy
CREATE TABLE my_new_table
    PARALLEL 10 NOLOGGING
AS
SELECT /*+ parallel(10) */ * FROM my_source_table;
-- To create an empty table:
CREATE TABLE my_new_table AS SELECT * FROM my_source_table
	WHERE rownum = 0;
Posted by: Guest on January-23-2021
1

oracle create as select

CREATE TABLE my_table AS
SELECT * FROM another_table t
WHERE 1=2 --delete the where condition if you also want the data
Posted by: Guest on March-15-2021
1

oracle sql create table

/*Deleting whole table with data */
DROP TABLE vehicles;
DROP TABLE owners;

/*First create only this table */
CREATE TABLE owners (
    owner_id NUMBER,
    first_name VARCHAR2(50 CHAR) NOT NULL,
    
    CONSTRAINT owners_pk PRIMARY KEY(owner_id)
);

/* One owner got many vehicles, one to many relation
	or one vehicle got many owners */
CREATE TABLE vehicles (
    vehicle_id NUMBER,
    vehicle_name VARCHAR2(50 CHAR) NOT NULL,
    
  	/* CONSTRAINT vehicle_pk PRIMARY KEY(vehicle_id) --If we had made PRIMARY KEY here it will be one to one relation */
    CONSTRAINT vehicle_owner_fk FOREIGN KEY(vehicle_id) REFERENCES owners(owner_id) ON DELETE SET NULL
);


INSERT INTO owners VALUES(1, 'Abbi');
INSERT INTO owners VALUES(2, 'Beatrix');
INSERT INTO owners VALUES(3, 'Caila');
INSERT INTO owners VALUES(4, 'Dea');
INSERT INTO owners VALUES(5, 'Elise');

INSERT INTO vehicles VALUES(1, 'car');
INSERT INTO vehicles VALUES(2, 'motorcycle');
INSERT INTO vehicles VALUES(3, 'airplane1');
INSERT INTO vehicles VALUES(4, 'airplane1');
INSERT INTO vehicles VALUES(4, 'steamer');
INSERT INTO vehicles VALUES(4, 'submarine');
COMMIT;

DELETE FROM projects WHERE vehicle_id = 4 AND vehicle_name = 'submarine';

/*
Sometimes Oracle SQL Dev don't like this sign ';', 
Primary Key is always NOT NULL UNIQUE,
single PK PRIMARY KEY(user_id), allowed combination:
(1,1) for example (user_id, project_id)
(2,1)
(3,1)
(4,2)

*/  
-- one line comment
Posted by: Guest on April-07-2021

Code answers related to "create table with select in oracle"

Code answers related to "SQL"

Browse Popular Code Answers by Language