基本SQL 陳述式操作資料增刪查改,sql增刪

來源:互聯網
上載者:User

基本SQL 陳述式操作資料增刪查改,sql增刪
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

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.