这个SQL查询有什么问题?

本文关键字:问题 什么 SQL 查询 这个 | 更新日期: 2023-09-27 17:51:14

这个SQL查询有什么问题?

UPDATE Student SET Id = '3', 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 = 1WHERE Id = '3'

如果Student表为:

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])
);

提前谢谢伙计们!

这个SQL查询有什么问题?

表中没有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'

在您的查询中"section"列不存在。

检查这个

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

检查这个答案我已经改变了你的查询

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'