基本SQL 语句操作数据增删查改
2017-05-04 11:13
543 查看
1、创建数据库: create database <数据库名>。
如:create database student;
2、连接到一个已经存在的数据库: use <数据库名>;
如:use student;
3、删除数据库:drop database <数据库名>。
如: drop database student;
4、创建表:create table <表名>(<列名><列的数据类型>[<列的约束>])
如:create table stuInfo(stuId int primary key,stuName varchar(20) not null)
5、删除表: drop table <表名>
如: drop table stuInfo;
6、改动表:alter table
给表加入新列: alter table <表名> add <列名><列的数据类型>;
加入多列,中间用逗号隔开
如:alter table stuInfo add stuGender varchar(10)
改动某列的数据类型:alter table <表名> modify <列名><新数据类型>
如:alter table stuInfo modify stuGender int
改动列名:alter table <表名> change <老列名><新列名><数据类型>
如:alter table stuInfo change stuName stuAddress varchar(30)
删除列:alter table <表名> drop <列名>
如: alter table stuInfo drop stuGender
7、将创建的表的语句反向导出: show create table <表名>
8、查询表的全部内容:select * from <表名>
查询表的部分内容: select <列名列表> from <表名>
9、查询表结构:show columns from <表名>
10、插入单行数据:insert into <表名>(<列名列表>) values(<值列表>)
11、插入多行数据:作用相当于将数据从一个表拷贝到还有一个表
insert into <表名> (列名列表) select <select语句>
如将stuInfo表中的全部的学生姓名拷贝到students表中的stuName列中:insert into students(stuName) select stuName from stuInfo
12、删除数据:delete from <表名> where<过滤条件>
如删除stuID为4的人的数据:delete from stuInfo where stuId=4
如:create database student;
2、连接到一个已经存在的数据库: use <数据库名>;
如:use student;
3、删除数据库:drop database <数据库名>。
如: drop database student;
4、创建表:create table <表名>(<列名><列的数据类型>[<列的约束>])
如:create table stuInfo(stuId int primary key,stuName varchar(20) not null)
5、删除表: drop table <表名>
如: drop table stuInfo;
6、改动表:alter table
给表加入新列: alter table <表名> add <列名><列的数据类型>;
加入多列,中间用逗号隔开
如:alter table stuInfo add stuGender varchar(10)
改动某列的数据类型:alter table <表名> modify <列名><新数据类型>
如:alter table stuInfo modify stuGender int
改动列名:alter table <表名> change <老列名><新列名><数据类型>
如:alter table stuInfo change stuName stuAddress varchar(30)
删除列:alter table <表名> drop <列名>
如: alter table stuInfo drop stuGender
7、将创建的表的语句反向导出: show create table <表名>
8、查询表的全部内容:select * from <表名>
查询表的部分内容: select <列名列表> from <表名>
9、查询表结构:show columns from <表名>
10、插入单行数据:insert into <表名>(<列名列表>) values(<值列表>)
11、插入多行数据:作用相当于将数据从一个表拷贝到还有一个表
insert into <表名> (列名列表) select <select语句>
如将stuInfo表中的全部的学生姓名拷贝到students表中的stuName列中:insert into students(stuName) select stuName from stuInfo
12、删除数据:delete from <表名> where<过滤条件>
如删除stuID为4的人的数据:delete from stuInfo where stuId=4
相关文章推荐
- 基本SQL 语句操作数据增删查改
- 操作DB ~~对数据的增删改查!!sql语句 (二)
- 掌握sql四条最基本的数据操作语句
- MySql数据基本操作sql语句
- 操作DB~~对数据的增删改查!!sql语句
- 基本查询语句及利用SQL语句完成数据的添加、删除、修改操作
- 掌握SQL四条最基本的数据操作语句:Insert,Select,Update和Delete
- 掌握SQL四条最基本的数据操作语句
- mysql数据库常用的基本SQL语句--数据库表操作
- 掌握SQL四条最基本的数据操作语句:Insert,Select,Update和Delete
- mysql数据库常用的基本SQL语句--数据库数据操作
- 掌握sql四条最基本的数据操作语句- -
- SQL增删改查基本操作
- 用SQL语句添加删除修改字段及一些表与字段的基本操作
- SQL基本操作语句全集
- SQL SERVER 2005中使用sql语句对xml 文件和其数据的进行操作(很全面)
- 【数据操作】SQL语句性能调整原则
- 【数据操作】SQL语句性能调整原则
- C#数据库编程基础之sql语句操作数据库数据
- sql语句基本操作