T-SQL常用語句創建資料庫: CREATE DATABASE [資料庫名] CREATE DATABASE [School]刪除資料庫: DROP DATABASE [資料庫名] DROP DATABASE [School]創建表: CREATE TABLE [表名]([列名] [類型](長度) ...
T-SQL常用語句
創建資料庫:
CREATE DATABASE [資料庫名]
CREATE DATABASE [School]
刪除資料庫:
DROP DATABASE [資料庫名]
DROP DATABASE [School]
創建表:
CREATE TABLE [表名]([列名] [類型](長度) 設置,列名 類型(長度) 設置)
CREATE TABLE [Student] ( [NAME] [VARCHAR](11) IDENTITY(1,1) , [ID] [INT](11) NOT NULL)
刪除表:
DROP TABLE [表名]
DROP TABLE [MYTEST];
增加列:
ALTER TABLE [表名] ADD 列名 設置
ALTER TABLE [Student] ADD Commission money null
刪除列:
ALTER TABLE [表名] DROP COLUMN [要刪除列];
ALTER TABLE [Student] DROP COLUMN [TEST];
添加行:
INSERT INTO [表名](列名) VALUES (值);
INSERT INTO [Grade](Gradename) VALUES ('h1');
刪除行:
DELETE FROM [表名] WHERE [GradeId]>=4;//條件
DELETE FROM [Grade] WHERE [GradeId]>=4;
更新行中數據:
UPDATE [表名] SET [要修改列]=要修改值 WHERE [GradeId]=8;//條件
UPDATE [Grade] SET [Gradename]='test' WHERE [GradeId]=8;
查詢數據:
顯示所有:
SELECT *FROM 表名;
SELECT *FROM Grade;
顯示部分:
SELECT [列名],[列名] FROM [查詢表];
SELECT [STUDENTNO],[StudentName] FROM [Student];
顯示含空值:
SELECT *FROM [查詢表] WHERE [列]IS NULL;//is null 是否 is not null不是空
SELECT *FROM [Student] WHERE [STUDENTNAME]IS NULL;
限制顯示行:
SELECT TOP 3 *FROM [表名];//top 值:顯示多少行
SELECT TOP 3 *FROM [Student];