鍵約束和參紹約束的實例腳本
外鍵約束和參紹約束的實例腳本
/*
外鍵約束和參紹約束
pubs數據庫的CarIfo表創建外鍵約束
*/
USE Pubs
GO
/*不顯示行數*/
SET NOCOUNT ON
GO
/*創建示例表*/
IF EXISTS (SELECT * FROM dbo
WHERE id = object_id(N
AND OBJECTPROPERTY(id
DROP TABLE CarInfo
GO
CREATE TABLE CarInfo(
Car_ID CHAR (
Name CHAR (
Type CHAR (
Driver_Type CHAR (
)
IF EXISTS (SELECT * FROM dbo
WHERE id = object_id(N
AND OBJECTPROPERTY(id
DROP TABLE CarFactory
GO
CREATE TABLE CarFactory(
ID CHAR (
Name CHAR (
PostCode CHAR (
Telphone CHAR (
Address CHAR (
)
GO
ALTER TABLE CarFactory
ADD CONSTRAINT PK_Car_ID
PRIMARY KEY NONCLUSTERED (ID)
GO
ALTER TABLE CarInfo
WITH NOCHECK
ADD CONSTRAINT Car_id_link
FOREIGN KEY (Car_ID) REFERENCES CarFactory(ID)
GO
USE master
EXEC sp_dboption Pubs
GO
USE Pubs
SET NOCOUNT ON
GO
From:http://tw.wingwit.com/Article/program/Oracle/201311/16611.html