1. Primary Key :
#insert uniqe value
CREATE TABLE STATION
(ID INT ,STATION_NAME varchar(11),DATA_DATE DATETIME,PRIMARY KEY (ID));
#uniqe value insert to ID & DATA_DATE
CREATE TABLE STATION
(ID INT ,STATION_NAME varchar(11),DATA_DATE DATETIME,PRIMARY KEY (ID,DATA_DATE));
Add constraint
alter table STATION add CONSTRAINT PK_ID PRIMARY KEY (ID,DATA_DATE)
2.Unique Key
#uniqe value insert to ID & DATA_DATE
CREATE TABLE STATION
(ID INT AUTO_INCREMENT,STATION_NAME varchar(11),DATA_DATE DATETIME,UNIQUE KEY (ID));
#alter table STATION add constraint UK_SN
unique key (STATION_NAME)
Foreign key :
CREATE TABLE STATION_NAME1
(ID INT ,Name VARCHAR(20) primary key)
Note :This table column should be unique
#CREATE TABLE STATION
(ID INT PRIMARY KEY ,STATION_NAME varchar(11),DATA_DATE DATETIME);
#Add foreign Key :
alter table STATION add foreign key (STATION_NAME) REFERENCES STATION_NAME1(Name)
No comments:
Post a Comment