1

I'm new to MySQL, and would like to understand the following CREATE TABLE code:

CREATE TABLE IF NOT EXISTS label_gtin (
  LABEL_ID int NOT NULL,
  GTIN_CD varchar(13) NOT NULL,
  KEY LABEL_ID (LABEL_ID,GTIN_CD)
);

Specifically, I'd like to understand what "KEY LABEL_ID (LABEL_ID,GTIN_CD)" does, and translate this to Postgresql.

Would appreciate any help. Thanks a lot!

1

1 Answer 1

2

you can write given CREATE TABLE code in postgresql as shown :

CREATE TABLE IF NOT EXISTS label_gtin (
  LABEL_ID integer NOT NULL,
  GTIN_CD varchar(13) NOT NULL,
  CONSTRAINT LABEL_ID PRIMARY KEY(LABEL_ID,GTIN_CD)
);

Key (PRIMARY KEY in postgresql) is a Primary Key constraint on one or more columns whose combination is unic for records in table.

Syntax: CONSTRAINT <Constraint Name> PRIMARY KEY(<Column1>[,<Column2>,<Column3>,...])

IF NOT EXISTS: Do not throw an error if a relation with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing relation is anything like the one that would have been created.

you can Refer this link for details : http://www.postgresql.org/docs/current/static/sql-createtable.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.