SQL Server simply creates a database

Source: Internet
Author: User

Simple, as not a good program, it is easy to forget the SQL statement:

Use master
Go

--Determine if the database exists
If exists (select *from sysdatabases where name= ' database name ')
Drop database name
Go

--Create a database
Create DATABASE name
On primary
(
Name= ' wydb_test_data ',--database logical name
Filename= ' D:\SQL\WYDB_test_data.mdf ',--database physical file name
SIZE=20MB,--Database Initial Size
filegrowth=10mb--database File Increment
)
Log on
(
Name= ' Wydb_test_log ',--database logical name
Filename= ' D:\SQL\WYDB_test_log.ldf ',--database physical file name
SIZE=10MB,--Database Initial Size
filegrowth=5mb--database File Increment
)
Go

--Using the database
Use database name

--Determine if the table name exists
if exists (SELECT * from Sysobjects where name= ' table name ')
Drop Tablet_user
Go

--Create TABLE T_user | User table
CREATE TABLE Table name
(
Idintidentity (primary) key,--user ID
Usernamevarchar (uniquenot) null,--user name
Passwordvarchar () NOT null,--user login password
Phonenchar (one),--constraint mobile phone number is 11 digits
Birthdaysmalldatetime,--User's birthday
Classintdefault 1,--User level (default is level 1)
Imagehearturlvarchar (max),--user picture
Createtimesmalldatetimedefault getdate (),--User creation time
Isadminbitdefault 0--is administrator 0: No 1: Yes
)
Go

SQL Server simply creates a database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.