mysql命令大全实用

DELETE FROM food WHERE address='北京';

(1)创建teacher表。SQL代码如下: CREATE TABLE teacher( id INT(4) NOT NULL UNIQUE PRIMARY KEY AUTO_INCREMENT, num INT(10) NOT NULL UNIQUE , name VARCHAR(20) NOT NULL , sex VARCHAR(4) NOT NULL , birthday DATETIME , address VARCHAR(50) );

然后向teacher表中插入记录。INSERT语句的代码如下:

INSERT INTO teacher VALUES(1, 1001, '张三','男' ,'1984-11-08' ,'北京市昌平区'); INSERT INTO teacher VALUES (2, 1002, '李四','女' ,'1970-01-21' ,'北京市海淀区') , (NULL, 1003, '王五','男' ,'1976-10-30' ,'北京市昌平区') , (NULL, 1004, '赵六','男' ,'1980-06-05' ,'北京市顺义区') ;

(2)更新id为1的记录,将生日(birthday)改为“1982-11-08”。UPDATE语句的代码如下:

UPDATE teacher SET birthday='1982-11-08' WHERE id=1 ;

(3)将性别(sex)为“男”的记录的家庭住址(address)都变为“北京市朝阳区”。UPDATE语句的代码如下:

UPDATE teacher SET address='北京市朝阳区' WHERE sex='男' ;

(4)删除教工号(num)为1002的记录删除。DELETE语句的代码如下: DELETE FROM teacher WHERE num=1002;

联系客服:779662525#qq.com(#替换为@)