对表的一些基本操作
1
Creating a Table
syntax
CREATE TABLE Tablename (column_name type, column_name, type, .....)
for example
CREATE TABLE Employee (names VARCHAR(20),
address VARCHAR(20),
employee_number INT,
salary SMALLMONEY)
2
Inserting Values into a Table
the two way to insert values into a table
one way to insert values into one row of a table is to use the INSERT INTO command
with the VALUES option.
syntax :
INSERT INTO TableName VALUES ('character_attribute_value', numeric_attribute_value, ...)
the other way we can insert many rows into a table at one time.
syntax:
INSERT INTO Names(fullname) SELECT names FROM Employee
3
The UPDATE Command
to set /change data values in a table ,we use the update command.
syntac:
UPDATE TableName
SET fieldname
for example
UPDATE Emp2
SET sal = 0 --把表中雇员的薪水都改为0
或者写成
UPDATE Emp2
SET sal = 1000
WHERE aga > 40 --讲年龄大于40雇员工资改为 1000
4
The ALTER TABLE Command
if you want to add ,change,delete column in a table, wo will use the ALTER TABLE command.
for example
ALTER TABLE Tablename ADD column-name type
5
the DELETE Command
we use the DELETE command to delete the row of a table what we want to .
Syntar:
DELETE FROM Table
WHERE(condition)
for example
DELETE FROM student
WHERE(age>16)--删除学生表中 年龄大于16岁学生的信息
if you want to delete entire table
please write
DROP TABLE Tablename