Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create a table in sqlserver

Shulou Source: shulou.com Published: 2022-05-31 23:11:40 09月21日 Update

This article introduces the knowledge about "how to create tables in sqlserver". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

The method is as follows:

1: In sql statements, temporary tables have two types: local and global temporary tables. Local temporary tables are only visible in their sessions (transactions), and global temporary tables can be accessed by any program or module in the session (transactions).

2: Create a local temporary table

use db_sqlservergocreate table #db_local_table( id int, name varchar(50), age int, area int)

Temporary tables created cannot be shared with other sessions, and both row and table definitions will be deleted when the session ends

3: Create global temporary tables

use db_sqlservergocreate table ##db_local_table( id int, name varchar(50), age int, area int)

The global temporary table is visible to all users and will not be deleted until every user accessing the table disconnects from the server

4: Create database tables with primary key and foreign key associations

use db_sqlserver;gocreate table db_table5(employee number int primary key, employee number varchar(50) unique, warehouse number varchar(50), salary int) gocreate table db_table6(order number int primary key, order number varchar(50) unique, employee number varchar(50) references db_table5(employee number), order date datetime, sales amount int)

5: Create database tables with check constraint fields

use db_sqlserver;gocreate table db_table7(warehouse number int primary key, employee number varchar(50) unique, warehouse number varchar(50), salary int, area int check(area>=600 and area =800 and base wage =300 and area =300 and area

Tags: Data database fields warehouse area salary staff global base salary sorting information size local attributes e-mail e-mail type message length association Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple vpn MariaDB MySQL