首页 > 代码库 > MySQL数据库表的数据插入、修改、删除操作及实例应用

MySQL数据库表的数据插入、修改、删除操作及实例应用

1.MySQL数据库表的数据插入、修改、删除操作SQL语法格式:

 1 CREATE DATABASE db0504;
 2 
 3 USE db0504;
 4 
 5 CREATE TABLE student (
 6     sno VARCHAR (10) NOT NULL UNIQUE PRIMARY KEY,
 7     sname VARCHAR (20) NOT NULL,
 8     ssex enum (, ) NOT NULL DEFAULT ,
 9     sbirth date,
10     sclass VARCHAR (10),
11     zno CHAR (4)
12 ) DEFAULT charset = gb2312;
13 #添加操作
14 INSERT INTO student
15 VALUES(2012010713,丁暖,,1993-9-9,物联网12-1,z002);
16 
17 INSERT INTO student (sno,sname,ssex,sbirth,sclass,zno)
18 VALUES(2011010503,孔超,,1993-9-19,自动化11-1,z006);
19 
20 INSERT INTO student (sno, sname, ssex, zno)
21 VALUES(2011010521,韩梅,,z006);
22 
23 INSERT INTO student (sname, zno, sno)
24 VALUES(韩梅2,z006,2011010522);
25 
26 INSERT INTO student VALUES
27 (2011010501,孔超1,,1993-9-19,自动化11-1,z006);
28 (2011010505,孔超2,,1993-9-19,自动化11-1,z006);
29 (2011010504,孔超3,,1993-9-19,自动化11-1,z006);
30 (2011010505,孔超4,,1993-9-19,自动化11-1,z006);
31 #修改操作
32 UPDATE student
33 SET sname = 张三,sbirth = 1993-6-19
34 WHERE sname = 丁暖;
35 
36 UPDATE student SET zno = LEFT (zno, 3);
37 #删除操作
38 delete from student
39 where sname=张三;
40 
41 #清空表操作
42 truncate student;#高效
43 delete from student;
44 
45 SELECT * FROM student;

插入:insert

修改:update

删除:delete

2.实例开发

MySQL数据库表的数据插入、修改、删除操作及实例应用