标准T-SQL语句的增删改查

Mysql连接数据库:

      Mysql -uroot -p -h ***  //   -h参数跟上远程服务器的IP

      Mysql返回1130表示没有账号开启外联

      Mysql返回1045表示有账号开启外联,但是不知道是那个账号

1、          查询所有数据库

show database zhutougg;   //新建名为zhutougg的数据库

2、          使用数据库

use zhutougg;

3、          查询当前库的所有的表名

create table_name from information_scheam.tble_scheam=’zhutougg’

4、          新建数据表

creat table stu(

   id int primary key auto_increment,  //整型,主键(数据不能重复)自动增长

   stu_name varchar(255) not null,   //字符型,不能空

   stu_sex varchar(2) not null,  

   course varchar(255) not null,

   score int not null

,     )

5、          想stu表插入数据

//张三 男 语文 99

//张三 男 数学 59

//张三 男 英语 89

//李四 女 语文 97

//李四 女 数学 79

//李四 女 英语 89

insert into stu(stu_name,stu_sex,course,scorse)

values(‘张三’,‘男’,‘语文’,99)

(‘张三’,‘男’,‘数学’,59)

(‘张三’,‘男’,‘英语’,89)

(‘李四’,‘女’,‘语文’,97)

(‘李四’,‘女’,‘数学’,79)

(‘李四’,‘女’,‘英语’,89)

6、          查询stu表中的所有数据

select*from stu

7、          查询分数在90分以上的所有学生的信息

select*from stu where score>90

8、          查询分数在70~80分之间的所有学生的信息

select*from stu where score between 70 and 80

9、          查询语文考试的学生情况

select*from stu where course=’语文’

10、       修改张三同学的数学成绩

update stu set score=60 where stu_name=’张三’and score=’数学’

11、       删除李四同学的所有信息

delete from stu where stu_name=’李四’

12、       删除表数据

delete from stu

13、       删除表

drop table stu

14、       删除库

drop database zhutougg

15、       修改数据库名

rename database 原库名 to 新库名    //只能在mysql版本5.1.7-5.1.23内用

16、       查看mysql版本

select @@version

猜你喜欢

转载自www.cnblogs.com/qie-date/p/12183474.html