SQL Server创建数据库和数据的增删改查
生活随笔
收集整理的這篇文章主要介紹了
SQL Server创建数据库和数据的增删改查
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SQL Server創建數據庫和數據的增刪改查
本文是針對數據的增刪改查,數據的創建
首先我們使用命令創建sql server數據庫
D盤新建一個文件夾DB
全選上面代碼,按一下F5,便執行完畢
(上面代碼若一時記不得,多寫幾遍就記得了,實在記不得,敲200遍就記得了,直到敲到閉著眼睛都能默寫下來,固定的寫法,沒有必要記,記不得來我這里博客翻閱一下,便知道,但是知道有這回事,大腦過一遍)
drop table Students – 刪除表
與mysql一樣,在使用某個數據庫之前,必須先use一下
use DemoDBcreate table Students (StuId int identity(1,1),Name varchar(20) not null,Gender char(2) not null,Birthday datetime not null,StuIdNO numeric(18,0)not null,-- 身份證號Age int not null,PhoneNUmber varchar(50),StuAddress varchar(500),ClassId int not null)goselect Students.StuId,C#成績=CSharp,StudentName,ClassName from ScoreList --哪個字段多,放在這里 inner join Students on Students.StuId = ScoreList.StudentId inner join StudentClass on Students.ClassId=StudentClass.ClassId where CSharp > 80 多表聯合查詢select StudentName,StudentAddress,Birthday from Stduents where Birthday between '1977-01-01' and '1988-07-05' 時間的篩選string sql = "select StudentId,StudentName,Gender,Birthday,ClassName,StudentIdNO,PhoneNumber,StudentAddress,CardNO from Students";sql +=" inner join StudentClass on Stduents.ClassId = StudentClass.CLassId";sql +=" where StudentId = " + studentId;;string connectionString = string.Format(@"Data Source={0};User ID={1};Password={2};Initial Catalog={3};Pooling=true",dataSource, userID, password, databaseName); 字符串之模板占位符咱們嘗試使用圖形界面軟件去創建數據庫,如圖所示
亦可使用圖形界面工具創建表,以及添加主鍵,外鍵,以及字段約束
通過關系圖,可以快速的查看表與表之間有沒有主外鍵的關系
總結
以上是生活随笔為你收集整理的SQL Server创建数据库和数据的增删改查的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于苹果开发
- 下一篇: mysql的联表查询和去重复数据