这个SQL查询有什么问题?

时间:2015-05-30 05:44:51

标签: c# sql asp.net

这个SQL查询有什么问题?

  

更新学生SET ID =' 3',电子邮件=' 3 @3.com',密码=' 20105',   名称=' 3',FatherName =' 3',CNIC = 3,ContactNo = 3
  ,Section =' G',Department =' EE',Image =   ' 10414450_624151571051295_2997621265926572989_n.png',SemesterId = 1   在哪里ID =' 3'

如果学生表是:

CREATE TABLE [dbo].[Student] (
    [Id]         VARCHAR (10)  NOT NULL,
    [Email]      VARCHAR (50)  NOT NULL,
    [Password]   VARCHAR (50)  NOT NULL,
    [Name]       VARCHAR (50)  NOT NULL,
    [FatherName] VARCHAR (50)  NULL,
    [CNIC]       CHAR (13)     NOT NULL,
    [ContactNo]  CHAR (11)     NOT NULL,
    [Department] VARCHAR (10)  NULL,
    [Degree]     VARCHAR (10)  NULL,
    [Image]      VARCHAR (MAX) NULL,
    [SemesterId] SMALLINT      NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC),
    FOREIGN KEY ([Department]) REFERENCES [dbo].[Department] ([Id]),
    CONSTRAINT [FK_Student_ToDegree] FOREIGN KEY ([Degree]) REFERENCES [dbo].[Degree] ([Name])
);

先谢谢老兄!

3 个答案:

答案 0 :(得分:0)

表格中没有Section列。我认为它应该是Degree

所以你的查询将是

UPDATE Student SET Id = '3', Email = '3@3.com', Password = '20105', Name = '3', FatherName = '3', CNIC = 3, ContactNo = 3, Department = 'EE', Degree = 'G', Image = '10414450_624151571051295_2997621265926572989_n.png', SemesterId = 1 WHERE Id = '3'

答案 1 :(得分:0)

在您的查询"部分"您的定义中不存在列。

检查

I execute this commented script to check your issue. 
--CREATE TABLE [dbo].[Student] (
--    [Id]         VARCHAR (10)  NOT NULL,
--    [Email]      VARCHAR (50)  NOT NULL,
--    [Password]   VARCHAR (50)  NOT NULL,
--    [Name]       VARCHAR (50)  NOT NULL,
--    [FatherName] VARCHAR (50)  NULL,
--    [CNIC]       CHAR (13)     NOT NULL,
--    [ContactNo]  CHAR (11)     NOT NULL,
--    [Department] VARCHAR (10)  NULL,
--    [Degree]     VARCHAR (10)  NULL,
--    [Image]      VARCHAR (MAX) NULL,
--    [SemesterId] SMALLINT      NULL,
--    PRIMARY KEY CLUSTERED ([Id] ASC)
--    --,FOREIGN KEY ([Department]) REFERENCES [dbo].[Department] ([Id]),
--    --CONSTRAINT [FK_Student_ToDegree] FOREIGN KEY ([Degree]) REFERENCES [dbo].[Degree] ([Name])
--);

--insert into student values (33, 'test@gmail.com' , 'password', 'test' , 'fathername', 'cni', '9999999', 'dept1' , 'degree1' , 'image1', 1 )

--Section column is not exist in your table 
UPDATE Student SET Id = '1', Email = '3@3.com', Password = '20105', Name = '3', FatherName = '3', CNIC = 3 , ContactNo = 3
--, Section = 'G'   
,Department = 'EE', Image = '10414450_624151571051295_2997621265926572989_n.png', SemesterId = 1 WHERE Id = '1'

select * from student

答案 2 :(得分:0)

选中此答案我已更改您的查询

UPDATE Student 
SET Id = '3', Email = '3@3.com', Password = '20105', 
    Name = '3', FatherName = '3', CNIC = '3', ContactNo = '3',
    Department = 'EE', Degree = 'G', 
    Image = '10414450_624151571051295_2997621265926572989_n.png', 
    SemesterId = 1 
WHERE Id = '3'