2. Database creation
- 2.1 Database Creation via SSMS
- 2.2 Creating a database with SQL statements
3. Create a table
- 3.1 Creating a table from SSMs
- 3.2 Creating tables with SQL statements
1. Preface
Configuration is Win10+sql Server 2012, the GUI management tool that is used by SQL Server 2012 comes with SQL Server Management Studio (hereinafter referred to as SSMS). The main purpose of this series is to learn SQL Server Foundation, in order to use Python to connect and use the database. Also paste the SQL Server 2012 here.
2. Database Creation2.1 Database creation via SSMS
2.1.1 Open SSMs and connect to the database.
, locate the database, right-click the database, and select New database.
2.1.2 Enter ssmstest at the database name, select OK.
(Primary data file: *.mdf, log file *.ldf, secondary data file *.ndf)
2.1.3 Right-click on the database to refresh or press F5, then you can see the ssmstest under the database.
(You can see that the icon to the left of Ssmstest is a cylinder, which can be understood as each cylinder represents a database.) )
2.1.4 to this point, a database named Ssmstest has been established.
2.2 Creating a database with SQL statements
2.2.1 Click New Query at the beginning of the screen.
2.2.2 Enter the following code in the click New query interface:
create database SQLTest
2.2.3 Click on the above execution, or press F5 after the following screen.
2.2.4 Right-click on the database to refresh or press F5, then you can see the sqltest under the database.
2.2.5 to this point, a database named Sqltest has been established.
3. Create a table3.1 Creating a table from SSMs
3.1.1 Open the newly created Ssmstest database and locate the table (Database->ssmstest-> table).
Right-click the table and select New table.
3.1.2 in the interface of clicking on the new table, follow the input:
3.1.3 Press Ctrl+s or click on the file in the top menu bar to select Save.
Enter the name of the table you want to save student, and click OK.
3.1.4 Click New Table again, follow the input, and save as course.
3.1.5 Click New Table again, follow the input, and save as SC.
3.1.6 The database->ssmstest-> table there, you will find the three tables that have just been created.
(Select Database->ssmstest-> table->dbo.student Right-click to select the design to see the details of the table you just created.) )
3.2 Creating tables with SQL statements
3.2.1 Select Database->sqltest, and then select New Query. Notice the box in the upper left corner to select Sqltest, if not, select it manually.
3.2.2 Enter the following code in the new query interface:
--This is the comment information in SQL, annotated with two minus signs.DropTable Student--Delete Table studentCreateTable Student--Create TABLE student (SnoChar4), snameChar8), SageInt,ssexChar2), sdeptChar20))DropTable Course--Delete Table courseCreateTable Course--Create TABLE course (CNOchar (4), CNAME char ( Span class= "DV" >8), cpno char (4), Ccredit int) drop table SC --Delete Table SC create table SC --CREATE TABLE SC (sno char (4), CNO char (4), Grade < Span class= "hljs-built_in" >int)
3.2.3 Click Execute, the following warning will appear. This is because we haven't created the table yet, so nothing has been deleted. Just click to execute again.
3.2.4 The database->sqltest-> table there, you will find the three tables that have just been created.
(Select Database->sqltest-> table->dbo.student Right-click to select the design to see the details of the table you just created.) )
SQL Server: establishing databases and tables