Dovberman
asked on
Oracle Create Table Primary Key
Need to verify the primary key syntax and usage.
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY (customer_no)
When rows are inserted, will the customer_no increment by 1?
Does the insert statement need to specify the customer_no column name?
INSERT INTO customer(customer_no, cust_name, cust_phone)
VALUES( ???, 'Mike', '385-367-1234');
Thanks,
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY (customer_no)
When rows are inserted, will the customer_no increment by 1?
Does the insert statement need to specify the customer_no column name?
INSERT INTO customer(customer_no, cust_name, cust_phone)
VALUES( ???, 'Mike', '385-367-1234');
Thanks,
ASKER
Yes, I should have said that I am using 10g.
Can I still include the constraint in the Create Table syntax?
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY (customer_no)
I will find out more about insert triggers and new value for incrementing the next number in a sequence.
Thanks,
Can I still include the constraint in the Create Table syntax?
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY (customer_no)
I will find out more about insert triggers and new value for incrementing the next number in a sequence.
Thanks,
Here is the code
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
ASKER
10g is definitely different.
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY (customer_no)
Should be:
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
CREATE SEQUENCE customer_no_seq start with 1
, birth_date DATE
, etc....
Is the sequence defined within the primary key column definition as shown above?
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
CREATE SEQUENCE customer_no_seq start with 1
, birth_date DATE
, etc....
OR is it defined within the CREATE TABLE block as shown below?
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
, birth_date DATE
, etc....);
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
, birth_date DATE
, etc....);
CREATE SEQUENCE customer_no_seq start with 1 -- Where is the table name referenced?
Thanks,
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY (customer_no)
Should be:
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
CREATE SEQUENCE customer_no_seq start with 1
, birth_date DATE
, etc....
Is the sequence defined within the primary key column definition as shown above?
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
CREATE SEQUENCE customer_no_seq start with 1
, birth_date DATE
, etc....
OR is it defined within the CREATE TABLE block as shown below?
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
, birth_date DATE
, etc....);
CREATE TABLE customer
( customer_no NUMBER
CONSTRAINT customer_no_pk PRIMARY KEY )
, birth_date DATE
, etc....);
CREATE SEQUENCE customer_no_seq start with 1 -- Where is the table name referenced?
Thanks,
ASKER
I found out that the created sequence can be shared and does not need to reference a specific table.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is new to me as a MS SQL Server developer.
MS SQL Server is similar to Oracle 12. You specify in the table creation that the primary key is self increments by one.
This helps.
Thank you.
MS SQL Server is similar to Oracle 12. You specify in the table creation that the primary key is self increments by one.
This helps.
Thank you.
ASKER
Excellent
http://docs.oracle.com/database/121/DRDAA/migr_tools_feat.htm#DRDAA109
For purpose of the autoincrement columns you need to create sequence and on insert triger will populate the column with newxt val from sequence...
as part of the creation of the table you should do it
Open in new window