(1): Query whether a table exists in a database ( two ways): Assuming that the table name is table_name
if exists (select * from sysobjects where name= ' table_name ')
DROP TABLE table_name
If OBJECT_ID (' table_name ') is NOT null
DROP TABLE table_name
The same operation can also be used to determine whether the database exists!
(2): Some instances of the table operation:
create an instance of a table: (Student score table:grade_table)
if exists (select * from sysobjects where name = ' grade_table ')
drop table Grade_table
Go
CREATE TABLE Grade_table
(
Stuid varchar (20),
CourseID varchar (20),
Grade int
)
(3): Insert data in table: (Student score table:grade_table)
INSERT into grade_table values (' 10001 ', ' 001 ', ' 85 ')
INSERT into grade_table values (' 10002 ', ' 001 ', ' 95 ')
(4): update the data in the table:
Update grade_table set grade=70 where stuid= ' 10001 ' and courseid= ' 001 '
(5): Delete data from table:
Delete grade_table where stuid= ' 10001 ' and courseid= ' 001 '
(6): Create a new table with the same student_table as the student and then insert the data queried in student_table, which is generally used to guide some data
CREATE TABLE student_table
(
stuid varchar,
CourseID varchar,
grade int
)
CREATE TABLE Student
(
stuid varchar,
CourseID varchar,
grade int
)
INSERT into student_table values (' 10001 ', ' 001 ', ' I ')
INSERT into student_table values (' 10002 ', ' 001 ', ' 95 ')
INSERT INTO student
SELECT * from student_table as S1
where S1.stuid not in (select Stuid from student)
This article from "Ricky's Blog" blog, reproduced please contact the author!
2. SQL--Query table, CREATE TABLE, insert data into table