sql语句的增删改查 下载本文

内容发布更新时间 : 2024/12/24 3:09:55星期一 下面是文章的全部内容请认真阅读。

-- sql的增删改查

-- 新建表wr_t_student CREATE TABLE

IF NOT EXISTS wr_t_student ( id INT NOT NULL PRIMARY KEY auto_increment, `name` VARCHAR (50) NOT NULL, telephone VARCHAR (20), cdcard VARCHAR (18), photourl VARCHAR (50) );

-- 新建表wr_t_teacher CREATE TABLE

IF NOT EXISTS wr_t_teacher ( id INT NOT NULL PRIMARY KEY auto_increment, `name` VARCHAR (50) NOT NULL, telephone VARCHAR (20), cdcard VARCHAR (18), photourl VARCHAR (50) );

-- 新建表wr_t_class CREATE TABLE

IF NOT EXISTS wr_t_class ( id INT NOT NULL PRIMARY KEY auto_increment, teaid INT NOT NULL, address VARCHAR (50), startdatedatetime, enddatedatetime, masterid INT );

-- 新建表wr_t_login CREATE TABLE

IF NOT EXISTS wr_t_login ( id INT NOT NULL PRIMARY KEY auto_increment, userid INT NOT NULL, isstudent VARCHAR (4), username VARCHAR (50), `password` VARCHAR (50) );

-- 新建表wr_t_exam

CREATE TABLE

IF NOT EXISTS wr_t_exam ( id INT NOT NULL PRIMARY KEY auto_increment, examnum INT, content text, answer text, score FLOAT, questiontimedatetime, questionid INT );

-- 新建表wr_t_examresult CREATE TABLE

IF NOT EXISTS wr_t_examresult ( id INT NOT NULL PRIMARY KEY auto_increment, examid INT, studentid INT, studentanswer text, score FLOAT );

-- 删除整张表

DROP TABLE teacher; -- 删除表中的一条数据 DELETE FROM wr_t_exam WHERE id = 1;

-- 删除全表内容,同时删除标的计数器 TRUNCATE TABLE wr_t_exam;

-- 查询数据 SELECT * FROM wr_t_exam;

-- 插入数据

INSERT INTO wr_t_exam ( examnum, content, answer, score,

questiontime, questionid )

VALUES ( 12, \ \ 451, \ 456 );

-- 更新数据

UPDATE wr_t_exam SET examnum = 1234, content = \ answer = \

questiontime = \questionid = 1234 WHERE id = 1;