SQL考试,急
答案:1 悬赏:30 手机版
解决时间 2021-02-14 19:01
- 提问者网友:酱爆肉
- 2021-02-13 20:26
SQL考试,急
最佳答案
- 五星知识达人网友:枭雄戏美人
- 2021-02-13 22:03
1.
CREATE TABLE [dbo].[Student](
[Sno] [char](10) NOT NULL,
[Sname] [varchar](20) NULL,
[SSex] [char](10) NULL,
[Sage] [int] NULL,
CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED
(
[Sno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
--==下面的是说明,你可以不写
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'学号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Sno'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'姓名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Sname'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'性别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'SSex'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'年龄' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Sage'
GO
--==
2.
INSERT INTO dbo.Student
VALUES('201213001','王晓红','女',20)
--==
3.
CREATE VIEW [dbo].[vGetStudentInfo]
AS
SELECt Sno, Sname, SSex, Sage
FROM dbo.Student
WHERe (Sage > 20) AND (SSex = '女')
GO
因为只有一条数据并且她的年龄等于20,而题目要求是大于20,所以没有数据。
--==
4.题目是不是有点问题,还是我理解错了,应该是输出提示字符吧,输入提示字符的话,没看明白,如果错了,那你再追问,我是按照输出提示来做的
IF EXISTS(SELECt * FROM SYSOBJECTS WHERe XTYPE = 'TR' AND NAME = 'TR_InsertStudentInfo')
DROP TRIGGER TR_InsertStudentInfo
GO --这个地方是判断是否有触发器如果有先删除了。
CREATE TRIGGER TR_InsertStudentInfo
ON dbo.Student
AFTER INSERT
AS
BEGIN
PRINT '输入一行新数据'
END
GO
--==
如果第四题不太对的话,那么再追问
CREATE TABLE [dbo].[Student](
[Sno] [char](10) NOT NULL,
[Sname] [varchar](20) NULL,
[SSex] [char](10) NULL,
[Sage] [int] NULL,
CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED
(
[Sno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
--==下面的是说明,你可以不写
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'学号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Sno'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'姓名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Sname'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'性别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'SSex'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'年龄' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Student', @level2type=N'COLUMN',@level2name=N'Sage'
GO
--==
2.
INSERT INTO dbo.Student
VALUES('201213001','王晓红','女',20)
--==
3.
CREATE VIEW [dbo].[vGetStudentInfo]
AS
SELECt Sno, Sname, SSex, Sage
FROM dbo.Student
WHERe (Sage > 20) AND (SSex = '女')
GO
因为只有一条数据并且她的年龄等于20,而题目要求是大于20,所以没有数据。
--==
4.题目是不是有点问题,还是我理解错了,应该是输出提示字符吧,输入提示字符的话,没看明白,如果错了,那你再追问,我是按照输出提示来做的
IF EXISTS(SELECt * FROM SYSOBJECTS WHERe XTYPE = 'TR' AND NAME = 'TR_InsertStudentInfo')
DROP TRIGGER TR_InsertStudentInfo
GO --这个地方是判断是否有触发器如果有先删除了。
CREATE TRIGGER TR_InsertStudentInfo
ON dbo.Student
AFTER INSERT
AS
BEGIN
PRINT '输入一行新数据'
END
GO
--==
如果第四题不太对的话,那么再追问
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯