日期:2014-05-17 浏览次数:20546 次
--表的结构大概是这样的 [Tab_Details]的[UserID]是外键
CREATE TABLE [dbo].[Tab_User](
[UserID] [int] IDENTITY(1,1)PRIMARY KEY,
[UserName] [nvarchar](50) NOT NULL,
[UserPassword] [nvarchar](50) NOT NULL,
[UserAge] [int] NOT NULL,
[UserBirthday] [datetime] NOT NULL,
[UserGongzi] [money] NULL,
[UserSex] [bit] NOT NULL,
[UserCityID] [int] NOT NULL,
)
CREATE TABLE [Tab_Details](
[DetailsID] [int]IDENTITY(1,1) PRIMARY KEY,
[UserID] [int]FOREIGN KEY REFERENCES Tab_User(UserID) ,--
[UserIP] [varchar](50),
[UserLastLoginTime] [datetime] NOT NULL ,
[UserPhone] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[UserEMail] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[UserTouxiang] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
)
--我想这么写却报错!
INSERT INTO Tab_Details
(UserID,UserIP,UserLastLoginTime,UserPhone,UserEMail,UserTouxiang)
VALUES(
INSERT INTO Tab_User
(UserName,UserPassword,UserAge,UserBirthday,UserGongzi,UserSex,UserCityID)OUTPUT INSERTED.UserID
VALUES('郭德纲','1234',38,1974-11-13,100000,1,1),
'119.119.119.119',2012-11-11,'13888888888','360@qq.com''http://xx.com/1.jpg'
);
--表的结构大概是这样的 [Tab_Details]的[UserID]是外键
CREATE TABLE [dbo].[Tab_User](
[UserID] [int] IDENTITY(1,1)PRIMARY KEY,
[UserName] [nvarchar](50) NOT NULL,
[UserPassword] [nvarchar](50) NOT NULL,
[UserAge] [int] NOT NULL,
[UserBirthday] [datetime] NOT NULL,
[UserGongzi] [money] NULL,
[UserSex] [bit] NOT NULL,
[UserCityID] [int] NOT NULL,
)
CREATE TABLE [Tab_Details](
[DetailsID] [int]IDENTITY(1,1) PRIMARY KEY,
[UserID] [int]FOREIGN KEY REFERENCES Tab_User(UserID) ,--
[UserIP] [varchar](50),
[UserLastLoginTime] [datetime] NOT NULL ,
[UserPhone] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[UserEMail] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[UserTouxiang] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
)
DECLARE @id INT
INSERT INTO Tab_User
( UserName ,
UserPassword ,
UserAge ,
UserBirthday ,
UserGongzi ,
UserSex ,
&nbs