創建表:create table A (........);
查詢記錄:select * from A
更新記錄:update A set a.x=y where a.z=c
插入記錄: insert into A(x,y,z) values(......);
刪除某記錄:delete [form] A where a.x =y [如果刪除整表數據則不用條件]
刪除表:drop table A
清空整表數據: truncate table A [有外鍵關聯則不能單獨清空數據]
1。使查詢出來的數據不重複:
select distinct 字段名 from 表名
2。查詢出重複的數據:
select 字段名 from 表名 group by 字段名 having count(字段名)>1
3。從其他表中獲取數據建立表
CREATE TABLE table1 AS SELECT * FROM table2
4。增加列
ALTER TABLE [schema.] table_name ADD column_definition column_type
5。更改列
ALTER TABLE [schema.] table_name MODIFY (column_name column_type, newcolumn_name newcolumn_type)
6。更改表名
RENAME old_name TO new_name
7.連表查詢
1)查出來的數據有重複
select * from A, B where A.x = B.x and B.x=y
2)查出來的數據沒重複(子查詢)
select * from A where A.x in(select * from B where B.x =y)
8.修改表的所有者
sp_MSForEachTable ’sp_changeobjectowner ’’?’’,’’dbo’’’
9.關聯更新:
MySQL:update A a,B b set a.x=b.x where a.z=b.z
SQL2000:update a set a.x=b.x from A a,B b where a.z=b.z
10.修改字段類型:
mysql: alter table autopay modify PayDate datetime;