簡單常用的SQL命令
---恢復內容開始---
1數據庫操作
1:創建數據庫:create database <name>
2:顯示數據庫 show databasess (註意最後有個s)
3:刪除數據庫 drop database <name>
2表操作:
2.1獲取表結構:desc <name> 或者show columns from <name>
2.2刪除表 :drop table <name>
2.3向表插入一條數據:insert into <表名> [( <字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )]
eg:insert into MyClass values(1,‘Tom‘,96.45),(2,‘Joan‘,82.99), (2,‘Wang‘, 96.59);
2.4查詢表:
查詢所有行:select *from <name>
查看表 MyClass 中前2行數據
mysql> select * from MyClass order by id limit 0,2;
2.5 刪除一條數據 delete from <name> where id=1
2.6 修改表中的數據 update class set name=‘bb‘ where id=1
distinct 子句:僅選取唯一不同的值,重復值只顯示一次
select distinct <列名> from <表名>
ORDER BY 語句:按照升序對記錄進行排序。
order by desc:按照降序對記錄排序
select company,ordernumber from orders order by company
SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC
向表中插入一條數據:
INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
INSERT INTO 表名稱 VALUES (值1, 值2,....)
INSERT INTO Persons VALUES (‘Gates‘, ‘Bill‘, ‘Xuanwumen 10‘, ‘Beijing‘)
update語句:
update <表名> set <列名>=新值 where 列名=某值
update class set name=Joy where id =3
UPDATE Person SET Address = ‘Zhongshan 23‘, City = ‘Nanjing‘ WHERE LastName = ‘Wils‘
delete 語句:用於刪除表中某一行
delete from class where city=‘beijing‘
---恢復內容結束---
簡單常用的SQL命令