SQL数据库,创建表的所有代码,查询表,增删改,越详细越好,最好有注释
展开全部
举例:学生成绩数据库
1.创建一个数据库:
CREATE DATABASE XSCJ
ON
(NAME='XSCJ_DATA',
FILENAME='D:\Program Files\Microsoft SQL Server\MSSQL\Data\XSCJ_DATA.MDF',
SIZE=5MB,
MAXSIZE=50MB,
FILEGROWTH=10%
)
LOG ON
(NAME='XSCJ_LOG',
FILENAME='D:\Program Files\Microsoft SQL Server\MSSQL\Data\XSCJ_LOG.LOG',
SIZE=2MB,
MAXSIZE=5MB,
FILEGROWTH=1MB
)
GO
2.创建学生信息表:
CREATE TABLE XS
(学号 CHAR(6) PRIMARY KEY,
姓名 CHAR(6) NOT NULL,
专业名 CHAR(10) NULL,
性别 BIT NOT NULL,
出生时间 DATETIME NOT NULL,
总学分 TINYINT NOT NULL,
备注 TEXT NULL
)
GO
3.向XS表中插入数据:
INSERT INTO XS
VALUES('001106','李方方','计算机',1,'1980-11-20',50,NULL)
GO
INSERT INTO XS
VALUES('001107','李明','计算机',1,'1980-05-01',54,'提前修完《数据结构》,并获得学分')
GO
INSERT INTO XS
VALUES('001108','林一帆','计算机',1,'1979-08-05',52,'已提前修完1门课')
GO
4.查询XS表:
SELECT *
FROM XS
5.修改学号为001106同学的专业:
UPDATE XS
SET 专业名='通信工程'
WHERE 学号='001106'
GO
6.删除李方方同学的信息:
DELETE FROM XS
WHERE 姓名='李方方'
GO
1.创建一个数据库:
CREATE DATABASE XSCJ
ON
(NAME='XSCJ_DATA',
FILENAME='D:\Program Files\Microsoft SQL Server\MSSQL\Data\XSCJ_DATA.MDF',
SIZE=5MB,
MAXSIZE=50MB,
FILEGROWTH=10%
)
LOG ON
(NAME='XSCJ_LOG',
FILENAME='D:\Program Files\Microsoft SQL Server\MSSQL\Data\XSCJ_LOG.LOG',
SIZE=2MB,
MAXSIZE=5MB,
FILEGROWTH=1MB
)
GO
2.创建学生信息表:
CREATE TABLE XS
(学号 CHAR(6) PRIMARY KEY,
姓名 CHAR(6) NOT NULL,
专业名 CHAR(10) NULL,
性别 BIT NOT NULL,
出生时间 DATETIME NOT NULL,
总学分 TINYINT NOT NULL,
备注 TEXT NULL
)
GO
3.向XS表中插入数据:
INSERT INTO XS
VALUES('001106','李方方','计算机',1,'1980-11-20',50,NULL)
GO
INSERT INTO XS
VALUES('001107','李明','计算机',1,'1980-05-01',54,'提前修完《数据结构》,并获得学分')
GO
INSERT INTO XS
VALUES('001108','林一帆','计算机',1,'1979-08-05',52,'已提前修完1门课')
GO
4.查询XS表:
SELECT *
FROM XS
5.修改学号为001106同学的专业:
UPDATE XS
SET 专业名='通信工程'
WHERE 学号='001106'
GO
6.删除李方方同学的信息:
DELETE FROM XS
WHERE 姓名='李方方'
GO
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |