I want to create a table called quiz_mailing_list
in my database in SQL Server 2005.
With Fields:
id auto-increment primary key
email varchar(256)
optIn tinyint
referringEmail varchar(256)
Here is what I tried:
CREATE TABLE quiz_mailing_list(
id int identity(1,1) primary key,
email varchar(256),
optIn bit
referringEmail varchar(256))
I get this error:
System.Data.SqlClient.SqlException: Incorrect syntax near 'referringEmail'
How do I create a table in SQL Server 2005?
USE YourDatabaseName
GO
CREATE TABLE quiz_mailing_list (
id int identity(1,1) primary key,
email varchar(256),
optIn bit,
referringEmail varchar(256))
This should do the trick...
USE [whatever_db]
GO
/****** Object: Table [dbo].[quiz_mailing_list] Script Date: 09/11/2009 17:06:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[quiz_mailing_list](
[id] [int] IDENTITY(1,1) NOT NULL,
[email] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[optin] [bit] NOT NULL,
[referringEmail] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
Sir you are missing a comma ( ,) after optIn bit . Try below code
CREATE TABLE quiz_mailing_list(
id int identity(1,1) primary key,
email varchar(256),
optIn bit,
referringEmail varchar(256))
use MyDatabase
go
create table Quiz_Mailing_List
(
ID int identity(1,1) primary key clustered,
Email varchar(256),
Size tinyint,
OptIn bit,
ReferringEmail varchar(256)
)
If you don't understand SQL, you can use the Graphical User Interface walk you through creating a new table this way:
Right click the "Tables" folder under your database.
Choose "New Table".
Enter in a new column names and data types. You can choose properties of your columns from the properties window.
Click the save button or use Ctrl-S.
Left click the "Tables" button in object explorer under the database you created it in, and you should see your table.
Click the "New Query" button in the upper left.
Add this code to the query window:
use yourdatabase go create table Quiz_Mailing_List ( ID int identity(1,1) primary key clustered, Email varchar(256), Size tinyint, OptIn bit, ReferringEmail varchar(256) )
Select the text and press F5 to execute.
It should say: "Command(s) completed successfully."
Left click "Tables" on the Object Explorer pane to see your created table.
在T-SQL脚本中“使用数据库”的命令是
USE DatabaseName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.