2015-05-30 240 views
-3

這個SQL查詢有什麼問題?這個SQL查詢有什麼問題?

UPDATE學生集ID = '3',電子郵件= '[email protected]',密碼= '20105', 名稱= '3',FatherName = '3',CNIC = 3,ContactNo = 3
,第= 'G',部= 'EE',圖片= '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]) 
); 

先謝謝了!

+0

什麼是錯的錯誤? –

+0

您是否收到錯誤? –

+2

'Section ='G''什麼是'Section'?應該是'Department'嗎? –

回答

0

表中沒有Section列。我認爲它應該是Degree

所以您的查詢就會

UPDATE Student SET Id = '3', Email = '[email protected]', 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'

+0

謝謝。 @Nikhil Agrawal這就是問題所在。對不起 –

+0

我試過了,但在10分鐘前我不能接受答案...... –

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, '[email protected]' , 'password', 'test' , 'fathername', 'cni', '9999999', 'dept1' , 'degree1' , 'image1', 1) 

--Section column is not exist in your table 
UPDATE Student SET Id = '1', Email = '[email protected]', 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 
+0

感謝您的時間。 –

0

檢查這個答案我有改變你的查詢

UPDATE Student 
SET Id = '3', Email = '[email protected]', 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'